|
@@ -170,16 +170,25 @@ function hangup (requestFeedback = false) {
|
170
|
170
|
|
171
|
171
|
/**
|
172
|
172
|
* Create local tracks of specified types.
|
173
|
|
- * @param {string[]} devices required track types ('audio', 'video' etc.)
|
|
173
|
+ * @param {string[]} devices - required track types ('audio', 'video' etc.)
|
|
174
|
+ * @param {string|null} [cameraDeviceId] - camera device id, if undefined - one
|
|
175
|
+ * from settings will be used
|
|
176
|
+ * @param {string|null} [micDeviceId] - microphone device id, if undefined - one
|
|
177
|
+ * from settings will be used
|
174
|
178
|
* @returns {Promise<JitsiLocalTrack[]>}
|
175
|
179
|
*/
|
176
|
|
-function createLocalTracks (...devices) {
|
|
180
|
+function createLocalTracks (devices, cameraDeviceId, micDeviceId) {
|
177
|
181
|
return JitsiMeetJS.createLocalTracks({
|
178
|
182
|
// copy array to avoid mutations inside library
|
179
|
183
|
devices: devices.slice(0),
|
180
|
184
|
resolution: config.resolution,
|
181
|
|
- cameraDeviceId: APP.settings.getCameraDeviceId(),
|
182
|
|
- micDeviceId: APP.settings.getMicDeviceId(),
|
|
185
|
+ cameraDeviceId: typeof cameraDeviceId === 'undefined'
|
|
186
|
+ || cameraDeviceId === null
|
|
187
|
+ ? APP.settings.getCameraDeviceId()
|
|
188
|
+ : cameraDeviceId,
|
|
189
|
+ micDeviceId: typeof micDeviceId === 'undefined' || micDeviceId === null
|
|
190
|
+ ? APP.settings.getMicDeviceId()
|
|
191
|
+ : micDeviceId,
|
183
|
192
|
// adds any ff fake device settings if any
|
184
|
193
|
firefox_fake_device: config.firefox_fake_device
|
185
|
194
|
}).catch(function (err) {
|
|
@@ -327,6 +336,7 @@ export default {
|
327
|
336
|
* @returns {Promise}
|
328
|
337
|
*/
|
329
|
338
|
init(options) {
|
|
339
|
+ let self = this;
|
330
|
340
|
this.roomName = options.roomName;
|
331
|
341
|
JitsiMeetJS.setLogLevel(JitsiMeetJS.logLevels.TRACE);
|
332
|
342
|
|
|
@@ -356,9 +366,9 @@ export default {
|
356
|
366
|
return JitsiMeetJS.init(config).then(() => {
|
357
|
367
|
return Promise.all([
|
358
|
368
|
// try to retrieve audio and video
|
359
|
|
- createLocalTracks('audio', 'video')
|
|
369
|
+ createLocalTracks(['audio', 'video'])
|
360
|
370
|
// if failed then try to retrieve only audio
|
361
|
|
- .catch(() => createLocalTracks('audio'))
|
|
371
|
+ .catch(() => createLocalTracks(['audio']))
|
362
|
372
|
// if audio also failed then just return empty array
|
363
|
373
|
.catch(() => []),
|
364
|
374
|
connect(options.roomName)
|
|
@@ -370,15 +380,49 @@ export default {
|
370
|
380
|
this.isDesktopSharingEnabled =
|
371
|
381
|
JitsiMeetJS.isDesktopSharingEnabled();
|
372
|
382
|
|
|
383
|
+ // if user didn't give access to mic or camera or doesn't have
|
|
384
|
+ // them at all, we disable corresponding toolbar buttons
|
|
385
|
+ if (!tracks.find((t) => t.isAudioTrack())) {
|
|
386
|
+ APP.UI.disableMicrophoneButton();
|
|
387
|
+ }
|
|
388
|
+
|
|
389
|
+ if (!tracks.find((t) => t.isVideoTrack())) {
|
|
390
|
+ APP.UI.disableCameraButton();
|
|
391
|
+ }
|
|
392
|
+
|
373
|
393
|
// update list of available devices
|
374
|
394
|
if (JitsiMeetJS.mediaDevices.isDeviceListAvailable() &&
|
375
|
395
|
JitsiMeetJS.mediaDevices.isDeviceChangeAvailable()) {
|
376
|
|
- JitsiMeetJS.mediaDevices.enumerateDevices(
|
377
|
|
- APP.UI.onAvailableDevicesChanged);
|
|
396
|
+ JitsiMeetJS.mediaDevices.enumerateDevices(function(devices) {
|
|
397
|
+ // Ugly way to synchronize real device IDs with local
|
|
398
|
+ // storage and settings menu. This is a workaround until
|
|
399
|
+ // getConstraints() method will be implemented in browsers.
|
|
400
|
+ if (localAudio) {
|
|
401
|
+ localAudio._setRealDeviceIdFromDeviceList(devices);
|
|
402
|
+ APP.settings.setMicDeviceId(localAudio.getDeviceId());
|
|
403
|
+ }
|
|
404
|
+
|
|
405
|
+ if (localVideo) {
|
|
406
|
+ localVideo._setRealDeviceIdFromDeviceList(devices);
|
|
407
|
+ APP.settings.setCameraDeviceId(
|
|
408
|
+ localVideo.getDeviceId());
|
|
409
|
+ }
|
|
410
|
+
|
|
411
|
+ APP.UI.onAvailableDevicesChanged(devices);
|
|
412
|
+ });
|
378
|
413
|
|
379
|
414
|
JitsiMeetJS.mediaDevices.addEventListener(
|
380
|
415
|
JitsiMeetJS.events.mediaDevices.DEVICE_LIST_CHANGED,
|
381
|
|
- APP.UI.onAvailableDevicesChanged);
|
|
416
|
+ (devices) => {
|
|
417
|
+ // Just defer callback until other event callbacks are
|
|
418
|
+ // processed.
|
|
419
|
+ window.setTimeout(() => {
|
|
420
|
+ checkLocalDevicesAfterDeviceListChanged(devices)
|
|
421
|
+ .then(() => {
|
|
422
|
+ APP.UI.onAvailableDevicesChanged(devices);
|
|
423
|
+ });
|
|
424
|
+ }, 0);
|
|
425
|
+ });
|
382
|
426
|
}
|
383
|
427
|
if (config.iAmRecorder)
|
384
|
428
|
this.recorder = new Recorder();
|
|
@@ -388,6 +432,164 @@ export default {
|
388
|
432
|
return new Promise((resolve, reject) => {
|
389
|
433
|
(new ConferenceConnector(resolve, reject)).connect();
|
390
|
434
|
});
|
|
435
|
+
|
|
436
|
+ function checkAudioOutputDeviceAfterDeviceListChanged(newDevices) {
|
|
437
|
+ if (!JitsiMeetJS.mediaDevices
|
|
438
|
+ .isDeviceChangeAvailable('output')) {
|
|
439
|
+ return;
|
|
440
|
+ }
|
|
441
|
+
|
|
442
|
+ var selectedAudioOutputDeviceId =
|
|
443
|
+ APP.settings.getAudioOutputDeviceId(),
|
|
444
|
+ availableAudioOutputDevices = newDevices.filter(d => {
|
|
445
|
+ return d.kind === 'audiooutput';
|
|
446
|
+ });
|
|
447
|
+
|
|
448
|
+ if (selectedAudioOutputDeviceId !== 'default' &&
|
|
449
|
+ !availableAudioOutputDevices.find(d =>
|
|
450
|
+ d.deviceId === selectedAudioOutputDeviceId)) {
|
|
451
|
+ APP.settings.setAudioOutputDeviceId('default');
|
|
452
|
+ }
|
|
453
|
+ }
|
|
454
|
+
|
|
455
|
+ function checkLocalDevicesAfterDeviceListChanged(newDevices) {
|
|
456
|
+ checkAudioOutputDeviceAfterDeviceListChanged(newDevices);
|
|
457
|
+
|
|
458
|
+ let availableAudioInputDevices = newDevices.filter(
|
|
459
|
+ d => d.kind === 'audioinput'),
|
|
460
|
+ availableVideoInputDevices = newDevices.filter(
|
|
461
|
+ d => d.kind === 'videoinput'),
|
|
462
|
+ selectedAudioInputDeviceId = APP.settings.getMicDeviceId(),
|
|
463
|
+ selectedVideoInputDeviceId =
|
|
464
|
+ APP.settings.getCameraDeviceId(),
|
|
465
|
+ selectedAudioInputDevice = availableAudioInputDevices.find(
|
|
466
|
+ d => d.deviceId === selectedAudioInputDeviceId),
|
|
467
|
+ selectedVideoInputDevice = availableVideoInputDevices.find(
|
|
468
|
+ d => d.deviceId === selectedVideoInputDeviceId),
|
|
469
|
+ tracksToCreate = [],
|
|
470
|
+ micIdToUse = null,
|
|
471
|
+ cameraIdToUse = null;
|
|
472
|
+
|
|
473
|
+ // Here we handle case when no device was initially plugged, but
|
|
474
|
+ // then it's connected OR new device was connected when previous
|
|
475
|
+ // track has ended.
|
|
476
|
+ if (!localAudio || localAudio.disposed || localAudio.isEnded()){
|
|
477
|
+ if (availableAudioInputDevices.length
|
|
478
|
+ && availableAudioInputDevices[0].label !== '') {
|
|
479
|
+ tracksToCreate.push('audio');
|
|
480
|
+ micIdToUse = availableAudioInputDevices[0].deviceId;
|
|
481
|
+ } else {
|
|
482
|
+ APP.UI.disableMicrophoneButton();
|
|
483
|
+ }
|
|
484
|
+ }
|
|
485
|
+
|
|
486
|
+ if ((!localVideo || localVideo.disposed || localVideo.isEnded())
|
|
487
|
+ && !self.isSharingScreen){
|
|
488
|
+ if (availableVideoInputDevices.length
|
|
489
|
+ && availableVideoInputDevices[0].label !== '') {
|
|
490
|
+ tracksToCreate.push('video');
|
|
491
|
+ cameraIdToUse = availableVideoInputDevices[0].deviceId;
|
|
492
|
+ } else {
|
|
493
|
+ APP.UI.disableCameraButton();
|
|
494
|
+ }
|
|
495
|
+ }
|
|
496
|
+
|
|
497
|
+ if (localAudio && !localAudio.disposed && !localAudio.isEnded()
|
|
498
|
+ && selectedAudioInputDevice
|
|
499
|
+ && selectedAudioInputDeviceId !== localAudio.getDeviceId()
|
|
500
|
+ && tracksToCreate.indexOf('audio') === -1) {
|
|
501
|
+ tracksToCreate.push('audio');
|
|
502
|
+ micIdToUse = selectedAudioInputDeviceId;
|
|
503
|
+ }
|
|
504
|
+
|
|
505
|
+ if (localVideo && !localVideo.disposed && !localVideo.isEnded()
|
|
506
|
+ && selectedVideoInputDevice
|
|
507
|
+ && selectedVideoInputDeviceId !== localVideo.getDeviceId()
|
|
508
|
+ && tracksToCreate.indexOf('video') === -1
|
|
509
|
+ && !self.isSharingScreen) {
|
|
510
|
+ tracksToCreate.push('video');
|
|
511
|
+ cameraIdToUse = selectedVideoInputDeviceId;
|
|
512
|
+ }
|
|
513
|
+
|
|
514
|
+ if (tracksToCreate.length) {
|
|
515
|
+ return createNewTracks(
|
|
516
|
+ tracksToCreate, cameraIdToUse, micIdToUse);
|
|
517
|
+ } else {
|
|
518
|
+ return Promise.resolve();
|
|
519
|
+ }
|
|
520
|
+
|
|
521
|
+ function createNewTracks(type, cameraDeviceId, micDeviceId) {
|
|
522
|
+ return createLocalTracks(type, cameraDeviceId, micDeviceId)
|
|
523
|
+ .then(onTracksCreated)
|
|
524
|
+ .catch(() => {
|
|
525
|
+ // if we tried to create both audio and video tracks
|
|
526
|
+ // at once and failed, let's try again only with
|
|
527
|
+ // audio. Such situation may happen in case if we
|
|
528
|
+ // granted access only to microphone, but not to
|
|
529
|
+ // camera.
|
|
530
|
+ if (type.indexOf('audio') !== -1
|
|
531
|
+ && type.indexOf('video') !== -1) {
|
|
532
|
+ return createLocalTracks(['audio'], null,
|
|
533
|
+ micDeviceId);
|
|
534
|
+ }
|
|
535
|
+
|
|
536
|
+ })
|
|
537
|
+ .then(onTracksCreated)
|
|
538
|
+ .catch(() => {
|
|
539
|
+ // if we tried to create both audio and video tracks
|
|
540
|
+ // at once and failed, let's try again only with
|
|
541
|
+ // video. Such situation may happen in case if we
|
|
542
|
+ // granted access only to camera, but not to
|
|
543
|
+ // microphone.
|
|
544
|
+ if (type.indexOf('audio') !== -1
|
|
545
|
+ && type.indexOf('video') !== -1) {
|
|
546
|
+ return createLocalTracks(['video'],
|
|
547
|
+ cameraDeviceId,
|
|
548
|
+ null);
|
|
549
|
+ }
|
|
550
|
+ })
|
|
551
|
+ .then(onTracksCreated)
|
|
552
|
+ .catch(() => {
|
|
553
|
+ // can't do anything in this case, so just ignore;
|
|
554
|
+ });
|
|
555
|
+ }
|
|
556
|
+
|
|
557
|
+ function onTracksCreated(tracks) {
|
|
558
|
+ tracks && tracks.forEach(track => {
|
|
559
|
+ if (track.isAudioTrack()) {
|
|
560
|
+ self.useAudioStream(track).then(() => {
|
|
561
|
+ console.log('switched local audio');
|
|
562
|
+
|
|
563
|
+ // If we have more than 1 device - mute.
|
|
564
|
+ // We check with 2 for audio, because
|
|
565
|
+ // it always has 'default' if device is
|
|
566
|
+ // available at all.
|
|
567
|
+ // TODO: this is not 100% solution - need
|
|
568
|
+ // to investigate more
|
|
569
|
+ if (availableAudioInputDevices.length > 2) {
|
|
570
|
+ muteLocalAudio(true);
|
|
571
|
+ }
|
|
572
|
+ });
|
|
573
|
+ } else if (track.isVideoTrack()) {
|
|
574
|
+ self.useVideoStream(track).then(() => {
|
|
575
|
+ console.log('switched local video');
|
|
576
|
+
|
|
577
|
+ // TODO: maybe make video large if we
|
|
578
|
+ // are not in conference yet
|
|
579
|
+ // If we have more than 1 device - mute.
|
|
580
|
+ // TODO: this is not 100% solution - need
|
|
581
|
+ // to investigate more
|
|
582
|
+ if (availableVideoInputDevices.length > 1) {
|
|
583
|
+ muteLocalVideo(true);
|
|
584
|
+ }
|
|
585
|
+ });
|
|
586
|
+ } else {
|
|
587
|
+ console.error("Ignored not an audio nor a "
|
|
588
|
+ + "video track: ", track);
|
|
589
|
+ }
|
|
590
|
+ });
|
|
591
|
+ }
|
|
592
|
+ }
|
391
|
593
|
});
|
392
|
594
|
},
|
393
|
595
|
/**
|
|
@@ -667,6 +869,8 @@ export default {
|
667
|
869
|
this.isSharingScreen = false;
|
668
|
870
|
}
|
669
|
871
|
|
|
872
|
+ stream.videoType === 'camera' && APP.UI.enableCameraButton();
|
|
873
|
+
|
670
|
874
|
APP.UI.setVideoMuted(this.localId, this.videoMuted);
|
671
|
875
|
|
672
|
876
|
APP.UI.updateDesktopSharingButtons();
|
|
@@ -701,6 +905,7 @@ export default {
|
701
|
905
|
this.audioMuted = false;
|
702
|
906
|
}
|
703
|
907
|
|
|
908
|
+ APP.UI.enableMicrophoneButton();
|
704
|
909
|
APP.UI.setAudioMuted(this.localId, this.audioMuted);
|
705
|
910
|
});
|
706
|
911
|
},
|
|
@@ -719,7 +924,7 @@ export default {
|
719
|
924
|
this.videoSwitchInProgress = true;
|
720
|
925
|
|
721
|
926
|
if (shareScreen) {
|
722
|
|
- createLocalTracks('desktop').then(([stream]) => {
|
|
927
|
+ createLocalTracks(['desktop']).then(([stream]) => {
|
723
|
928
|
stream.on(
|
724
|
929
|
TrackEvents.LOCAL_TRACK_STOPPED,
|
725
|
930
|
() => {
|
|
@@ -767,7 +972,7 @@ export default {
|
767
|
972
|
);
|
768
|
973
|
});
|
769
|
974
|
} else {
|
770
|
|
- createLocalTracks('video').then(
|
|
975
|
+ createLocalTracks(['video']).then(
|
771
|
976
|
([stream]) => this.useVideoStream(stream)
|
772
|
977
|
).then(() => {
|
773
|
978
|
this.videoSwitchInProgress = false;
|
|
@@ -1118,7 +1323,7 @@ export default {
|
1118
|
1323
|
UIEvents.VIDEO_DEVICE_CHANGED,
|
1119
|
1324
|
(cameraDeviceId) => {
|
1120
|
1325
|
APP.settings.setCameraDeviceId(cameraDeviceId);
|
1121
|
|
- createLocalTracks('video').then(([stream]) => {
|
|
1326
|
+ createLocalTracks(['video']).then(([stream]) => {
|
1122
|
1327
|
this.useVideoStream(stream);
|
1123
|
1328
|
console.log('switched local video device');
|
1124
|
1329
|
});
|
|
@@ -1129,7 +1334,7 @@ export default {
|
1129
|
1334
|
UIEvents.AUDIO_DEVICE_CHANGED,
|
1130
|
1335
|
(micDeviceId) => {
|
1131
|
1336
|
APP.settings.setMicDeviceId(micDeviceId);
|
1132
|
|
- createLocalTracks('audio').then(([stream]) => {
|
|
1337
|
+ createLocalTracks(['audio']).then(([stream]) => {
|
1133
|
1338
|
this.useAudioStream(stream);
|
1134
|
1339
|
console.log('switched local audio device');
|
1135
|
1340
|
});
|