@layercode/js-sdk 2.8.9 → 2.8.10

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.
@@ -6870,6 +6870,23 @@ class LayercodeClient {
6870
6870
  * Disconnect VAD
6871
6871
  */
6872
6872
  stopVad() {
6873
+ // If user was speaking when VAD is destroyed, send synthetic vad_end to server
6874
+ // This ensures the server receives vad_end even when VAD is destroyed mid-speech
6875
+ // (e.g., due to mute, device change, or disconnect)
6876
+ // Only send if VAD is actually running (not for push-to-talk which uses trigger.turn events)
6877
+ if (this.userIsSpeaking && this.vad) {
6878
+ console.debug('[Layercode]: sending synthetic vad_end (VAD destroyed mid-speech)');
6879
+ this._setUserSpeaking(false); // Update state before callbacks (consistent with onSpeechEnd)
6880
+ const vadEndMessage = {
6881
+ type: 'vad_events',
6882
+ event: 'vad_end',
6883
+ };
6884
+ this._wsSend(vadEndMessage);
6885
+ this.options.onMessage({
6886
+ ...vadEndMessage,
6887
+ userSpeaking: this.userIsSpeaking,
6888
+ });
6889
+ }
6873
6890
  if (this.vad) {
6874
6891
  this.vad.pause();
6875
6892
  this.vad.destroy();