sample-xmonitor-js 1.0.9 → 1.0.12
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/lib/Monitor.d.ts +1 -1
- package/lib/Monitor.js +15 -5
- package/lib/txrtc/index.js +5 -2
- package/package.json +1 -1
package/lib/Monitor.d.ts
CHANGED
|
@@ -90,7 +90,7 @@ export type MonitorOptions = {
|
|
|
90
90
|
export default class Monitor {
|
|
91
91
|
readonly options: MonitorOptions;
|
|
92
92
|
readonly no: string;
|
|
93
|
-
element: HTMLVideoElement;
|
|
93
|
+
element: HTMLVideoElement | HTMLCanvasElement;
|
|
94
94
|
readonly type: MonitorType;
|
|
95
95
|
readonly watcher: Watcher;
|
|
96
96
|
private eventPool;
|
package/lib/Monitor.js
CHANGED
|
@@ -22,12 +22,22 @@ class Watcher {
|
|
|
22
22
|
sharpness = 1;
|
|
23
23
|
if (sharpness < 0)
|
|
24
24
|
sharpness = 0.1;
|
|
25
|
-
let { videoWidth, videoHeight } = this.monitor.element;
|
|
26
25
|
let name = Date.now() + '.jpg';
|
|
27
26
|
let canvas = document.createElement("canvas");
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
if (this.monitor.element instanceof HTMLVideoElement) {
|
|
28
|
+
let { videoWidth, videoHeight } = this.monitor.element;
|
|
29
|
+
canvas.width = videoWidth * sharpness;
|
|
30
|
+
canvas.height = videoHeight * sharpness;
|
|
31
|
+
// @ts-ignore
|
|
32
|
+
canvas.getContext('2d').drawImage(this.monitor.element, 0, 0, canvas.width, canvas.height);
|
|
33
|
+
}
|
|
34
|
+
else if (this.monitor.element instanceof HTMLCanvasElement) {
|
|
35
|
+
let sourceCanvas = this.monitor.element;
|
|
36
|
+
canvas.width = sourceCanvas.width * sharpness;
|
|
37
|
+
canvas.height = sourceCanvas.height * sharpness;
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
canvas.getContext('2d').drawImage(sourceCanvas, 0, 0, canvas.width, canvas.height);
|
|
40
|
+
}
|
|
31
41
|
let img = { name };
|
|
32
42
|
Object.defineProperty(img, "blob", {
|
|
33
43
|
get() {
|
|
@@ -100,7 +110,7 @@ export default class Monitor {
|
|
|
100
110
|
this.watcher = new Watcher(this);
|
|
101
111
|
}
|
|
102
112
|
isPaused() {
|
|
103
|
-
return this.element.paused;
|
|
113
|
+
return this.element instanceof HTMLVideoElement && this.element.paused;
|
|
104
114
|
}
|
|
105
115
|
shot() {
|
|
106
116
|
return this.watcher.shot(this.options.setup?.sharpness).then(img => {
|
package/lib/txrtc/index.js
CHANGED
|
@@ -42,9 +42,9 @@ export default class TxrtcMonitor extends Monitor {
|
|
|
42
42
|
}).on(TRTC.EVENT.SCREEN_SHARE_STOPPED, () => {
|
|
43
43
|
this.dispatchEvent('cancel');
|
|
44
44
|
this.stop();
|
|
45
|
-
}).on(TRTC.EVENT.TRACK, () => {
|
|
45
|
+
}).on(TRTC.EVENT.TRACK, (data) => {
|
|
46
46
|
this.active = true;
|
|
47
|
-
this.dispatchEvent('start');
|
|
47
|
+
this.dispatchEvent('start', data);
|
|
48
48
|
}).on(TRTC.EVENT.VIDEO_PLAY_STATE_CHANGED, ({ state }) => {
|
|
49
49
|
if (state === 'STOPPED') {
|
|
50
50
|
this.dispatchEvent('stop');
|
|
@@ -53,6 +53,9 @@ export default class TxrtcMonitor extends Monitor {
|
|
|
53
53
|
this.dispatchEvent('playing');
|
|
54
54
|
}
|
|
55
55
|
this.element = this.options.element.querySelector('video');
|
|
56
|
+
if (!this.element) {
|
|
57
|
+
this.element = this.options.element.querySelector('canvas');
|
|
58
|
+
}
|
|
56
59
|
}).on(TRTC.EVENT.CUSTOM_MESSAGE, (message) => {
|
|
57
60
|
let decoder = new TextDecoder('utf-8');
|
|
58
61
|
let payload = decoder.decode(message.data);
|