@sendbird/ai-agent-messenger-react 1.34.1 → 1.34.2

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/dist/index.d.ts CHANGED
@@ -5050,9 +5050,11 @@ declare class LiveMetricManager {
5050
5050
  this.dispatch?.({ category, metricKey, data });
5051
5051
  };
5052
5052
  private readonly emitters: Record<MetricSource['type'], LiveMetricEmitter>;
5053
+ private isStarted = false;
5054
+ private registeredChatSDK?: ChatSDKType;
5053
5055
 
5054
- constructor(private readonly chatSDK: ChatSDKType) {
5055
- const getCurrentUserId = () => this.chatSDK.currentUser?.userId;
5056
+ constructor() {
5057
+ const getCurrentUserId = () => this.registeredChatSDK?.currentUser?.userId;
5056
5058
  this.emitters = {
5057
5059
  connection: new ConnectionMetricEmitter(this.emit),
5058
5060
  conversation: new ConversationMetricEmitter(this.emit),
@@ -5062,7 +5064,9 @@ declare class LiveMetricManager {
5062
5064
  };
5063
5065
  }
5064
5066
 
5065
- start(): void {
5067
+ start(chatSDK: ChatSDKType): void {
5068
+ if (this.isStarted) return;
5069
+
5066
5070
  const connectionHandler = new ConnectionHandler({
5067
5071
  onConnected: (userId) => this.trackConnection('connected', userId),
5068
5072
  onDisconnected: (userId) => this.trackConnection('disconnected', userId),
@@ -5087,8 +5091,10 @@ declare class LiveMetricManager {
5087
5091
  onUserLeft: (channel) => this.track({ type: 'handoff', channel }),
5088
5092
  });
5089
5093
 
5090
- this.chatSDK.addConnectionHandler(this.id, connectionHandler);
5091
- this.chatSDK.groupChannel.addGroupChannelHandler(this.id, channelHandler);
5094
+ chatSDK.addConnectionHandler(this.id, connectionHandler);
5095
+ chatSDK.groupChannel.addGroupChannelHandler(this.id, channelHandler);
5096
+ this.registeredChatSDK = chatSDK;
5097
+ this.isStarted = true;
5092
5098
  }
5093
5099
 
5094
5100
  /**
@@ -5104,11 +5110,15 @@ declare class LiveMetricManager {
5104
5110
  }
5105
5111
 
5106
5112
  dispose(): void {
5107
- this.chatSDK.removeConnectionHandler(this.id);
5108
- this.chatSDK.groupChannel.removeGroupChannelHandler(this.id);
5113
+ if (!this.isStarted || !this.registeredChatSDK) return;
5114
+
5115
+ this.registeredChatSDK.removeConnectionHandler(this.id);
5116
+ this.registeredChatSDK.groupChannel.removeGroupChannelHandler(this.id);
5117
+ this.registeredChatSDK = undefined;
5118
+ this.isStarted = false;
5109
5119
  }
5110
5120
 
5111
- private trackConnection(detail: ConnectionEventDetail, userId = this.chatSDK.currentUser?.userId): void {
5121
+ private trackConnection(detail: ConnectionEventDetail, userId = this.registeredChatSDK?.currentUser?.userId): void {
5112
5122
  if (userId) this.track({ type: 'connection', detail, userId });
5113
5123
  }
5114
5124
  }