sample-xmonitor-js 1.0.10 → 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 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
- canvas.width = videoWidth * sharpness;
29
- canvas.height = videoHeight * sharpness;
30
- canvas.getContext('2d').drawImage(this.monitor.element, 0, 0, videoWidth * sharpness, videoHeight * sharpness);
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() {
@@ -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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sample-xmonitor-js",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "description": "",
5
5
  "main": "./lib/index",
6
6
  "files": [