o2g-node-sdk 2.5.7 → 2.5.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -54,6 +54,28 @@ await O2G.telephony.makeCall("1234", "5678");
54
54
  await O2G.shutdown();
55
55
  ```
56
56
 
57
+ ## What's New in 2.5.8
58
+
59
+ ### Service instance caching — fixes listeners silenced after recovery
60
+
61
+ Service getters (`O2G.eventSummary`, `O2G.telephony`, …) now return the **same
62
+ instance** for the lifetime of a session. Previously every call created a new
63
+ object, and because each constructor silently overwrites the shared `EventSink`
64
+ registration, any listener attached to an earlier instance would stop receiving
65
+ events — a particularly subtle failure after session recovery.
66
+
67
+ The instances are automatically invalidated on `O2G_SESSION_LOST` and
68
+ `O2G_RECONNECTED`, so the first access after recovery always binds to the new
69
+ session. Re-attach your listeners once in the `O2G_RECONNECTED` handler and they
70
+ will keep working across any number of recovery cycles.
71
+
72
+ ```typescript
73
+ O2G.on(O2G.O2G_RECONNECTED, () => {
74
+ // Re-attach — O2G.eventSummary now returns a fresh instance
75
+ O2G.eventSummary.on(EventSummary.ON_EVENT_SUMMARY_UPDATED, onEventSummary);
76
+ });
77
+ ```
78
+
57
79
  ## What's New in 2.5.7
58
80
 
59
81
  - Add new field `emailAddress` in object `User`
@@ -248,6 +270,10 @@ O2G.on(O2G.O2G_SESSION_LOST, ({ reason }) => {
248
270
 
249
271
  O2G.on(O2G.O2G_RECONNECTED, () => {
250
272
  console.log("Session recovered — resuming activity.");
273
+ // Re-attach service listeners here: each service getter returns a fresh
274
+ // instance after recovery, so listeners registered before the outage must
275
+ // be re-registered (see "Service instance caching" in What's New 2.5.8).
276
+ O2G.eventSummary.on(EventSummary.ON_EVENT_SUMMARY_UPDATED, onEventSummary);
251
277
  });
252
278
 
253
279
  O2G.on(O2G.O2G_SERVER_SWITCHED, ({ from, to }) => {
@@ -11420,6 +11420,34 @@ class O2G {
11420
11420
  throw new Error('O2G has already been initialized.');
11421
11421
  }
11422
11422
  this._application = new o2g_application_1.default(appName, servers, apiVersion);
11423
+ // Service instances are cached per session (see getters below).
11424
+ // On O2G_SESSION_LOST the cache is cleared so stale references are dropped
11425
+ // immediately. On O2G_RECONNECTED the cache is cleared again so that the
11426
+ // first post-recovery access always creates a fresh instance bound to the
11427
+ // new Session — regardless of any transient access that may have occurred
11428
+ // during the outage. Both listeners are registered first so they run before
11429
+ // any application-level handlers (EventEmitter preserves registration order).
11430
+ this._application.on(o2g_application_1.O2G_SESSION_LOST, () => this._clearServiceCache());
11431
+ this._application.on(o2g_application_1.O2G_RECONNECTED, () => this._clearServiceCache());
11432
+ }
11433
+ static _clearServiceCache() {
11434
+ this._routing = null;
11435
+ this._eventSummary = null;
11436
+ this._users = null;
11437
+ this._usersManagement = null;
11438
+ this._telephony = null;
11439
+ this._directory = null;
11440
+ this._comlog = null;
11441
+ this._analytics = null;
11442
+ this._callCenterAgent = null;
11443
+ this._callCenterPilot = null;
11444
+ this._callCenterRealtime = null;
11445
+ this._callCenterStatistics = null;
11446
+ this._callCenterManagement = null;
11447
+ this._maintenance = null;
11448
+ this._pbxManagement = null;
11449
+ this._phoneSetProgramming = null;
11450
+ this._messaging = null;
11423
11451
  }
11424
11452
  /**
11425
11453
  * Sets a custom {@link SessionMonitoringPolicy} to control how the SDK
@@ -11533,7 +11561,7 @@ class O2G {
11533
11561
  static get routing() {
11534
11562
  if (!this._application)
11535
11563
  throw new Error('Routing service not available.');
11536
- return this._application.getRoutingService();
11564
+ return this._routing ?? (this._routing = this._application.getRoutingService());
11537
11565
  }
11538
11566
  /**
11539
11567
  * Returns the {@link EventSummary} service, which provides access to event summary counters.
@@ -11542,7 +11570,7 @@ class O2G {
11542
11570
  static get eventSummary() {
11543
11571
  if (!this._application)
11544
11572
  throw new Error('EventSummary service not available.');
11545
- return this._application.getEventSummaryService();
11573
+ return this._eventSummary ?? (this._eventSummary = this._application.getEventSummaryService());
11546
11574
  }
11547
11575
  /**
11548
11576
  * Returns the {@link Users} service, which provides user profile and preference management.
@@ -11551,7 +11579,7 @@ class O2G {
11551
11579
  static get users() {
11552
11580
  if (!this._application)
11553
11581
  throw new Error('Users service not available.');
11554
- return this._application.getUsersService();
11582
+ return this._users ?? (this._users = this._application.getUsersService());
11555
11583
  }
11556
11584
  /**
11557
11585
  * Returns the {@link UsersManagement} service, which provides administrator-level user management.
@@ -11560,7 +11588,7 @@ class O2G {
11560
11588
  static get usersManagement() {
11561
11589
  if (!this._application)
11562
11590
  throw new Error('UsersManagement service not available.');
11563
- return this._application.getUserManagementService();
11591
+ return this._usersManagement ?? (this._usersManagement = this._application.getUserManagementService());
11564
11592
  }
11565
11593
  /**
11566
11594
  * Returns the {@link Telephony} service, which provides call control and telephony operations.
@@ -11569,7 +11597,7 @@ class O2G {
11569
11597
  static get telephony() {
11570
11598
  if (!this._application)
11571
11599
  throw new Error('Telephony service not available.');
11572
- return this._application.getTelephonyService();
11600
+ return this._telephony ?? (this._telephony = this._application.getTelephonyService());
11573
11601
  }
11574
11602
  /**
11575
11603
  * Returns the {@link Directory} service, which provides enterprise directory search.
@@ -11578,7 +11606,7 @@ class O2G {
11578
11606
  static get directory() {
11579
11607
  if (!this._application)
11580
11608
  throw new Error('Directory service not available.');
11581
- return this._application.getDirectoryService();
11609
+ return this._directory ?? (this._directory = this._application.getDirectoryService());
11582
11610
  }
11583
11611
  /**
11584
11612
  * Returns the {@link CommunicationLog} service, which provides access to communication history records.
@@ -11587,7 +11615,7 @@ class O2G {
11587
11615
  static get comlog() {
11588
11616
  if (!this._application)
11589
11617
  throw new Error('CommunicationLog service not available.');
11590
- return this._application.getCommunicationLogService();
11618
+ return this._comlog ?? (this._comlog = this._application.getCommunicationLogService());
11591
11619
  }
11592
11620
  /**
11593
11621
  * Returns the {@link Analytics} service, which provides access to charging and incident data.
@@ -11596,7 +11624,7 @@ class O2G {
11596
11624
  static get analytics() {
11597
11625
  if (!this._application)
11598
11626
  throw new Error('Analytics service not available.');
11599
- return this._application.getAnalyticsService();
11627
+ return this._analytics ?? (this._analytics = this._application.getAnalyticsService());
11600
11628
  }
11601
11629
  /**
11602
11630
  * Returns the {@link CallCenterAgent} service, which provides ACD agent state and skill management.
@@ -11605,7 +11633,7 @@ class O2G {
11605
11633
  static get callCenterAgent() {
11606
11634
  if (!this._application)
11607
11635
  throw new Error('CallCenterAgent service not available.');
11608
- return this._application.getCallCenterAgentService();
11636
+ return this._callCenterAgent ?? (this._callCenterAgent = this._application.getCallCenterAgentService());
11609
11637
  }
11610
11638
  /**
11611
11639
  * Returns the {@link CallCenterPilot} service, which provides CCD pilot monitoring.
@@ -11614,7 +11642,7 @@ class O2G {
11614
11642
  static get callCenterPilot() {
11615
11643
  if (!this._application)
11616
11644
  throw new Error('CallCenterPilot service not available.');
11617
- return this._application.getCallCenterPilotService();
11645
+ return this._callCenterPilot ?? (this._callCenterPilot = this._application.getCallCenterPilotService());
11618
11646
  }
11619
11647
  /**
11620
11648
  * Returns the {@link CallCenterRealtime} service, which provides real-time ACD statistics and RTI data.
@@ -11623,7 +11651,7 @@ class O2G {
11623
11651
  static get callCenterRealtime() {
11624
11652
  if (!this._application)
11625
11653
  throw new Error('CallCenterRealtime service not available.');
11626
- return this._application.getCallCenterRealtimeService();
11654
+ return this._callCenterRealtime ?? (this._callCenterRealtime = this._application.getCallCenterRealtimeService());
11627
11655
  }
11628
11656
  /**
11629
11657
  * Returns the {@link CallCenterStatistics} service, which provides historical ACD statistics and reporting.
@@ -11632,7 +11660,7 @@ class O2G {
11632
11660
  static get callCenterStatistics() {
11633
11661
  if (!this._application)
11634
11662
  throw new Error('CallCenterStatistics service not available.');
11635
- return this._application.getCallCenterStatisticsService();
11663
+ return this._callCenterStatistics ?? (this._callCenterStatistics = this._application.getCallCenterStatisticsService());
11636
11664
  }
11637
11665
  /**
11638
11666
  * Returns the {@link CallCenterManagement} service, which provides CCD pilot and calendar management.
@@ -11641,7 +11669,7 @@ class O2G {
11641
11669
  static get callCenterManagement() {
11642
11670
  if (!this._application)
11643
11671
  throw new Error('CallCenterManagement service not available.');
11644
- return this._application.getCallCenterManagementService();
11672
+ return this._callCenterManagement ?? (this._callCenterManagement = this._application.getCallCenterManagementService());
11645
11673
  }
11646
11674
  /**
11647
11675
  * Returns the {@link Maintenance} service, which provides system status and PBX health information.
@@ -11650,7 +11678,7 @@ class O2G {
11650
11678
  static get maintenance() {
11651
11679
  if (!this._application)
11652
11680
  throw new Error('Maintenance service not available.');
11653
- return this._application.getMaintenanceService();
11681
+ return this._maintenance ?? (this._maintenance = this._application.getMaintenanceService());
11654
11682
  }
11655
11683
  /**
11656
11684
  * Returns the {@link PbxManagement} service, which provides PBX object model access and configuration.
@@ -11659,7 +11687,7 @@ class O2G {
11659
11687
  static get pbxManagement() {
11660
11688
  if (!this._application)
11661
11689
  throw new Error('PbxManagement service not available.');
11662
- return this._application.getPbxManagementService();
11690
+ return this._pbxManagement ?? (this._pbxManagement = this._application.getPbxManagementService());
11663
11691
  }
11664
11692
  /**
11665
11693
  * Returns the {@link PhoneSetProgramming} service, which provides phone device key and pin management.
@@ -11668,7 +11696,7 @@ class O2G {
11668
11696
  static get phoneSetProgramming() {
11669
11697
  if (!this._application)
11670
11698
  throw new Error('PhoneSetProgramming service not available.');
11671
- return this._application.getPhoneSetProgrammingService();
11699
+ return this._phoneSetProgramming ?? (this._phoneSetProgramming = this._application.getPhoneSetProgrammingService());
11672
11700
  }
11673
11701
  /**
11674
11702
  * Returns the {@link Messaging} service, which provides voicemail and mailbox management.
@@ -11677,7 +11705,7 @@ class O2G {
11677
11705
  static get messaging() {
11678
11706
  if (!this._application)
11679
11707
  throw new Error('Messaging service not available.');
11680
- return this._application.getMessagingService();
11708
+ return this._messaging ?? (this._messaging = this._application.getMessagingService());
11681
11709
  }
11682
11710
  }
11683
11711
  exports.O2G = O2G;