@layercode/js-sdk 1.0.16 → 1.0.18

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.
@@ -3501,6 +3501,8 @@ class LayercodeClient {
3501
3501
  this.pushToTalkEnabled = false;
3502
3502
  this.canInterrupt = false;
3503
3503
  this.userIsSpeaking = false;
3504
+ this.recorderStarted = false;
3505
+ this.readySent = false;
3504
3506
  // Bind event handlers
3505
3507
  this._handleWebSocketMessage = this._handleWebSocketMessage.bind(this);
3506
3508
  this._handleDataAvailable = this._handleDataAvailable.bind(this);
@@ -3731,6 +3733,13 @@ class LayercodeClient {
3731
3733
  this.ws.send(messageString);
3732
3734
  }
3733
3735
  }
3736
+ _sendReadyIfNeeded() {
3737
+ var _a;
3738
+ if (this.recorderStarted && ((_a = this.ws) === null || _a === void 0 ? void 0 : _a.readyState) === WebSocket.OPEN && !this.readySent) {
3739
+ this._wsSend({ type: 'client.ready' });
3740
+ this.readySent = true;
3741
+ }
3742
+ }
3734
3743
  /**
3735
3744
  * Sets up amplitude monitoring for a given audio source.
3736
3745
  * @param {WavRecorder | WavStreamPlayer} source - The audio source (recorder or player).
@@ -3806,6 +3815,8 @@ class LayercodeClient {
3806
3815
  console.log('WebSocket connection established');
3807
3816
  this._setStatus('connected');
3808
3817
  this.options.onConnect({ sessionId: this.sessionId });
3818
+ // Attempt to send ready message if recorder already started
3819
+ this._sendReadyIfNeeded();
3809
3820
  };
3810
3821
  this.ws.onclose = () => {
3811
3822
  console.log('WebSocket connection closed');
@@ -3819,13 +3830,16 @@ class LayercodeClient {
3819
3830
  };
3820
3831
  // Initialize microphone audio capture
3821
3832
  await this.wavRecorder.begin();
3822
- await this.wavRecorder.record(this._handleDataAvailable);
3833
+ await this.wavRecorder.record(this._handleDataAvailable, 1638);
3823
3834
  // Set up microphone amplitude monitoring
3824
3835
  this._setupAmplitudeMonitoring(this.wavRecorder, this.options.onUserAmplitudeChange, (amp) => (this.userAudioAmplitude = amp));
3825
3836
  // Initialize audio player
3826
3837
  await this.wavPlayer.connect();
3827
3838
  // Set up audio player amplitude monitoring
3828
3839
  this._setupAmplitudeMonitoring(this.wavPlayer, this.options.onAgentAmplitudeChange, (amp) => (this.agentAudioAmplitude = amp));
3840
+ // Mark recorder as started and attempt to notify server
3841
+ this.recorderStarted = true;
3842
+ this._sendReadyIfNeeded();
3829
3843
  }
3830
3844
  catch (error) {
3831
3845
  console.error('Error connecting to Layercode pipeline:', error);