@layercode/js-sdk 2.0.5 → 2.0.6
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.
|
@@ -6402,6 +6402,7 @@ registerProcessor('audio_processor', AudioProcessor);
|
|
|
6402
6402
|
this.activeDeviceId = null;
|
|
6403
6403
|
this.useSystemDefaultDevice = false;
|
|
6404
6404
|
this.lastReportedDeviceId = null;
|
|
6405
|
+
this.lastKnownSystemDefaultDeviceKey = null;
|
|
6405
6406
|
this.isMuted = false;
|
|
6406
6407
|
// this.audioPauseTime = null;
|
|
6407
6408
|
// Bind event handlers
|
|
@@ -6780,6 +6781,7 @@ registerProcessor('audio_processor', AudioProcessor);
|
|
|
6780
6781
|
this.activeDeviceId = null;
|
|
6781
6782
|
this.useSystemDefaultDevice = false;
|
|
6782
6783
|
this.lastReportedDeviceId = null;
|
|
6784
|
+
this.lastKnownSystemDefaultDeviceKey = null;
|
|
6783
6785
|
this.recorderStarted = false;
|
|
6784
6786
|
this.readySent = false;
|
|
6785
6787
|
// Clean up VAD if it exists
|
|
@@ -6900,6 +6902,8 @@ registerProcessor('audio_processor', AudioProcessor);
|
|
|
6900
6902
|
try {
|
|
6901
6903
|
const defaultDevice = devices.find((device) => device.default);
|
|
6902
6904
|
const usingDefaultDevice = this.useSystemDefaultDevice;
|
|
6905
|
+
const previousDefaultDeviceKey = this.lastKnownSystemDefaultDeviceKey;
|
|
6906
|
+
const currentDefaultDeviceKey = this._getDeviceComparisonKey(defaultDevice);
|
|
6903
6907
|
let shouldSwitch = !this.recorderStarted;
|
|
6904
6908
|
if (!shouldSwitch) {
|
|
6905
6909
|
if (usingDefaultDevice) {
|
|
@@ -6911,12 +6915,17 @@ registerProcessor('audio_processor', AudioProcessor);
|
|
|
6911
6915
|
defaultDevice.deviceId !== this.activeDeviceId) {
|
|
6912
6916
|
shouldSwitch = true;
|
|
6913
6917
|
}
|
|
6918
|
+
else if ((previousDefaultDeviceKey && previousDefaultDeviceKey !== currentDefaultDeviceKey) ||
|
|
6919
|
+
(!previousDefaultDeviceKey && !currentDefaultDeviceKey && this.recorderStarted)) {
|
|
6920
|
+
shouldSwitch = true;
|
|
6921
|
+
}
|
|
6914
6922
|
}
|
|
6915
6923
|
else {
|
|
6916
6924
|
const matchesRequestedDevice = devices.some((device) => device.deviceId === this.deviceId || device.deviceId === this.activeDeviceId);
|
|
6917
6925
|
shouldSwitch = !matchesRequestedDevice;
|
|
6918
6926
|
}
|
|
6919
6927
|
}
|
|
6928
|
+
this.lastKnownSystemDefaultDeviceKey = currentDefaultDeviceKey;
|
|
6920
6929
|
if (shouldSwitch) {
|
|
6921
6930
|
console.debug('Selecting fallback audio input device');
|
|
6922
6931
|
const fallbackDevice = defaultDevice || devices[0];
|
|
@@ -6934,6 +6943,24 @@ registerProcessor('audio_processor', AudioProcessor);
|
|
|
6934
6943
|
}
|
|
6935
6944
|
});
|
|
6936
6945
|
}
|
|
6946
|
+
_getDeviceComparisonKey(device) {
|
|
6947
|
+
if (!device || typeof device !== 'object') {
|
|
6948
|
+
return null;
|
|
6949
|
+
}
|
|
6950
|
+
const deviceId = typeof device.deviceId === 'string' ? device.deviceId : '';
|
|
6951
|
+
if (deviceId && deviceId !== 'default') {
|
|
6952
|
+
return deviceId;
|
|
6953
|
+
}
|
|
6954
|
+
const groupId = typeof device.groupId === 'string' ? device.groupId : '';
|
|
6955
|
+
if (groupId) {
|
|
6956
|
+
return groupId;
|
|
6957
|
+
}
|
|
6958
|
+
const label = typeof device.label === 'string' ? device.label : '';
|
|
6959
|
+
if (label) {
|
|
6960
|
+
return label;
|
|
6961
|
+
}
|
|
6962
|
+
return null;
|
|
6963
|
+
}
|
|
6937
6964
|
/**
|
|
6938
6965
|
* Mutes the microphone to stop sending audio to the server
|
|
6939
6966
|
* The connection and recording remain active for quick unmute
|