@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.
|
@@ -3507,6 +3507,8 @@ registerProcessor('audio_processor', AudioProcessor);
|
|
|
3507
3507
|
this.pushToTalkEnabled = false;
|
|
3508
3508
|
this.canInterrupt = false;
|
|
3509
3509
|
this.userIsSpeaking = false;
|
|
3510
|
+
this.recorderStarted = false;
|
|
3511
|
+
this.readySent = false;
|
|
3510
3512
|
// Bind event handlers
|
|
3511
3513
|
this._handleWebSocketMessage = this._handleWebSocketMessage.bind(this);
|
|
3512
3514
|
this._handleDataAvailable = this._handleDataAvailable.bind(this);
|
|
@@ -3737,6 +3739,13 @@ registerProcessor('audio_processor', AudioProcessor);
|
|
|
3737
3739
|
this.ws.send(messageString);
|
|
3738
3740
|
}
|
|
3739
3741
|
}
|
|
3742
|
+
_sendReadyIfNeeded() {
|
|
3743
|
+
var _a;
|
|
3744
|
+
if (this.recorderStarted && ((_a = this.ws) === null || _a === void 0 ? void 0 : _a.readyState) === WebSocket.OPEN && !this.readySent) {
|
|
3745
|
+
this._wsSend({ type: 'client.ready' });
|
|
3746
|
+
this.readySent = true;
|
|
3747
|
+
}
|
|
3748
|
+
}
|
|
3740
3749
|
/**
|
|
3741
3750
|
* Sets up amplitude monitoring for a given audio source.
|
|
3742
3751
|
* @param {WavRecorder | WavStreamPlayer} source - The audio source (recorder or player).
|
|
@@ -3812,6 +3821,8 @@ registerProcessor('audio_processor', AudioProcessor);
|
|
|
3812
3821
|
console.log('WebSocket connection established');
|
|
3813
3822
|
this._setStatus('connected');
|
|
3814
3823
|
this.options.onConnect({ sessionId: this.sessionId });
|
|
3824
|
+
// Attempt to send ready message if recorder already started
|
|
3825
|
+
this._sendReadyIfNeeded();
|
|
3815
3826
|
};
|
|
3816
3827
|
this.ws.onclose = () => {
|
|
3817
3828
|
console.log('WebSocket connection closed');
|
|
@@ -3825,13 +3836,16 @@ registerProcessor('audio_processor', AudioProcessor);
|
|
|
3825
3836
|
};
|
|
3826
3837
|
// Initialize microphone audio capture
|
|
3827
3838
|
await this.wavRecorder.begin();
|
|
3828
|
-
await this.wavRecorder.record(this._handleDataAvailable);
|
|
3839
|
+
await this.wavRecorder.record(this._handleDataAvailable, 1638);
|
|
3829
3840
|
// Set up microphone amplitude monitoring
|
|
3830
3841
|
this._setupAmplitudeMonitoring(this.wavRecorder, this.options.onUserAmplitudeChange, (amp) => (this.userAudioAmplitude = amp));
|
|
3831
3842
|
// Initialize audio player
|
|
3832
3843
|
await this.wavPlayer.connect();
|
|
3833
3844
|
// Set up audio player amplitude monitoring
|
|
3834
3845
|
this._setupAmplitudeMonitoring(this.wavPlayer, this.options.onAgentAmplitudeChange, (amp) => (this.agentAudioAmplitude = amp));
|
|
3846
|
+
// Mark recorder as started and attempt to notify server
|
|
3847
|
+
this.recorderStarted = true;
|
|
3848
|
+
this._sendReadyIfNeeded();
|
|
3835
3849
|
}
|
|
3836
3850
|
catch (error) {
|
|
3837
3851
|
console.error('Error connecting to Layercode pipeline:', error);
|