botium-connector-voip 0.0.27 → 0.0.28

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.
@@ -184,6 +184,7 @@ class BotiumConnectorVoip {
184
184
  debug$3(this.caps[Capabilities.VOIP_TTS_URL]);
185
185
  this.stopCalled = false;
186
186
  this.fullRecord = '';
187
+ this.fullRecordAttachmentEmitted = false;
187
188
  this.end = false;
188
189
  this.connected = false;
189
190
  this.convoStep = null;
@@ -703,6 +704,18 @@ class BotiumConnectorVoip {
703
704
  testSessionJobId: this.caps.VOIP_TEST_SESSION_JOB_ID || null
704
705
  }
705
706
  });
707
+ this.fullRecordAttachmentEmitted = true;
708
+ };
709
+ this._emitBufferedFullRecordIfAny = reason => {
710
+ if (this.fullRecordAttachmentEmitted) return false;
711
+ if (!this.fullRecord || typeof this.fullRecord !== 'string' || this.fullRecord.length === 0) return false;
712
+ emitFullRecordAttachment(this.fullRecord);
713
+ _info('recording_attached', {
714
+ sessionId: this.sessionId,
715
+ source: reason,
716
+ base64Len: this.fullRecord.length
717
+ });
718
+ return true;
706
719
  };
707
720
  if (parsedData && parsedData.type === 'callinfo' && parsedData.status === 'initialized') {
708
721
  this.sessionId = parsedData.voipConfig.sessionId;
@@ -749,6 +762,9 @@ class BotiumConnectorVoip {
749
762
  sttPartialCount: this.sttPartialCount
750
763
  });
751
764
  flushPendingBotMsgs('callinfo_disconnected');
765
+ // Some workers may disconnect without sending fullRecordEnd.
766
+ // If we already buffered full-record chunks, emit them now.
767
+ this._emitBufferedFullRecordIfAny('callinfo_disconnected_buffered');
752
768
  const apiKey = this._extractApiKey(this._getBody(Capabilities.VOIP_STT_BODY));
753
769
  if (parsedData.connectDuration && parsedData.connectDuration > 0) {
754
770
  this.eventEmitter.emit('CONSUMPTION_METADATA', this, {
@@ -769,6 +785,8 @@ class BotiumConnectorVoip {
769
785
  }
770
786
  if (parsedData && parsedData.type === 'error') {
771
787
  flushPendingBotMsgs('error');
788
+ // Ensure buffered recording is not lost on terminal worker errors.
789
+ this._emitBufferedFullRecordIfAny('error_buffered');
772
790
  _info('ws_error_msg', {
773
791
  sessionId: this.sessionId,
774
792
  message: parsedData.message || null,
@@ -1279,13 +1297,22 @@ class BotiumConnectorVoip {
1279
1297
  }
1280
1298
  }, 100);
1281
1299
  });
1300
+ // Final guard: if worker never emitted fullRecordEnd/fullRecord but
1301
+ // chunks were buffered, publish the attachment before teardown.
1302
+ if (typeof this._emitBufferedFullRecordIfAny === 'function') {
1303
+ this._emitBufferedFullRecordIfAny('stop_final_guard');
1304
+ }
1282
1305
  } else {
1283
1306
  this.wsOpened = false;
1284
1307
  this.ws = null;
1285
1308
  this.end = false;
1286
1309
  this.convoStep = null;
1287
1310
  this.firstSttInfoReceived = false;
1311
+ if (typeof this._emitBufferedFullRecordIfAny === 'function') {
1312
+ this._emitBufferedFullRecordIfAny('stop_final_guard');
1313
+ }
1288
1314
  }
1315
+ this._emitBufferedFullRecordIfAny = null;
1289
1316
  }
1290
1317
  _isTtsCacheEnabled() {
1291
1318
  return this.ttsCacheEnabled && this.ttsCacheMaxEntries > 0;