|
@@ -9,7 +9,6 @@ import ConnectionQuality from './modules/connectionquality/connectionquality';
|
9
|
9
|
|
10
|
10
|
import CQEvents from './service/connectionquality/CQEvents';
|
11
|
11
|
import UIEvents from './service/UI/UIEvents';
|
12
|
|
-import DSEvents from './service/desktopsharing/DesktopSharingEventTypes';
|
13
|
12
|
|
14
|
13
|
const ConnectionEvents = JitsiMeetJS.events.connection;
|
15
|
14
|
const ConnectionErrors = JitsiMeetJS.errors.connection;
|
|
@@ -18,6 +17,7 @@ const ConferenceEvents = JitsiMeetJS.events.conference;
|
18
|
17
|
const ConferenceErrors = JitsiMeetJS.errors.conference;
|
19
|
18
|
|
20
|
19
|
const TrackEvents = JitsiMeetJS.events.track;
|
|
20
|
+const TrackErrors = JitsiMeetJS.errors.track;
|
21
|
21
|
|
22
|
22
|
let room, connection, localTracks, localAudio, localVideo, roomLocker;
|
23
|
23
|
|
|
@@ -108,6 +108,41 @@ function muteLocalVideo (muted) {
|
108
|
108
|
}
|
109
|
109
|
}
|
110
|
110
|
|
|
111
|
+/**
|
|
112
|
+ * Create local tracks of specified types.
|
|
113
|
+ * @param {string[]} devices required track types ('audio', 'video' etc.)
|
|
114
|
+ * @returns {Promise<JitsiLocalTrack[]>}
|
|
115
|
+ */
|
|
116
|
+function createLocalTracks (...devices) {
|
|
117
|
+ return JitsiMeetJS.createLocalTracks({
|
|
118
|
+ // copy array to avoid mutations inside library
|
|
119
|
+ devices: devices.slice(0),
|
|
120
|
+ resolution: config.resolution,
|
|
121
|
+ // adds any ff fake device settings if any
|
|
122
|
+ firefox_fake_device: config.firefox_fake_device
|
|
123
|
+ }).catch(function (err) {
|
|
124
|
+ console.error('failed to create local tracks', ...devices, err);
|
|
125
|
+ return Promise.reject(err);
|
|
126
|
+ });
|
|
127
|
+}
|
|
128
|
+
|
|
129
|
+/**
|
|
130
|
+ * Create local screen sharing track.
|
|
131
|
+ * Shows UI notification if Firefox extension is required.
|
|
132
|
+ * @returns {Promise<JitsiLocalTrack[]>}
|
|
133
|
+ */
|
|
134
|
+function createDesktopTrack () {
|
|
135
|
+ return createLocalTracks('desktop').catch(function (err) {
|
|
136
|
+ if (err === TrackErrors.FIREFOX_EXTENSION_NEEDED) {
|
|
137
|
+ APP.UI.showExtensionRequiredDialog(
|
|
138
|
+ config.desktopSharingFirefoxExtensionURL
|
|
139
|
+ );
|
|
140
|
+ }
|
|
141
|
+
|
|
142
|
+ return Promise.reject(err);
|
|
143
|
+ });
|
|
144
|
+}
|
|
145
|
+
|
111
|
146
|
class ConferenceConnector {
|
112
|
147
|
constructor(resolve, reject) {
|
113
|
148
|
this._resolve = resolve;
|
|
@@ -232,6 +267,8 @@ export default {
|
232
|
267
|
isModerator: false,
|
233
|
268
|
audioMuted: false,
|
234
|
269
|
videoMuted: false,
|
|
270
|
+ isSharingScreen: false,
|
|
271
|
+ isDesktopSharingEnabled: false,
|
235
|
272
|
/**
|
236
|
273
|
* Open new connection and join to the conference.
|
237
|
274
|
* @param {object} options
|
|
@@ -244,10 +281,12 @@ export default {
|
244
|
281
|
|
245
|
282
|
return JitsiMeetJS.init(config).then(() => {
|
246
|
283
|
return Promise.all([
|
247
|
|
- this.createLocalTracks('audio', 'video').catch(()=>{
|
248
|
|
- return this.createLocalTracks('audio');
|
249
|
|
- }).catch(
|
250
|
|
- () => {return [];}),
|
|
284
|
+ // try to retrieve audio and video
|
|
285
|
+ createLocalTracks('audio', 'video')
|
|
286
|
+ // if failed then try to retrieve only audio
|
|
287
|
+ .catch(() => createLocalTracks('audio'))
|
|
288
|
+ // if audio also failed then just return empty array
|
|
289
|
+ .catch(() => []),
|
251
|
290
|
connect()
|
252
|
291
|
]);
|
253
|
292
|
}).then(([tracks, con]) => {
|
|
@@ -255,6 +294,8 @@ export default {
|
255
|
294
|
localTracks = tracks;
|
256
|
295
|
connection = con;
|
257
|
296
|
this._createRoom();
|
|
297
|
+ this.isDesktopSharingEnabled =
|
|
298
|
+ JitsiMeetJS.isDesktopSharingEnabled();
|
258
|
299
|
// XXX The API will take care of disconnecting from the XMPP server
|
259
|
300
|
// (and, thus, leaving the room) on unload.
|
260
|
301
|
return new Promise((resolve, reject) => {
|
|
@@ -262,24 +303,6 @@ export default {
|
262
|
303
|
});
|
263
|
304
|
});
|
264
|
305
|
},
|
265
|
|
- /**
|
266
|
|
- * Create local tracks of specified types.
|
267
|
|
- * If we cannot obtain required tracks it will return empty array.
|
268
|
|
- * @param {string[]} devices required track types ('audio', 'video' etc.)
|
269
|
|
- * @returns {Promise<JitsiLocalTrack[]>}
|
270
|
|
- */
|
271
|
|
- createLocalTracks (...devices) {
|
272
|
|
- return JitsiMeetJS.createLocalTracks({
|
273
|
|
- // copy array to avoid mutations inside library
|
274
|
|
- devices: devices.slice(0),
|
275
|
|
- resolution: config.resolution,
|
276
|
|
- // adds any ff fake device settings if any
|
277
|
|
- firefox_fake_device: config.firefox_fake_device
|
278
|
|
- }).catch(function (err) {
|
279
|
|
- console.error('failed to create local tracks', ...devices, err);
|
280
|
|
- return Promise.reject(err);
|
281
|
|
- });
|
282
|
|
- },
|
283
|
306
|
/**
|
284
|
307
|
* Check if id is id of the local user.
|
285
|
308
|
* @param {string} id id to check
|
|
@@ -456,6 +479,79 @@ export default {
|
456
|
479
|
}
|
457
|
480
|
return options;
|
458
|
481
|
},
|
|
482
|
+
|
|
483
|
+ videoSwitchInProgress: false,
|
|
484
|
+ toggleScreenSharing () {
|
|
485
|
+ if (this.videoSwitchInProgress) {
|
|
486
|
+ console.warn("Switch in progress.");
|
|
487
|
+ return;
|
|
488
|
+ }
|
|
489
|
+ if (!this.isDesktopSharingEnabled) {
|
|
490
|
+ console.warn("Cannot toggle screen sharing: not supported.");
|
|
491
|
+ return;
|
|
492
|
+ }
|
|
493
|
+
|
|
494
|
+ this.videoSwitchInProgress = true;
|
|
495
|
+
|
|
496
|
+ if (this.isSharingScreen) {
|
|
497
|
+ // stop sharing desktop and share video
|
|
498
|
+ createLocalTracks('video').then(function ([stream]) {
|
|
499
|
+ return room.addTrack(stream);
|
|
500
|
+ }).then((stream) => {
|
|
501
|
+ if (localVideo) {
|
|
502
|
+ localVideo.stop();
|
|
503
|
+ }
|
|
504
|
+ localVideo = stream;
|
|
505
|
+ this.videoMuted = stream.isMuted();
|
|
506
|
+ APP.UI.setVideoMuted(this.localId, this.videoMuted);
|
|
507
|
+
|
|
508
|
+ APP.UI.addLocalStream(stream);
|
|
509
|
+ console.log('sharing local video');
|
|
510
|
+ }).catch((err) => {
|
|
511
|
+ localVideo = null;
|
|
512
|
+ console.error('failed to share local video', err);
|
|
513
|
+ }).then(() => {
|
|
514
|
+ this.videoSwitchInProgress = false;
|
|
515
|
+ this.isSharingScreen = false;
|
|
516
|
+ APP.UI.updateDesktopSharingButtons();
|
|
517
|
+ });
|
|
518
|
+ } else {
|
|
519
|
+ // stop sharing video and share desktop
|
|
520
|
+ createDesktopTrack().then(([stream]) => {
|
|
521
|
+ stream.on(
|
|
522
|
+ TrackEvents.TRACK_STOPPED,
|
|
523
|
+ () => {
|
|
524
|
+ // if stream was stopped during screensharing session
|
|
525
|
+ // then we should switch to video
|
|
526
|
+ // otherwise we stopped it because we already switched
|
|
527
|
+ // to video, so nothing to do here
|
|
528
|
+ if (this.isSharingScreen) {
|
|
529
|
+ this.toggleScreenSharing();
|
|
530
|
+ }
|
|
531
|
+ }
|
|
532
|
+ );
|
|
533
|
+ return room.addTrack(stream);
|
|
534
|
+ }).then((stream) => {
|
|
535
|
+ if (localVideo) {
|
|
536
|
+ localVideo.stop();
|
|
537
|
+ }
|
|
538
|
+ localVideo = stream;
|
|
539
|
+
|
|
540
|
+ this.videoMuted = stream.isMuted();
|
|
541
|
+ APP.UI.setVideoMuted(this.localId, this.videoMuted);
|
|
542
|
+
|
|
543
|
+ APP.UI.addLocalStream(stream);
|
|
544
|
+
|
|
545
|
+ this.videoSwitchInProgress = false;
|
|
546
|
+ this.isSharingScreen = true;
|
|
547
|
+ APP.UI.updateDesktopSharingButtons();
|
|
548
|
+ console.log('sharing local desktop');
|
|
549
|
+ }).catch((err) => {
|
|
550
|
+ this.videoSwitchInProgress = false;
|
|
551
|
+ console.error('failed to share local desktop', err);
|
|
552
|
+ });
|
|
553
|
+ }
|
|
554
|
+ },
|
459
|
555
|
/**
|
460
|
556
|
* Setup interaction between conference and UI.
|
461
|
557
|
*/
|
|
@@ -799,45 +895,8 @@ export default {
|
799
|
895
|
room.pinParticipant(id);
|
800
|
896
|
});
|
801
|
897
|
|
802
|
|
- APP.UI.addListener(UIEvents.TOGGLE_SCREENSHARING, () => {
|
803
|
|
- APP.desktopsharing.toggleScreenSharing();
|
804
|
|
- });
|
805
|
|
-
|
806
|
|
- APP.desktopsharing.addListener(DSEvents.SWITCHING_DONE,
|
807
|
|
- (isSharingScreen) => {
|
808
|
|
- APP.UI.updateDesktopSharingButtons(isSharingScreen);
|
809
|
|
- });
|
810
|
|
-
|
811
|
|
- APP.desktopsharing.addListener(DSEvents.FIREFOX_EXTENSION_NEEDED,
|
812
|
|
- (url) => {
|
813
|
|
- APP.UI.showExtensionRequiredDialog(url);
|
814
|
|
- });
|
815
|
|
-
|
816
|
|
- APP.desktopsharing.addListener(DSEvents.NEW_STREAM_CREATED,
|
817
|
|
- (track, callback) => {
|
818
|
|
- const localCallback = (newTrack) => {
|
819
|
|
- if(!newTrack || !localVideo || !newTrack.isLocal() ||
|
820
|
|
- newTrack !== localVideo)
|
821
|
|
- return;
|
822
|
|
- if(localVideo.isMuted() &&
|
823
|
|
- localVideo.videoType !== track.videoType) {
|
824
|
|
- localVideo.mute();
|
825
|
|
- }
|
826
|
|
- callback();
|
827
|
|
- if(room)
|
828
|
|
- room.off(ConferenceEvents.TRACK_ADDED, localCallback);
|
829
|
|
- };
|
830
|
|
- if(room) {
|
831
|
|
- room.on(ConferenceEvents.TRACK_ADDED, localCallback);
|
832
|
|
- }
|
833
|
|
- if(localVideo)
|
834
|
|
- localVideo.stop();
|
835
|
|
- localVideo = track;
|
836
|
|
- room.addTrack(track);
|
837
|
|
- if(!room)
|
838
|
|
- localCallback();
|
839
|
|
- APP.UI.addLocalStream(track);
|
840
|
|
- }
|
|
898
|
+ APP.UI.addListener(
|
|
899
|
+ UIEvents.TOGGLE_SCREENSHARING, this.toggleScreenSharing.bind(this)
|
841
|
900
|
);
|
842
|
901
|
}
|
843
|
902
|
};
|