@dtelecom/livekit-client 1.12.14 → 1.12.15
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.
- package/dist/livekit-client.esm.mjs +87 -8
- package/dist/livekit-client.esm.mjs.map +1 -1
- package/dist/livekit-client.umd.js +1 -1
- package/dist/livekit-client.umd.js.map +1 -1
- package/dist/src/room/DeviceManager.d.ts +3 -0
- package/dist/src/room/DeviceManager.d.ts.map +1 -1
- package/dist/src/room/Room.d.ts.map +1 -1
- package/dist/ts4.2/src/room/DeviceManager.d.ts +3 -0
- package/package.json +1 -1
- package/src/room/DeviceManager.ts +32 -5
- package/src/room/Room.ts +63 -2
|
@@ -14198,7 +14198,7 @@ function getMatch(exp, ua) {
|
|
|
14198
14198
|
return match && match.length >= id && match[id] || '';
|
|
14199
14199
|
}
|
|
14200
14200
|
|
|
14201
|
-
var version$1 = "1.12.
|
|
14201
|
+
var version$1 = "1.12.14";
|
|
14202
14202
|
|
|
14203
14203
|
const version = version$1;
|
|
14204
14204
|
const protocolVersion = 9;
|
|
@@ -15195,6 +15195,18 @@ function getNewAudioContext() {
|
|
|
15195
15195
|
});
|
|
15196
15196
|
}
|
|
15197
15197
|
}
|
|
15198
|
+
/**
|
|
15199
|
+
* @internal
|
|
15200
|
+
*/
|
|
15201
|
+
function kindToSource(kind) {
|
|
15202
|
+
if (kind === 'audioinput') {
|
|
15203
|
+
return Track.Source.Microphone;
|
|
15204
|
+
} else if (kind === 'videoinput') {
|
|
15205
|
+
return Track.Source.Camera;
|
|
15206
|
+
} else {
|
|
15207
|
+
return Track.Source.Unknown;
|
|
15208
|
+
}
|
|
15209
|
+
}
|
|
15198
15210
|
/**
|
|
15199
15211
|
* @internal
|
|
15200
15212
|
*/
|
|
@@ -16364,12 +16376,18 @@ const CryptorEvent = {
|
|
|
16364
16376
|
|
|
16365
16377
|
const defaultId = 'default';
|
|
16366
16378
|
class DeviceManager {
|
|
16379
|
+
constructor() {
|
|
16380
|
+
this._previousDevices = [];
|
|
16381
|
+
}
|
|
16367
16382
|
static getInstance() {
|
|
16368
16383
|
if (this.instance === undefined) {
|
|
16369
16384
|
this.instance = new DeviceManager();
|
|
16370
16385
|
}
|
|
16371
16386
|
return this.instance;
|
|
16372
16387
|
}
|
|
16388
|
+
get previousDevices() {
|
|
16389
|
+
return this._previousDevices;
|
|
16390
|
+
}
|
|
16373
16391
|
getDevices(kind) {
|
|
16374
16392
|
let requestPermissions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
16375
16393
|
var _a;
|
|
@@ -16387,10 +16405,10 @@ class DeviceManager {
|
|
|
16387
16405
|
}
|
|
16388
16406
|
}
|
|
16389
16407
|
let devices = yield navigator.mediaDevices.enumerateDevices();
|
|
16390
|
-
if (requestPermissions &&
|
|
16408
|
+
if (requestPermissions &&
|
|
16391
16409
|
// for safari we need to skip this check, as otherwise it will re-acquire user media and fail on iOS https://bugs.webkit.org/show_bug.cgi?id=179363
|
|
16392
|
-
!
|
|
16393
|
-
const isDummyDeviceOrEmpty = devices.length === 0 || devices.some(device => {
|
|
16410
|
+
!(isSafari() && this.hasDeviceInUse(kind))) {
|
|
16411
|
+
const isDummyDeviceOrEmpty = devices.filter(d => d.kind === kind).length === 0 || devices.some(device => {
|
|
16394
16412
|
const noLabel = device.label === '';
|
|
16395
16413
|
const isRelevant = kind ? device.kind === kind : true;
|
|
16396
16414
|
return noLabel && isRelevant;
|
|
@@ -16398,7 +16416,11 @@ class DeviceManager {
|
|
|
16398
16416
|
if (isDummyDeviceOrEmpty) {
|
|
16399
16417
|
const permissionsToAcquire = {
|
|
16400
16418
|
video: kind !== 'audioinput' && kind !== 'audiooutput',
|
|
16401
|
-
audio: kind !== 'videoinput'
|
|
16419
|
+
audio: kind !== 'videoinput' && {
|
|
16420
|
+
deviceId: {
|
|
16421
|
+
ideal: 'default'
|
|
16422
|
+
}
|
|
16423
|
+
}
|
|
16402
16424
|
};
|
|
16403
16425
|
const stream = yield navigator.mediaDevices.getUserMedia(permissionsToAcquire);
|
|
16404
16426
|
devices = yield navigator.mediaDevices.enumerateDevices();
|
|
@@ -16407,6 +16429,7 @@ class DeviceManager {
|
|
|
16407
16429
|
});
|
|
16408
16430
|
}
|
|
16409
16431
|
}
|
|
16432
|
+
this._previousDevices = devices;
|
|
16410
16433
|
if (kind) {
|
|
16411
16434
|
devices = devices.filter(device => device.kind === kind);
|
|
16412
16435
|
}
|
|
@@ -16421,10 +16444,22 @@ class DeviceManager {
|
|
|
16421
16444
|
// resolve actual device id if it's 'default': Chrome returns it when no
|
|
16422
16445
|
// device has been chosen
|
|
16423
16446
|
const devices = yield this.getDevices(kind);
|
|
16424
|
-
const
|
|
16447
|
+
const defaultDevice = devices.find(d => d.deviceId === defaultId);
|
|
16448
|
+
if (!defaultDevice) {
|
|
16449
|
+
livekitLogger.warn('could not reliably determine default device');
|
|
16450
|
+
return undefined;
|
|
16451
|
+
}
|
|
16452
|
+
const device = devices.find(d => d.deviceId !== defaultId && d.groupId === (groupId !== null && groupId !== void 0 ? groupId : defaultDevice.groupId));
|
|
16453
|
+
if (!device) {
|
|
16454
|
+
livekitLogger.warn('could not reliably determine default device');
|
|
16455
|
+
return undefined;
|
|
16456
|
+
}
|
|
16425
16457
|
return device === null || device === void 0 ? void 0 : device.deviceId;
|
|
16426
16458
|
});
|
|
16427
16459
|
}
|
|
16460
|
+
hasDeviceInUse(kind) {
|
|
16461
|
+
return kind ? DeviceManager.userMediaPromiseMap.has(kind) : DeviceManager.userMediaPromiseMap.size > 0;
|
|
16462
|
+
}
|
|
16428
16463
|
}
|
|
16429
16464
|
DeviceManager.mediaDeviceKinds = ['audioinput', 'audiooutput', 'videoinput'];
|
|
16430
16465
|
DeviceManager.userMediaPromiseMap = new Map();
|
|
@@ -23255,6 +23290,50 @@ class Room extends EventEmitter {
|
|
|
23255
23290
|
this.emit(RoomEvent.AudioPlaybackStatusChanged, false);
|
|
23256
23291
|
};
|
|
23257
23292
|
this.handleDeviceChange = () => __awaiter(this, void 0, void 0, function* () {
|
|
23293
|
+
var _j, _k, _l;
|
|
23294
|
+
const previousDevices = DeviceManager.getInstance().previousDevices;
|
|
23295
|
+
// check for available devices, but don't request permissions in order to avoid prompts for kinds that haven't been used before
|
|
23296
|
+
const availableDevices = yield DeviceManager.getInstance().getDevices(undefined, false);
|
|
23297
|
+
const browser = getBrowser();
|
|
23298
|
+
if ((browser === null || browser === void 0 ? void 0 : browser.name) === 'Chrome' && browser.os !== 'iOS') {
|
|
23299
|
+
for (let availableDevice of availableDevices) {
|
|
23300
|
+
const previousDevice = previousDevices.find(info => info.deviceId === availableDevice.deviceId);
|
|
23301
|
+
if (previousDevice && previousDevice.label !== '' && previousDevice.kind === availableDevice.kind && previousDevice.label !== availableDevice.label) {
|
|
23302
|
+
// label has changed on device the same deviceId, indicating that the default device has changed on the OS level
|
|
23303
|
+
if (this.getActiveDevice(availableDevice.kind) === 'default') {
|
|
23304
|
+
// emit an active device change event only if the selected output device is actually on `default`
|
|
23305
|
+
this.emit(RoomEvent.ActiveDeviceChanged, availableDevice.kind, availableDevice.deviceId);
|
|
23306
|
+
}
|
|
23307
|
+
}
|
|
23308
|
+
}
|
|
23309
|
+
}
|
|
23310
|
+
const kinds = ['audiooutput', 'audioinput', 'videoinput'];
|
|
23311
|
+
for (let kind of kinds) {
|
|
23312
|
+
const targetSource = kindToSource(kind);
|
|
23313
|
+
const targetPublication = this.localParticipant.getTrack(targetSource);
|
|
23314
|
+
if (targetPublication && ((_j = targetPublication.track) === null || _j === void 0 ? void 0 : _j.isUserProvided)) {
|
|
23315
|
+
// if the track is user provided, we don't want to switch devices on behalf of the user
|
|
23316
|
+
continue;
|
|
23317
|
+
}
|
|
23318
|
+
const devicesOfKind = availableDevices.filter(d => d.kind === kind);
|
|
23319
|
+
const activeDevice = this.getActiveDevice(kind);
|
|
23320
|
+
if (activeDevice === ((_k = previousDevices.filter(info => info.kind === kind)[0]) === null || _k === void 0 ? void 0 : _k.deviceId)) {
|
|
23321
|
+
// in Safari the first device is always the default, so we assume a user on the default device would like to switch to the default once it changes
|
|
23322
|
+
// FF doesn't emit an event when the default device changes, so we perform the same best effort and switch to the new device once connected and if it's the first in the array
|
|
23323
|
+
if (devicesOfKind.length > 0 && ((_l = devicesOfKind[0]) === null || _l === void 0 ? void 0 : _l.deviceId) !== activeDevice) {
|
|
23324
|
+
yield this.switchActiveDevice(kind, devicesOfKind[0].deviceId);
|
|
23325
|
+
continue;
|
|
23326
|
+
}
|
|
23327
|
+
}
|
|
23328
|
+
if (kind === 'audioinput' && !isSafari() || kind === 'videoinput') {
|
|
23329
|
+
// airpods on Safari need special handling for audioinput as the track doesn't end as soon as you take them out
|
|
23330
|
+
continue;
|
|
23331
|
+
}
|
|
23332
|
+
// switch to first available device if previously active device is not available any more
|
|
23333
|
+
if (devicesOfKind.length > 0 && !devicesOfKind.find(deviceInfo => deviceInfo.deviceId === this.getActiveDevice(kind))) {
|
|
23334
|
+
yield this.switchActiveDevice(kind, devicesOfKind[0].deviceId);
|
|
23335
|
+
}
|
|
23336
|
+
}
|
|
23258
23337
|
this.emit(RoomEvent.MediaDevicesChanged);
|
|
23259
23338
|
});
|
|
23260
23339
|
this.handleRoomUpdate = room => {
|
|
@@ -23292,7 +23371,7 @@ class Room extends EventEmitter {
|
|
|
23292
23371
|
this.emit(RoomEvent.TrackUnmuted, pub, this.localParticipant);
|
|
23293
23372
|
};
|
|
23294
23373
|
this.onLocalTrackPublished = pub => __awaiter(this, void 0, void 0, function* () {
|
|
23295
|
-
var
|
|
23374
|
+
var _m;
|
|
23296
23375
|
this.emit(RoomEvent.LocalTrackPublished, pub, this.localParticipant);
|
|
23297
23376
|
if (pub.track instanceof LocalAudioTrack) {
|
|
23298
23377
|
const trackIsSilent = yield pub.track.checkForSilence();
|
|
@@ -23300,7 +23379,7 @@ class Room extends EventEmitter {
|
|
|
23300
23379
|
this.emit(RoomEvent.LocalAudioSilenceDetected, pub);
|
|
23301
23380
|
}
|
|
23302
23381
|
}
|
|
23303
|
-
const deviceId = yield (
|
|
23382
|
+
const deviceId = yield (_m = pub.track) === null || _m === void 0 ? void 0 : _m.getDeviceId();
|
|
23304
23383
|
const deviceKind = sourceToKind(pub.source);
|
|
23305
23384
|
if (deviceKind && deviceId && deviceId !== this.localParticipant.activeDeviceMap.get(deviceKind)) {
|
|
23306
23385
|
this.localParticipant.activeDeviceMap.set(deviceKind, deviceId);
|