@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.
@@ -4101,11 +4101,30 @@ registerProcessor('audio_processor', AudioProcessor);
4101
4101
  }
4102
4102
  }
4103
4103
  _stopAmplitudeMonitoring() {
4104
- var _a, _b;
4105
- (_a = this.stopPlayerAmplitude) === null || _a === void 0 ? void 0 : _a.call(this);
4106
- (_b = this.stopRecorderAmplitude) === null || _b === void 0 ? void 0 : _b.call(this);
4107
- this.stopPlayerAmplitude = undefined;
4108
- this.stopRecorderAmplitude = undefined;
4104
+ this._stopPlayerAmplitudeMonitoring();
4105
+ this._stopRecorderAmplitudeMonitoring();
4106
+ }
4107
+ _stopPlayerAmplitudeMonitoring() {
4108
+ var _a;
4109
+ this.agentAudioAmplitude = 0;
4110
+ if (this.options.enableAmplitudeMonitoring && this.options.onAgentAmplitudeChange !== NOOP) {
4111
+ this.options.onAgentAmplitudeChange(0);
4112
+ }
4113
+ if (this.stopPlayerAmplitude) {
4114
+ (_a = this.stopPlayerAmplitude) === null || _a === void 0 ? void 0 : _a.call(this);
4115
+ this.stopPlayerAmplitude = undefined;
4116
+ }
4117
+ }
4118
+ _stopRecorderAmplitudeMonitoring() {
4119
+ var _a;
4120
+ this.userAudioAmplitude = 0;
4121
+ if (this.options.enableAmplitudeMonitoring && this.options.onUserAmplitudeChange !== NOOP) {
4122
+ this.options.onUserAmplitudeChange(0);
4123
+ }
4124
+ if (this.stopRecorderAmplitude) {
4125
+ (_a = this.stopRecorderAmplitude) === null || _a === void 0 ? void 0 : _a.call(this);
4126
+ this.stopRecorderAmplitude = undefined;
4127
+ }
4109
4128
  }
4110
4129
  async audioInputConnect() {
4111
4130
  // Turn mic ON
@@ -4114,10 +4133,9 @@ registerProcessor('audio_processor', AudioProcessor);
4114
4133
  this._setupDeviceChangeListener();
4115
4134
  }
4116
4135
  async audioInputDisconnect() {
4117
- var _a;
4118
4136
  try {
4119
4137
  // stop amplitude monitoring tied to the recorder
4120
- (_a = this.stopRecorderAmplitude) === null || _a === void 0 ? void 0 : _a.call(this);
4138
+ this._stopRecorderAmplitudeMonitoring();
4121
4139
  // Try a graceful stop; end() already stops tracks and closes the AudioContext
4122
4140
  await this.wavRecorder.end();
4123
4141
  this.stopVad();
@@ -4125,7 +4143,7 @@ registerProcessor('audio_processor', AudioProcessor);
4125
4143
  this._teardownDeviceListeners();
4126
4144
  this.recorderStarted = false;
4127
4145
  }
4128
- catch (_b) {
4146
+ catch (_a) {
4129
4147
  // If there wasn't an active session, just release any stray tracks
4130
4148
  const stream = this.wavRecorder.getStream();
4131
4149
  stream === null || stream === void 0 ? void 0 : stream.getTracks().forEach((t) => t.stop());
@@ -4366,16 +4384,15 @@ registerProcessor('audio_processor', AudioProcessor);
4366
4384
  * Restarts audio recording after a device switch to ensure audio is captured from the new device
4367
4385
  */
4368
4386
  async _restartAudioRecording() {
4369
- var _a, _b, _c;
4387
+ var _a, _b;
4370
4388
  try {
4371
4389
  console.debug('Restarting audio recording after device switch...');
4372
4390
  // Stop amplitude monitoring tied to the previous recording session before tearing it down
4373
- (_a = this.stopRecorderAmplitude) === null || _a === void 0 ? void 0 : _a.call(this);
4374
- this.stopRecorderAmplitude = undefined;
4391
+ this._stopRecorderAmplitudeMonitoring();
4375
4392
  try {
4376
4393
  await this.wavRecorder.end();
4377
4394
  }
4378
- catch (_d) {
4395
+ catch (_c) {
4379
4396
  // Ignore cleanup errors
4380
4397
  }
4381
4398
  // Start with new device
@@ -4397,7 +4414,7 @@ registerProcessor('audio_processor', AudioProcessor);
4397
4414
  this.recorderStarted = true;
4398
4415
  this._sendReadyIfNeeded();
4399
4416
  }
4400
- const reportedDeviceId = (_b = this.activeDeviceId) !== null && _b !== void 0 ? _b : (this.useSystemDefaultDevice ? 'default' : (_c = this.deviceId) !== null && _c !== void 0 ? _c : 'default');
4417
+ const reportedDeviceId = (_a = this.activeDeviceId) !== null && _a !== void 0 ? _a : (this.useSystemDefaultDevice ? 'default' : (_b = this.deviceId) !== null && _b !== void 0 ? _b : 'default');
4401
4418
  if (reportedDeviceId !== previousReportedDeviceId) {
4402
4419
  this.lastReportedDeviceId = reportedDeviceId;
4403
4420
  if (this.options.onDeviceSwitched) {
@@ -4541,6 +4558,7 @@ registerProcessor('audio_processor', AudioProcessor);
4541
4558
  console.log('Microphone muted');
4542
4559
  this.options.onMuteStateChange(true);
4543
4560
  this.stopVad();
4561
+ this._stopRecorderAmplitudeMonitoring();
4544
4562
  }
4545
4563
  }
4546
4564
  /**
@@ -4552,6 +4570,9 @@ registerProcessor('audio_processor', AudioProcessor);
4552
4570
  console.log('Microphone unmuted');
4553
4571
  this.options.onMuteStateChange(false);
4554
4572
  this._initializeVAD();
4573
+ if (this.stopRecorderAmplitude === undefined) {
4574
+ this._setupAmplitudeMonitoring(this.wavRecorder, this.options.onUserAmplitudeChange, (amp) => (this.userAudioAmplitude = amp));
4575
+ }
4555
4576
  }
4556
4577
  }
4557
4578
  }