@@ -5,6 +5,7 @@ import { ConsoleLog } from "../logging/ConsoleLog.js";
5
5
import { NullLog } from "../logging/NullLog.js" ;
6
6
import { UserInfo } from "../models/data/UserInfo.js" ;
7
7
import { HeartbeatPlugin } from "../plugins/default/HeartbeatPlugin.js" ;
8
+ import { SessionIdManagementPlugin } from "../plugins/default/SessionIdManagementPlugin.js" ;
8
9
import { EventPluginContext } from "../plugins/EventPluginContext.js" ;
9
10
import { EventPluginManager } from "../plugins/EventPluginManager.js" ;
10
11
import { IEventPlugin } from "../plugins/IEventPlugin.js" ;
@@ -428,32 +429,24 @@ export class Configuration {
428
429
}
429
430
430
431
/**
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.
434
433
*/
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 {
440
438
const userInfo : UserInfo = typeof userInfoOrIdentity !== "string"
441
439
? userInfoOrIdentity
442
440
: < UserInfo > { identity : userInfoOrIdentity , name } ;
443
441
444
- const interval : number = typeof nameOrHeartbeatInterval === "number" ? nameOrHeartbeatInterval : heartbeatInterval ;
445
- const plugin = new HeartbeatPlugin ( interval ) ;
446
-
447
442
const shouldRemove : boolean = ! userInfo || ( ! userInfo . identity && ! userInfo . name ) ;
448
443
if ( shouldRemove ) {
449
- this . removePlugin ( plugin )
450
444
delete this . defaultData [ KnownEventDataKeys . UserInfo ] ;
451
445
} else {
452
- this . addPlugin ( plugin )
453
446
this . defaultData [ KnownEventDataKeys . UserInfo ] = userInfo ;
454
447
}
455
448
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 } ` ) ;
457
450
}
458
451
459
452
/**
@@ -477,7 +470,39 @@ export class Configuration {
477
470
* This setting only works in environments that supports persisted storage.
478
471
* There is also a performance penalty of extra IO/serialization.
479
472
*/
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
+ }
481
506
482
507
private originalSettings ?: Record < string , string > ;
483
508
0 commit comments