@layercode/js-sdk 2.5.0 → 2.6.0
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.
|
@@ -4095,11 +4095,30 @@ class LayercodeClient {
|
|
|
4095
4095
|
}
|
|
4096
4096
|
}
|
|
4097
4097
|
_stopAmplitudeMonitoring() {
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
|
|
4098
|
+
this._stopPlayerAmplitudeMonitoring();
|
|
4099
|
+
this._stopRecorderAmplitudeMonitoring();
|
|
4100
|
+
}
|
|
4101
|
+
_stopPlayerAmplitudeMonitoring() {
|
|
4102
|
+
var _a;
|
|
4103
|
+
this.agentAudioAmplitude = 0;
|
|
4104
|
+
if (this.options.enableAmplitudeMonitoring && this.options.onAgentAmplitudeChange !== NOOP) {
|
|
4105
|
+
this.options.onAgentAmplitudeChange(0);
|
|
4106
|
+
}
|
|
4107
|
+
if (this.stopPlayerAmplitude) {
|
|
4108
|
+
(_a = this.stopPlayerAmplitude) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
4109
|
+
this.stopPlayerAmplitude = undefined;
|
|
4110
|
+
}
|
|
4111
|
+
}
|
|
4112
|
+
_stopRecorderAmplitudeMonitoring() {
|
|
4113
|
+
var _a;
|
|
4114
|
+
this.userAudioAmplitude = 0;
|
|
4115
|
+
if (this.options.enableAmplitudeMonitoring && this.options.onUserAmplitudeChange !== NOOP) {
|
|
4116
|
+
this.options.onUserAmplitudeChange(0);
|
|
4117
|
+
}
|
|
4118
|
+
if (this.stopRecorderAmplitude) {
|
|
4119
|
+
(_a = this.stopRecorderAmplitude) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
4120
|
+
this.stopRecorderAmplitude = undefined;
|
|
4121
|
+
}
|
|
4103
4122
|
}
|
|
4104
4123
|
async audioInputConnect() {
|
|
4105
4124
|
// Turn mic ON
|
|
@@ -4108,10 +4127,9 @@ class LayercodeClient {
|
|
|
4108
4127
|
this._setupDeviceChangeListener();
|
|
4109
4128
|
}
|
|
4110
4129
|
async audioInputDisconnect() {
|
|
4111
|
-
var _a;
|
|
4112
4130
|
try {
|
|
4113
4131
|
// stop amplitude monitoring tied to the recorder
|
|
4114
|
-
|
|
4132
|
+
this._stopRecorderAmplitudeMonitoring();
|
|
4115
4133
|
// Try a graceful stop; end() already stops tracks and closes the AudioContext
|
|
4116
4134
|
await this.wavRecorder.end();
|
|
4117
4135
|
this.stopVad();
|
|
@@ -4119,7 +4137,7 @@ class LayercodeClient {
|
|
|
4119
4137
|
this._teardownDeviceListeners();
|
|
4120
4138
|
this.recorderStarted = false;
|
|
4121
4139
|
}
|
|
4122
|
-
catch (
|
|
4140
|
+
catch (_a) {
|
|
4123
4141
|
// If there wasn't an active session, just release any stray tracks
|
|
4124
4142
|
const stream = this.wavRecorder.getStream();
|
|
4125
4143
|
stream === null || stream === void 0 ? void 0 : stream.getTracks().forEach((t) => t.stop());
|
|
@@ -4360,16 +4378,15 @@ class LayercodeClient {
|
|
|
4360
4378
|
* Restarts audio recording after a device switch to ensure audio is captured from the new device
|
|
4361
4379
|
*/
|
|
4362
4380
|
async _restartAudioRecording() {
|
|
4363
|
-
var _a, _b
|
|
4381
|
+
var _a, _b;
|
|
4364
4382
|
try {
|
|
4365
4383
|
console.debug('Restarting audio recording after device switch...');
|
|
4366
4384
|
// Stop amplitude monitoring tied to the previous recording session before tearing it down
|
|
4367
|
-
|
|
4368
|
-
this.stopRecorderAmplitude = undefined;
|
|
4385
|
+
this._stopRecorderAmplitudeMonitoring();
|
|
4369
4386
|
try {
|
|
4370
4387
|
await this.wavRecorder.end();
|
|
4371
4388
|
}
|
|
4372
|
-
catch (
|
|
4389
|
+
catch (_c) {
|
|
4373
4390
|
// Ignore cleanup errors
|
|
4374
4391
|
}
|
|
4375
4392
|
// Start with new device
|
|
@@ -4391,7 +4408,7 @@ class LayercodeClient {
|
|
|
4391
4408
|
this.recorderStarted = true;
|
|
4392
4409
|
this._sendReadyIfNeeded();
|
|
4393
4410
|
}
|
|
4394
|
-
const reportedDeviceId = (
|
|
4411
|
+
const reportedDeviceId = (_a = this.activeDeviceId) !== null && _a !== void 0 ? _a : (this.useSystemDefaultDevice ? 'default' : (_b = this.deviceId) !== null && _b !== void 0 ? _b : 'default');
|
|
4395
4412
|
if (reportedDeviceId !== previousReportedDeviceId) {
|
|
4396
4413
|
this.lastReportedDeviceId = reportedDeviceId;
|
|
4397
4414
|
if (this.options.onDeviceSwitched) {
|
|
@@ -4535,6 +4552,7 @@ class LayercodeClient {
|
|
|
4535
4552
|
console.log('Microphone muted');
|
|
4536
4553
|
this.options.onMuteStateChange(true);
|
|
4537
4554
|
this.stopVad();
|
|
4555
|
+
this._stopRecorderAmplitudeMonitoring();
|
|
4538
4556
|
}
|
|
4539
4557
|
}
|
|
4540
4558
|
/**
|
|
@@ -4546,6 +4564,9 @@ class LayercodeClient {
|
|
|
4546
4564
|
console.log('Microphone unmuted');
|
|
4547
4565
|
this.options.onMuteStateChange(false);
|
|
4548
4566
|
this._initializeVAD();
|
|
4567
|
+
if (this.stopRecorderAmplitude === undefined) {
|
|
4568
|
+
this._setupAmplitudeMonitoring(this.wavRecorder, this.options.onUserAmplitudeChange, (amp) => (this.userAudioAmplitude = amp));
|
|
4569
|
+
}
|
|
4549
4570
|
}
|
|
4550
4571
|
}
|
|
4551
4572
|
}
|