Skip to content

Commit

Permalink
resolve the mess
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldambra committed Mar 19, 2024
1 parent 4b825bd commit 8457efa
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 60 deletions.
21 changes: 3 additions & 18 deletions src/__tests__/extensions/replay/sessionrecording.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import { assignableWindow, window } from '../../../utils/globals'
import { RequestRouter } from '../../../utils/request-router'
import { customEvent, EventType, eventWithTime, pluginEvent } from '@rrweb/types'
import Mock = jest.Mock
import { SimpleEventEmitter } from '../../../simple-event-emitter'

// Type and source defined here designate a non-user-generated recording event

Expand Down Expand Up @@ -145,13 +144,7 @@ describe('SessionRecording', () => {
const postHogPersistence = new PostHogPersistence(config)
postHogPersistence.clear()

sessionManager = new SessionIdManager(
config,
postHogPersistence,
new SimpleEventEmitter(),
sessionIdGeneratorMock,
windowIdGeneratorMock
)
sessionManager = new SessionIdManager(config, postHogPersistence, sessionIdGeneratorMock, windowIdGeneratorMock)

posthog = {
get_property: (property_key: string): Property | undefined => {
Expand Down Expand Up @@ -856,11 +849,7 @@ describe('SessionRecording', () => {
let mockCallback: Mock<SessionIdChangedCallback>
let unsubscribeCallback: () => void
beforeEach(() => {
sessionManager = new SessionIdManager(
config,
new PostHogPersistence(config),
new SimpleEventEmitter()
)
sessionManager = new SessionIdManager(config, new PostHogPersistence(config))
posthog.sessionManager = sessionManager

mockCallback = jest.fn()
Expand Down Expand Up @@ -937,11 +926,7 @@ describe('SessionRecording', () => {

describe('with a real session id manager', () => {
beforeEach(() => {
sessionManager = new SessionIdManager(
config,
new PostHogPersistence(config),
new SimpleEventEmitter()
)
sessionManager = new SessionIdManager(config, new PostHogPersistence(config))
posthog.sessionManager = sessionManager

sessionRecording.startRecordingIfEnabled()
Expand Down
6 changes: 2 additions & 4 deletions src/__tests__/sessionid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { uuidv7 } from '../uuidv7'
import { PostHogConfig, Properties } from '../types'
import { PostHogPersistence } from '../posthog-persistence'
import { assignableWindow } from '../utils/globals'
import { SimpleEventEmitter } from '../simple-event-emitter'

jest.mock('../uuidv7')
jest.mock('../storage')
Expand All @@ -23,7 +22,7 @@ describe('Session ID manager', () => {
const subject = (sessionIdManager: SessionIdManager, isReadOnly?: boolean) =>
sessionIdManager.checkAndGetSessionAndWindowId(isReadOnly, timestamp)
const sessionIdMgr = (phPersistence: Partial<PostHogPersistence>) =>
new SessionIdManager(config, phPersistence as PostHogPersistence, new SimpleEventEmitter())
new SessionIdManager(config, phPersistence as PostHogPersistence)

const originalDate = Date

Expand Down Expand Up @@ -273,8 +272,7 @@ describe('Session ID manager', () => {
{
session_idle_timeout_seconds: timeout,
},
persistence as PostHogPersistence,
new SimpleEventEmitter()
persistence as PostHogPersistence
)

beforeEach(() => {
Expand Down
5 changes: 1 addition & 4 deletions src/posthog-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ import { document, userAgent } from './utils/globals'
import { SessionPropsManager } from './session-props'
import { _isBlockedUA } from './utils/blocked-uas'
import { extendURLParams, request, SUPPORTS_REQUEST } from './request'
import { EmitterEvent, SimpleEventEmitter } from './simple-event-emitter'

/*
SIMPLE STYLE GUIDE:
Expand Down Expand Up @@ -220,8 +219,6 @@ export class PostHog {
set_once: (prop: string | Properties, to?: string, callback?: RequestCallback) => void
}

eventEmitter = new SimpleEventEmitter()

constructor() {
this.config = defaultConfig()
this.decideEndpointWasHit = false
Expand Down Expand Up @@ -341,7 +338,7 @@ export class PostHog {
this.__captureHooks = []
this.__request_queue = []

this.sessionManager = new SessionIdManager(this.config, this.persistence, this.eventEmitter)
this.sessionManager = new SessionIdManager(this.config, this.persistence)
this.sessionPropsManager = new SessionPropsManager(this.sessionManager, this.persistence)

this.sessionRecording = new SessionRecording(this)
Expand Down
5 changes: 0 additions & 5 deletions src/sessionid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { window } from './utils/globals'

import { _isArray, _isNumber, _isUndefined } from './utils/type-utils'
import { logger } from './utils/logger'
import { SimpleEventEmitter } from './simple-event-emitter'

const MAX_SESSION_IDLE_TIMEOUT = 30 * 60 // 30 minutes
const MIN_SESSION_IDLE_TIMEOUT = 60 // 1 minute
Expand All @@ -27,12 +26,10 @@ export class SessionIdManager {
private _sessionActivityTimestamp: number | null
private readonly _sessionTimeoutMs: number
private _sessionIdChangedHandlers: SessionIdChangedCallback[] = []
private _eventEmitter: SimpleEventEmitter

constructor(
config: Partial<PostHogConfig>,
persistence: PostHogPersistence,
eventEmitter: SimpleEventEmitter,
sessionIdGenerator?: () => string,
windowIdGenerator?: () => string
) {
Expand All @@ -44,7 +41,6 @@ export class SessionIdManager {
this._sessionActivityTimestamp = null
this._sessionIdGenerator = sessionIdGenerator || uuidv7
this._windowIdGenerator = windowIdGenerator || uuidv7
this._eventEmitter = eventEmitter

const persistenceName = config['persistence_name'] || config['token']
let desiredTimeout = config['session_idle_timeout_seconds'] || MAX_SESSION_IDLE_TIMEOUT
Expand Down Expand Up @@ -235,7 +231,6 @@ export class SessionIdManager {
this._setSessionId(sessionId, newTimestamp, sessionStartTimestamp)

if (valuesChanged) {
this._eventEmitter.emit('session_id_changed', sessionId, windowId)
this._sessionIdChangedHandlers.forEach((handler) => handler(sessionId, windowId))
}

Expand Down
29 changes: 0 additions & 29 deletions src/simple-event-emitter.ts

This file was deleted.

0 comments on commit 8457efa

Please sign in to comment.