sample-xmonitor-js 1.0.2 → 1.0.3
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/index.d.ts +15 -0
- package/lib/index.js +30 -0
- package/lib/txrtc/index.d.ts +0 -1
- package/lib/txrtc/index.js +27 -35
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -22,6 +22,11 @@ export default class MonitorFactory {
|
|
|
22
22
|
* @param {any} setup 监视器相关的参数
|
|
23
23
|
*/
|
|
24
24
|
init(type: MonitorType, element: HTMLDivElement, setup?: Setup): Promise<Monitor>;
|
|
25
|
+
switch(option: {
|
|
26
|
+
deviceId?: string;
|
|
27
|
+
useFrontCamera?: boolean;
|
|
28
|
+
[key: string]: any;
|
|
29
|
+
}): Promise<void>;
|
|
25
30
|
/**
|
|
26
31
|
* 启动所有监视器
|
|
27
32
|
*/
|
|
@@ -44,3 +49,13 @@ export declare function getInstance(options?: {
|
|
|
44
49
|
setup?: DefaultSetup | TxrtcSetup;
|
|
45
50
|
}>;
|
|
46
51
|
}): MonitorFactory;
|
|
52
|
+
export declare function switchCamera(option: {
|
|
53
|
+
deviceId?: string;
|
|
54
|
+
useFrontCamera?: boolean;
|
|
55
|
+
[key: string]: any;
|
|
56
|
+
}): void;
|
|
57
|
+
export declare function getSpeakerList(requestPermission?: boolean): Promise<MediaDeviceInfo[]>;
|
|
58
|
+
export declare function setCurrentSpeaker(speakerId: string): Promise<void>;
|
|
59
|
+
export declare function getMicrophoneList(requestPermission?: boolean): Promise<MediaDeviceInfo[]>;
|
|
60
|
+
export declare function getCameraList(requestPermission?: boolean): Promise<MediaDeviceInfo[]>;
|
|
61
|
+
export declare function isSupported(): Promise<any>;
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { MObject, MonitorEvents, MonitorType, NotSupportError } from "./Monitor";
|
|
2
2
|
import DefaultMonitor from "./default";
|
|
3
3
|
import TxrtcMonitor from "./txrtc";
|
|
4
|
+
import TRTC from "trtc-sdk-v5";
|
|
4
5
|
export default class MonitorFactory {
|
|
5
6
|
constructor(pointer) {
|
|
6
7
|
this.monitorMap = new Map();
|
|
@@ -47,6 +48,14 @@ export default class MonitorFactory {
|
|
|
47
48
|
this.monitorMap.set(type.toString(), monitor);
|
|
48
49
|
return monitor;
|
|
49
50
|
}
|
|
51
|
+
async switch(option) {
|
|
52
|
+
for (let [, monitor] of this.monitorMap) {
|
|
53
|
+
if (monitor.type.device !== 'screen') {
|
|
54
|
+
await monitor.switch(option);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
50
59
|
/**
|
|
51
60
|
* 启动所有监视器
|
|
52
61
|
*/
|
|
@@ -113,3 +122,24 @@ export function getInstance(options) {
|
|
|
113
122
|
}
|
|
114
123
|
return factory;
|
|
115
124
|
}
|
|
125
|
+
export function switchCamera(option) {
|
|
126
|
+
if (!factory) {
|
|
127
|
+
throw new Error('实例尚未创建,请先执行初始化');
|
|
128
|
+
}
|
|
129
|
+
factory.switch(option);
|
|
130
|
+
}
|
|
131
|
+
export function getSpeakerList(requestPermission) {
|
|
132
|
+
return TRTC.getSpeakerList(requestPermission);
|
|
133
|
+
}
|
|
134
|
+
export function setCurrentSpeaker(speakerId) {
|
|
135
|
+
return TRTC.setCurrentSpeaker(speakerId);
|
|
136
|
+
}
|
|
137
|
+
export function getMicrophoneList(requestPermission) {
|
|
138
|
+
return TRTC.getMicrophoneList(requestPermission);
|
|
139
|
+
}
|
|
140
|
+
export function getCameraList(requestPermission) {
|
|
141
|
+
return TRTC.getCameraList(requestPermission);
|
|
142
|
+
}
|
|
143
|
+
export function isSupported() {
|
|
144
|
+
return TRTC.isSupported();
|
|
145
|
+
}
|
package/lib/txrtc/index.d.ts
CHANGED
package/lib/txrtc/index.js
CHANGED
|
@@ -32,39 +32,33 @@ export default class TxrtcMonitor extends Monitor {
|
|
|
32
32
|
if (this.setup.userDefineRecordId) {
|
|
33
33
|
params.userDefineRecordId = this.setup.userDefineRecordId;
|
|
34
34
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
this.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
this.dispatchEvent('playing');
|
|
61
|
-
}
|
|
62
|
-
}).on(TRTC.EVENT.CUSTOM_MESSAGE, (message) => {
|
|
63
|
-
let decoder = new TextDecoder('utf-8');
|
|
64
|
-
let payload = decoder.decode(message.data);
|
|
65
|
-
this.dispatchEvent('message', payload);
|
|
66
|
-
});
|
|
35
|
+
this.trtc.on(TRTC.EVENT.ERROR, (error) => {
|
|
36
|
+
let err = error;
|
|
37
|
+
if (this.options.type.device === 'screen') {
|
|
38
|
+
err = new ScreenTypeError(error.message, 'ScreenTypeError');
|
|
39
|
+
}
|
|
40
|
+
this.dispatchEvent('error', null, err);
|
|
41
|
+
this.stop();
|
|
42
|
+
}).on(TRTC.EVENT.SCREEN_SHARE_STOPPED, () => {
|
|
43
|
+
this.dispatchEvent('cancel');
|
|
44
|
+
this.stop();
|
|
45
|
+
}).on(TRTC.EVENT.TRACK, () => {
|
|
46
|
+
this.active = true;
|
|
47
|
+
this.dispatchEvent('start');
|
|
48
|
+
}).on(TRTC.EVENT.VIDEO_PLAY_STATE_CHANGED, ({ state }) => {
|
|
49
|
+
if (state === 'STOPPED') {
|
|
50
|
+
this.dispatchEvent('stop');
|
|
51
|
+
}
|
|
52
|
+
else if (state === 'PLAYING') {
|
|
53
|
+
this.dispatchEvent('playing');
|
|
54
|
+
}
|
|
55
|
+
this.element = this.options.element.querySelector('video');
|
|
56
|
+
}).on(TRTC.EVENT.CUSTOM_MESSAGE, (message) => {
|
|
57
|
+
let decoder = new TextDecoder('utf-8');
|
|
58
|
+
let payload = decoder.decode(message.data);
|
|
59
|
+
this.dispatchEvent('message', payload);
|
|
67
60
|
});
|
|
61
|
+
await this.trtc.enterRoom(params);
|
|
68
62
|
}
|
|
69
63
|
/**
|
|
70
64
|
* 发送自定义消息
|
|
@@ -105,7 +99,6 @@ export class TxrtcScreenMonitor extends TxrtcMonitor {
|
|
|
105
99
|
async start() {
|
|
106
100
|
await super.start();
|
|
107
101
|
await this.trtc.startScreenShare({ publish: true, view: this.options.element });
|
|
108
|
-
await this.initEvent();
|
|
109
102
|
}
|
|
110
103
|
async stop() {
|
|
111
104
|
await this.trtc.stopScreenShare();
|
|
@@ -126,14 +119,13 @@ export class TxrtcCameraMonitor extends TxrtcMonitor {
|
|
|
126
119
|
await super.start();
|
|
127
120
|
await this.trtc.startLocalAudio({ publish: true });
|
|
128
121
|
await this.trtc.startLocalVideo({ publish: true, view: this.options.element });
|
|
129
|
-
await this.initEvent();
|
|
130
122
|
}
|
|
131
123
|
/**
|
|
132
124
|
* 切换摄像头
|
|
133
125
|
*/
|
|
134
126
|
async switch(option) {
|
|
135
127
|
if (option?.cameraId || option?.useFrontCamera) {
|
|
136
|
-
await this.trtc.updateLocalVideo({ option });
|
|
128
|
+
await this.trtc.updateLocalVideo({ option, publish: true, view: this.options.element });
|
|
137
129
|
}
|
|
138
130
|
}
|
|
139
131
|
async stop() {
|