@layercode/js-sdk 2.8.4 → 2.8.5
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.
|
@@ -6202,27 +6202,34 @@ class LayercodeClient {
|
|
|
6202
6202
|
* @param {ArrayBuffer} data - The audio data buffer
|
|
6203
6203
|
*/
|
|
6204
6204
|
_handleDataAvailable(data) {
|
|
6205
|
-
var _a, _b, _c;
|
|
6205
|
+
var _a, _b, _c, _d;
|
|
6206
6206
|
try {
|
|
6207
|
-
|
|
6208
|
-
//
|
|
6207
|
+
// Don't send or buffer audio if muted. Also clear any stale buffer so we
|
|
6208
|
+
// don't accidentally flush old audio after unmute.
|
|
6209
6209
|
if (this.isMuted) {
|
|
6210
|
+
this.audioBuffer = [];
|
|
6210
6211
|
return;
|
|
6211
6212
|
}
|
|
6212
6213
|
// Determine if we should gate audio based on VAD configuration
|
|
6213
|
-
const shouldGateAudio = ((_a = this.vadConfig) === null || _a === void 0 ? void 0 : _a.gate_audio) !== false; //
|
|
6214
|
-
const bufferFrames = (_c = (_b = this.vadConfig) === null || _b === void 0 ? void 0 : _b.buffer_frames) !== null && _c !== void 0 ? _c : 10; //
|
|
6214
|
+
const shouldGateAudio = ((_a = this.vadConfig) === null || _a === void 0 ? void 0 : _a.gate_audio) !== false; // default true
|
|
6215
|
+
const bufferFrames = (_c = (_b = this.vadConfig) === null || _b === void 0 ? void 0 : _b.buffer_frames) !== null && _c !== void 0 ? _c : 10; // default 10
|
|
6216
|
+
// If VAD is disabled or failed to init, gating would deadlock (userIsSpeaking never flips true).
|
|
6217
|
+
// Only gate if we actually have a running VAD instance.
|
|
6218
|
+
const vadEnabledByConfig = ((_d = this.vadConfig) === null || _d === void 0 ? void 0 : _d.enabled) !== false; // default true
|
|
6219
|
+
const vadAvailable = vadEnabledByConfig && !!this.vad && !this.pushToTalkEnabled;
|
|
6215
6220
|
let sendAudio;
|
|
6216
6221
|
if (this.pushToTalkEnabled) {
|
|
6217
6222
|
sendAudio = this.pushToTalkActive;
|
|
6218
6223
|
}
|
|
6219
6224
|
else if (shouldGateAudio) {
|
|
6220
|
-
|
|
6225
|
+
// Key fix: if VAD isn't available, don't gate — send audio.
|
|
6226
|
+
sendAudio = vadAvailable ? this.userIsSpeaking : true;
|
|
6221
6227
|
}
|
|
6222
6228
|
else {
|
|
6223
6229
|
// If gate_audio is false, always send audio
|
|
6224
6230
|
sendAudio = true;
|
|
6225
6231
|
}
|
|
6232
|
+
const base64 = arrayBufferToBase64(data.mono);
|
|
6226
6233
|
if (sendAudio) {
|
|
6227
6234
|
// If we have buffered audio and we're gating, send it first
|
|
6228
6235
|
if (shouldGateAudio && this.audioBuffer.length > 0) {
|
|
@@ -6395,13 +6402,17 @@ class LayercodeClient {
|
|
|
6395
6402
|
this.recorderStarted = true;
|
|
6396
6403
|
this._sendReadyIfNeeded();
|
|
6397
6404
|
}
|
|
6398
|
-
const reportedDeviceId = (_a = this.activeDeviceId) !== null && _a !== void 0 ? _a : (this.useSystemDefaultDevice ? 'default' : (
|
|
6405
|
+
const reportedDeviceId = (_a = this.activeDeviceId) !== null && _a !== void 0 ? _a : (this.useSystemDefaultDevice ? 'default' : (_b = this.deviceId) !== null && _b !== void 0 ? _b : 'default');
|
|
6399
6406
|
if (reportedDeviceId !== this.lastReportedDeviceId) {
|
|
6400
6407
|
this.lastReportedDeviceId = reportedDeviceId;
|
|
6401
6408
|
if (this.options.onDeviceSwitched) {
|
|
6402
6409
|
this.options.onDeviceSwitched(reportedDeviceId);
|
|
6403
6410
|
}
|
|
6404
6411
|
}
|
|
6412
|
+
// Ensure automatic mode has a VAD instance once the recorder stream is live
|
|
6413
|
+
if (!this.vad && !this.pushToTalkEnabled) {
|
|
6414
|
+
await this._initializeVAD();
|
|
6415
|
+
}
|
|
6405
6416
|
console.debug('Recorder started successfully with device:', reportedDeviceId);
|
|
6406
6417
|
}
|
|
6407
6418
|
catch (error) {
|
|
@@ -6728,7 +6739,7 @@ class LayercodeClient {
|
|
|
6728
6739
|
const newStream = this.wavRecorder.getStream();
|
|
6729
6740
|
await this._reinitializeVAD(newStream);
|
|
6730
6741
|
}
|
|
6731
|
-
const reportedDeviceId = (_c = (_b = this.lastReportedDeviceId) !== null && _b !== void 0 ? _b : this.activeDeviceId) !== null && _c !== void 0 ? _c : (this.useSystemDefaultDevice ? 'default' :
|
|
6742
|
+
const reportedDeviceId = (_c = (_b = this.lastReportedDeviceId) !== null && _b !== void 0 ? _b : this.activeDeviceId) !== null && _c !== void 0 ? _c : (this.useSystemDefaultDevice ? 'default' : normalizedDeviceId !== null && normalizedDeviceId !== void 0 ? normalizedDeviceId : 'default');
|
|
6732
6743
|
console.debug(`Successfully switched to input device: ${reportedDeviceId}`);
|
|
6733
6744
|
}
|
|
6734
6745
|
catch (error) {
|
|
@@ -6782,7 +6793,7 @@ class LayercodeClient {
|
|
|
6782
6793
|
this.recorderStarted = true;
|
|
6783
6794
|
this._sendReadyIfNeeded();
|
|
6784
6795
|
}
|
|
6785
|
-
const reportedDeviceId = (_a = this.activeDeviceId) !== null && _a !== void 0 ? _a : (this.useSystemDefaultDevice ? 'default' : (
|
|
6796
|
+
const reportedDeviceId = (_a = this.activeDeviceId) !== null && _a !== void 0 ? _a : (this.useSystemDefaultDevice ? 'default' : (_b = this.deviceId) !== null && _b !== void 0 ? _b : 'default');
|
|
6786
6797
|
if (reportedDeviceId !== previousReportedDeviceId) {
|
|
6787
6798
|
this.lastReportedDeviceId = reportedDeviceId;
|
|
6788
6799
|
if (this.options.onDeviceSwitched) {
|
|
@@ -7027,11 +7038,7 @@ class LayercodeClient {
|
|
|
7027
7038
|
async _shouldWarnAudioDevicesRequireUserGesture(error) {
|
|
7028
7039
|
const e = error;
|
|
7029
7040
|
const name = typeof (e === null || e === void 0 ? void 0 : e.name) === 'string' ? e.name : '';
|
|
7030
|
-
const msg = typeof (e === null || e === void 0 ? void 0 : e.message) === 'string'
|
|
7031
|
-
? e.message
|
|
7032
|
-
: typeof error === 'string'
|
|
7033
|
-
? error
|
|
7034
|
-
: '';
|
|
7041
|
+
const msg = typeof (e === null || e === void 0 ? void 0 : e.message) === 'string' ? e.message : typeof error === 'string' ? error : '';
|
|
7035
7042
|
const isPermissionLike = name === 'NotAllowedError' || name === 'SecurityError' || name === 'PermissionDeniedError';
|
|
7036
7043
|
if (!isPermissionLike)
|
|
7037
7044
|
return false;
|