sample-xmonitor-js 2.0.0 → 2.0.2-beta.0

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
@@ -66,7 +66,7 @@ export declare class MonitorType {
66
66
  * changed 状态改变
67
67
  * statistics 通话质量统计
68
68
  */
69
- export type MonitorEvent = 'cancel' | 'start' | 'playing' | 'pause' | 'shot' | 'stop' | 'error' | 'changed' | 'message' | 'statistics';
69
+ export type MonitorEvent = 'cancel' | 'start' | 'playing' | 'pause' | 'shot' | 'stop' | 'error' | 'changed' | 'message' | 'statistics' | 'publish-state-changed';
70
70
  export declare const MonitorEvents: Array<MonitorEvent>;
71
71
  export type MonitorEventObject = {
72
72
  event: MonitorEvent;
package/lib/Monitor.js CHANGED
@@ -119,7 +119,7 @@ export class MonitorType {
119
119
  return new MonitorType(type, device);
120
120
  }
121
121
  }
122
- export const MonitorEvents = ['cancel', 'start', 'playing', 'pause', 'shot', 'stop', 'error', 'changed', 'message', 'statistics'];
122
+ export const MonitorEvents = ['cancel', 'start', 'playing', 'pause', 'shot', 'stop', 'error', 'changed', 'message', 'statistics', 'publish-state-changed'];
123
123
  export class MObject {
124
124
  constructor(room, id) {
125
125
  this.room = room;
@@ -114,6 +114,9 @@ export default class TxrtcMonitor extends Monitor {
114
114
  this.dispatchEvent('error', event, event.error);
115
115
  this.stop();
116
116
  }
117
+ else {
118
+ this.dispatchEvent('publish-state-changed', event);
119
+ }
117
120
  }).on(TRTC.EVENT.CONNECTION_STATE_CHANGED, event => {
118
121
  if (event.state === 'CONNECTING' && event.prevState === 'DISCONNECTED' && event.isReconnecting) {
119
122
  // 尝试重连 10次之后抛出异常
@@ -166,10 +169,12 @@ export class TxrtcScreenMonitor extends TxrtcMonitor {
166
169
  async start() {
167
170
  try {
168
171
  await super.start();
172
+ const viewElement = this.options.element.querySelector('video')
173
+ || this.options.element.querySelector('canvas') || this.options.element;
169
174
  await this.trtc.startScreenShare({
170
175
  option: { profile: '720p', ...this.setup.option },
171
176
  publish: true,
172
- view: this.options.element
177
+ view: viewElement
173
178
  });
174
179
  }
175
180
  catch (e) {
@@ -195,10 +200,12 @@ export class TxrtcCameraMonitor extends TxrtcMonitor {
195
200
  try {
196
201
  await super.start();
197
202
  await this.trtc.startLocalAudio({ publish: true });
203
+ const viewElement = this.options.element.querySelector('video')
204
+ || this.options.element.querySelector('canvas') || this.options.element;
198
205
  await this.trtc.startLocalVideo({
199
206
  option: { profile: '480p', ...this.setup.option },
200
207
  publish: true,
201
- view: this.options.element
208
+ view: viewElement
202
209
  });
203
210
  // 检测人脸 需要在调用本地摄像头之后启动该插件
204
211
  if (this.setup.faceDetection) {
@@ -220,10 +227,12 @@ export class TxrtcCameraMonitor extends TxrtcMonitor {
220
227
  async switch(option) {
221
228
  option.cameraId = option.cameraId || option.deviceId;
222
229
  if (option.cameraId || option.useFrontCamera) {
230
+ const viewElement = this.options.element.querySelector('video')
231
+ || this.options.element.querySelector('canvas') || this.options.element;
223
232
  await this.trtc.updateLocalVideo({
224
233
  option: { profile: '480p', ...this.setup.option, ...option },
225
234
  publish: true,
226
- view: this.options.element
235
+ view: viewElement
227
236
  });
228
237
  }
229
238
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sample-xmonitor-js",
3
- "version": "2.0.0",
3
+ "version": "2.0.2-beta.0",
4
4
  "description": "",
5
5
  "main": "./lib/index",
6
6
  "files": [