@@ -5,6 +5,7 @@ import { ConsoleLog } from "../logging/ConsoleLog.js";
55import { NullLog } from "../logging/NullLog.js" ;
66import { UserInfo } from "../models/data/UserInfo.js" ;
77import { HeartbeatPlugin } from "../plugins/default/HeartbeatPlugin.js" ;
8+ import { SessionIdManagementPlugin } from "../plugins/default/SessionIdManagementPlugin.js" ;
89import { EventPluginContext } from "../plugins/EventPluginContext.js" ;
910import { EventPluginManager } from "../plugins/EventPluginManager.js" ;
1011import { IEventPlugin } from "../plugins/IEventPlugin.js" ;
@@ -428,32 +429,24 @@ export class Configuration {
428429 }
429430
430431 /**
431- * Set the default user identity for all events. If the heartbeat interval is
432- * greater than 0 (default: 30000ms), heartbeats will be sent after the first
433- * event submission.
432+ * Set the default user identity for all events.
434433 */
435- public setUserIdentity ( userInfo : UserInfo , heartbeatInterval ?: number ) : void ;
436- public setUserIdentity ( identity : string , heartbeatInterval ?: number ) : void ;
437- public setUserIdentity ( identity : string , name : string , heartbeatInterval ?: number ) : void ;
438- public setUserIdentity ( userInfoOrIdentity : UserInfo | string , nameOrHeartbeatInterval ?: string | number , heartbeatInterval : number = 30000 ) : void {
439- const name : string | undefined = typeof nameOrHeartbeatInterval === "string" ? nameOrHeartbeatInterval : undefined ;
434+ public setUserIdentity ( userInfo : UserInfo ) : void ;
435+ public setUserIdentity ( identity : string ) : void ;
436+ public setUserIdentity ( identity : string , name : string ) : void ;
437+ public setUserIdentity ( userInfoOrIdentity : UserInfo | string , name ?: string ) : void {
440438 const userInfo : UserInfo = typeof userInfoOrIdentity !== "string"
441439 ? userInfoOrIdentity
442440 : < UserInfo > { identity : userInfoOrIdentity , name } ;
443441
444- const interval : number = typeof nameOrHeartbeatInterval === "number" ? nameOrHeartbeatInterval : heartbeatInterval ;
445- const plugin = new HeartbeatPlugin ( interval ) ;
446-
447442 const shouldRemove : boolean = ! userInfo || ( ! userInfo . identity && ! userInfo . name ) ;
448443 if ( shouldRemove ) {
449- this . removePlugin ( plugin )
450444 delete this . defaultData [ KnownEventDataKeys . UserInfo ] ;
451445 } else {
452- this . addPlugin ( plugin )
453446 this . defaultData [ KnownEventDataKeys . UserInfo ] = userInfo ;
454447 }
455448
456- this . services . log . info ( `user identity: ${ shouldRemove ? "null" : < string > userInfo . identity } (heartbeat interval: ${ interval } ms) ` ) ;
449+ this . services . log . info ( `user identity: ${ shouldRemove ? "null" : < string > userInfo . identity } ` ) ;
457450 }
458451
459452 /**
@@ -477,7 +470,39 @@ export class Configuration {
477470 * This setting only works in environments that supports persisted storage.
478471 * There is also a performance penalty of extra IO/serialization.
479472 */
480- public usePersistedQueueStorage = false ;
473+ public usePersistedQueueStorage : boolean = false ;
474+
475+ /**
476+ * Gets or sets a value indicating whether to automatically send session start,
477+ * session heartbeats and session end events.
478+ */
479+ public sessionsEnabled = false ;
480+
481+ /**
482+ * Internal property used to track the current session identifier.
483+ */
484+ public currentSessionIdentifier : string | null = null ;
485+
486+ /**
487+ *
488+ * @param sendHeartbeats Controls whether heartbeat events are sent on an interval.
489+ * @param heartbeatInterval The interval at which heartbeats are sent after the last sent event. The default is 1 minutes.
490+ * @param useSessionIdManagement Allows you to manually control the session id. This is only recommended for single user desktop environments.
491+ */
492+ public useSessions ( sendHeartbeats : boolean = true , heartbeatInterval : number = 60000 , useSessionIdManagement : boolean = false ) {
493+ this . sessionsEnabled = true ;
494+
495+ if ( useSessionIdManagement ) {
496+ this . addPlugin ( new SessionIdManagementPlugin ( ) ) ;
497+ }
498+
499+ const plugin = new HeartbeatPlugin ( heartbeatInterval ) ;
500+ if ( sendHeartbeats ) {
501+ this . addPlugin ( plugin ) ;
502+ } else {
503+ this . removePlugin ( plugin ) ;
504+ }
505+ }
481506
482507 private originalSettings ?: Record < string , string > ;
483508
0 commit comments