|
@@ -1,4 +1,6 @@
|
1
|
1
|
// @flow
|
|
2
|
+import { JitsiTrackEvents } from '../../base/lib-jitsi-meet';
|
|
3
|
+
|
2
|
4
|
import {
|
3
|
5
|
CLEAR_TIMEOUT,
|
4
|
6
|
TIMEOUT_TICK,
|
|
@@ -14,6 +16,7 @@ import {
|
14
|
16
|
export default class JitsiStreamBackgroundEffect {
|
15
|
17
|
_model: Object;
|
16
|
18
|
_options: Object;
|
|
19
|
+ _stream: Object;
|
17
|
20
|
_segmentationPixelCount: number;
|
18
|
21
|
_inputVideoElement: HTMLVideoElement;
|
19
|
22
|
_onMaskFrameTimer: Function;
|
|
@@ -25,6 +28,7 @@ export default class JitsiStreamBackgroundEffect {
|
25
|
28
|
_segmentationMaskCanvas: Object;
|
26
|
29
|
_renderMask: Function;
|
27
|
30
|
_virtualImage: HTMLImageElement;
|
|
31
|
+ _virtualVideo: HTMLVideoElement;
|
28
|
32
|
isEnabled: Function;
|
29
|
33
|
startEffect: Function;
|
30
|
34
|
stopEffect: Function;
|
|
@@ -35,15 +39,22 @@ export default class JitsiStreamBackgroundEffect {
|
35
|
39
|
* @class
|
36
|
40
|
* @param {Object} model - Meet model.
|
37
|
41
|
* @param {Object} options - Segmentation dimensions.
|
|
42
|
+ * @param {Object} screenSharing - Desktop track for displaying desktop share as virtual background.
|
38
|
43
|
*/
|
39
|
|
- constructor(model: Object, options: Object) {
|
|
44
|
+ constructor(model: Object, options: Object, screenSharing: Object) {
|
40
|
45
|
this._options = options;
|
|
46
|
+ this._stream = screenSharing;
|
41
|
47
|
|
42
|
48
|
if (this._options.virtualBackground.backgroundType === 'image') {
|
43
|
49
|
this._virtualImage = document.createElement('img');
|
44
|
50
|
this._virtualImage.crossOrigin = 'anonymous';
|
45
|
51
|
this._virtualImage.src = this._options.virtualBackground.virtualSource;
|
46
|
52
|
}
|
|
53
|
+ if (this._options.virtualBackground.backgroundType === 'desktop-share' && this._stream) {
|
|
54
|
+ this._virtualVideo = document.createElement('video');
|
|
55
|
+ this._virtualVideo.autoplay = true;
|
|
56
|
+ this._virtualVideo.srcObject = this._stream.stream;
|
|
57
|
+ }
|
47
|
58
|
this._model = model;
|
48
|
59
|
this._options = options;
|
49
|
60
|
this._segmentationPixelCount = this._options.width * this._options.height;
|
|
@@ -119,6 +130,13 @@ export default class JitsiStreamBackgroundEffect {
|
119
|
130
|
this._inputVideoElement.width,
|
120
|
131
|
this._inputVideoElement.height
|
121
|
132
|
);
|
|
133
|
+ }
|
|
134
|
+ if (this._options.virtualBackground.backgroundType === 'desktop-share') {
|
|
135
|
+ this._outputCanvasCtx.drawImage(
|
|
136
|
+ this._virtualVideo,
|
|
137
|
+ 0,
|
|
138
|
+ 0
|
|
139
|
+ );
|
122
|
140
|
} else {
|
123
|
141
|
this._outputCanvasCtx.filter = `blur(${this._options.virtualBackground.blurValue}px)`;
|
124
|
142
|
this._outputCanvasCtx.drawImage(this._inputVideoElement, 0, 0);
|
|
@@ -234,6 +252,15 @@ export default class JitsiStreamBackgroundEffect {
|
234
|
252
|
this._inputVideoElement.height = parseInt(height, 10);
|
235
|
253
|
this._inputVideoElement.autoplay = true;
|
236
|
254
|
this._inputVideoElement.srcObject = stream;
|
|
255
|
+ this._stream && this._stream.on(
|
|
256
|
+ JitsiTrackEvents.LOCAL_TRACK_STOPPED,
|
|
257
|
+ () => {
|
|
258
|
+ this._options.virtualBackground.enabled = false;
|
|
259
|
+ this._options.virtualBackground.backgroundType = 'none';
|
|
260
|
+ this._options.virtualBackground.selectedThumbnail = 'none';
|
|
261
|
+ this._options.virtualBackground.backgroundEffectEnabled = false;
|
|
262
|
+ this._options.virtualBackground.enabled = false;
|
|
263
|
+ });
|
237
|
264
|
this._inputVideoElement.onloadeddata = () => {
|
238
|
265
|
this._maskFrameTimerWorker.postMessage({
|
239
|
266
|
id: SET_TIMEOUT,
|