zbzt-live-sdk 0.0.2
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/.babelrc +8 -0
- package/.editorconfig +13 -0
- package/.eslintrc.js +29 -0
- package/CHANGELOG.md +16 -0
- package/README.md +32 -0
- package/dist/zbzt-live-sdk.cjs.js +51 -0
- package/dist/zbzt-live-sdk.esm.js +51 -0
- package/dist/zbzt-live-sdk.umd.js +52 -0
- package/dist/zbzt-live-sdk.umd.js.map +1 -0
- package/example/app.js +133 -0
- package/example/bootstrap-3.4.1/css/bootstrap-theme.css +587 -0
- package/example/bootstrap-3.4.1/css/bootstrap-theme.css.map +1 -0
- package/example/bootstrap-3.4.1/css/bootstrap-theme.min.css +6 -0
- package/example/bootstrap-3.4.1/css/bootstrap-theme.min.css.map +1 -0
- package/example/bootstrap-3.4.1/css/bootstrap.css +6834 -0
- package/example/bootstrap-3.4.1/css/bootstrap.css.map +1 -0
- package/example/bootstrap-3.4.1/css/bootstrap.min.css +6 -0
- package/example/bootstrap-3.4.1/css/bootstrap.min.css.map +1 -0
- package/example/bootstrap-3.4.1/fonts/glyphicons-halflings-regular.eot +0 -0
- package/example/bootstrap-3.4.1/fonts/glyphicons-halflings-regular.svg +288 -0
- package/example/bootstrap-3.4.1/fonts/glyphicons-halflings-regular.ttf +0 -0
- package/example/bootstrap-3.4.1/fonts/glyphicons-halflings-regular.woff +0 -0
- package/example/bootstrap-3.4.1/fonts/glyphicons-halflings-regular.woff2 +0 -0
- package/example/bootstrap-3.4.1/js/bootstrap.js +2580 -0
- package/example/bootstrap-3.4.1/js/bootstrap.min.js +6 -0
- package/example/bootstrap-3.4.1/js/npm.js +13 -0
- package/example/css/style.css +18 -0
- package/example/index.html +59 -0
- package/example/js/jquery-3.7.1.min.js +2 -0
- package/example/js/utils.js +25 -0
- package/example/js/variables.js +14 -0
- package/example/js/zegoApi.js +229 -0
- package/example/style.css +25 -0
- package/example/test.html +100 -0
- package/package.json +60 -0
- package/release.js +33 -0
- package/rollup-plugin-http.js +49 -0
- package/src/channel/getSendMsgParams.js +66 -0
- package/src/channel/index.js +135 -0
- package/src/channel/pomelo/index.js +182 -0
- package/src/channel/pomelo/latestQueue.js +150 -0
- package/src/channel/pomelo/polemo.js +730 -0
- package/src/channel/pomelo/util.js +54 -0
- package/src/channel/sdk-cb.js +73 -0
- package/src/channel/stream-msg.js +97 -0
- package/src/channel/zbzt/index.js +74 -0
- package/src/channel/zbzt/interactWithChannel.js +4 -0
- package/src/channel/zbzt/interactWithChannelControl.js +1568 -0
- package/src/channel/zbzt/interactWithChannelEntry.js +318 -0
- package/src/config/config.js +226 -0
- package/src/default/base.js +71 -0
- package/src/default/extend.js +36 -0
- package/src/default/index.js +10 -0
- package/src/live/base.js +43 -0
- package/src/live/call-method.js +10 -0
- package/src/live/extend.js +53 -0
- package/src/live/index.js +10 -0
- package/src/network/api.js +56 -0
- package/src/network/commonFetch.js +66 -0
- package/src/network/dataReport.js +448 -0
- package/src/notice.js +418 -0
- package/src/tool/base.js +74 -0
- package/src/tool/call-method.js +10 -0
- package/src/tool/extend.js +42 -0
- package/src/tool/index.js +10 -0
- package/src/util/bridge.js +87 -0
- package/src/util/bridge1.js +46 -0
- package/src/util/dict.js +51 -0
- package/src/util/sessionStorage.js +29 -0
- package/src/util/sha256.js +483 -0
- package/src/util/util.js +329 -0
- package/src/zbzt-av-sdk/default-sdk.js +192 -0
- package/src/zbzt-av-sdk/device.js +86 -0
- package/src/zbzt-av-sdk/rtc-sdk.js +2854 -0
- package/src/zbzt-av-sdk/talrtc-sdk.js +2620 -0
- package/src/zbzt-av-sdk/trtc-sdk.js +1802 -0
- package/src/zbzt-av-sdk/zbzt-av-sdk.js +2121 -0
- package/src/zbzt-av-sdk/zego-sdk.js +1718 -0
- package/src/zbzt-av-sdk/zego-sdk.js.bak +3133 -0
- package/src/zbzt-live-sdk.js +1484 -0
|
@@ -0,0 +1,1484 @@
|
|
|
1
|
+
import zbztAVSDK from './zbzt-av-sdk/zbzt-av-sdk';
|
|
2
|
+
import {
|
|
3
|
+
version,
|
|
4
|
+
config,
|
|
5
|
+
getApiCloudBaseUrl,
|
|
6
|
+
USER_LOCATION,
|
|
7
|
+
} from './config/config';
|
|
8
|
+
import util from './util/util';
|
|
9
|
+
import dict from './util/dict';
|
|
10
|
+
|
|
11
|
+
import CHANNEL from './channel';
|
|
12
|
+
|
|
13
|
+
import dataReport from './network/dataReport';
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
getCloudData,
|
|
17
|
+
changeSdkInRoom
|
|
18
|
+
} from './network/api';
|
|
19
|
+
|
|
20
|
+
import defaultApi from './default';
|
|
21
|
+
import NOTICE from './notice';
|
|
22
|
+
|
|
23
|
+
// window.zegoHasPushFlow = 0
|
|
24
|
+
|
|
25
|
+
export let userAndDeviceStatusInfo = {
|
|
26
|
+
microPhone: false,
|
|
27
|
+
camera: false,
|
|
28
|
+
isPushingFlow: false,
|
|
29
|
+
//不看他
|
|
30
|
+
// ignoreList : new Set()
|
|
31
|
+
};
|
|
32
|
+
let sdkConfig = config;
|
|
33
|
+
let sdk_status = -1;
|
|
34
|
+
let sdkRetryCount = 0;
|
|
35
|
+
const windowObjArr = [['zbzt_sdk_req_get_cloud_params', 'zbztAVSDK_init_params', 'zbztAVSDK_device_checker_init', 'zbzt_sdk_cloud_data'], ['zbztAVSDK_init_sdk_type', 'current_sdk_type']];
|
|
36
|
+
|
|
37
|
+
let confId;
|
|
38
|
+
|
|
39
|
+
let mirrorStatus = null;
|
|
40
|
+
// 重试初始化
|
|
41
|
+
function retryInit(error, name = 'init', args, dealSDKMsg) {
|
|
42
|
+
//通知业务层,初始化失败,重试
|
|
43
|
+
sdkRetryCount++;
|
|
44
|
+
sdk_status = -1;
|
|
45
|
+
if (sdkRetryCount > 3) {
|
|
46
|
+
sdkRetryCount = 0;
|
|
47
|
+
NOTICE.sdkStatus({
|
|
48
|
+
status: 'retry_stop'
|
|
49
|
+
});
|
|
50
|
+
try {
|
|
51
|
+
// console.log('获取云控失败上报加入教室code1',window.zbzt_sdk_init_params);
|
|
52
|
+
dataReport.joinRoomResult({
|
|
53
|
+
code: '1',
|
|
54
|
+
// cloud_api_response: JSON.stringify(window.zbzt_sdk_cloud_data),
|
|
55
|
+
// cloud_api_response: window.zbzt_sdk_cloud_data,
|
|
56
|
+
cloud_api_url: `${getApiCloudBaseUrl()}/rtccloud/class/init`
|
|
57
|
+
});
|
|
58
|
+
} catch(e) {
|
|
59
|
+
defaultApi.writeLog('获取云控接口失败');
|
|
60
|
+
}
|
|
61
|
+
} else {
|
|
62
|
+
NOTICE.sdkStatus({
|
|
63
|
+
status: `retry_${name}`,
|
|
64
|
+
count: sdkRetryCount
|
|
65
|
+
});
|
|
66
|
+
defaultApi.writeLog(`sdk action: retry_${name}, count: it's the 【${sdkRetryCount}】 retry, ${error} error`);
|
|
67
|
+
if (name === 'init') {
|
|
68
|
+
return zbztsdk.init(args, dealSDKMsg);
|
|
69
|
+
}
|
|
70
|
+
return zbztsdk.changeSDK(1);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 设备状态通知
|
|
77
|
+
* @param {String} deviceType 'audio', 'video'
|
|
78
|
+
* @param {Bollean} operation
|
|
79
|
+
*/
|
|
80
|
+
function sendDeviceStatus(deviceType, operation) {
|
|
81
|
+
if (window.zbztAVSDK_init_params) {
|
|
82
|
+
const initParams = window.zbzt_sdk_init_params;
|
|
83
|
+
NOTICE.deviceStatus({
|
|
84
|
+
userId: initParams.userId,
|
|
85
|
+
userName: initParams.userName,
|
|
86
|
+
role: initParams.role,
|
|
87
|
+
//获取设备类型和状态对应的文案,返回给业务层
|
|
88
|
+
deviceType: deviceType,
|
|
89
|
+
deviceStatus: operation ? 'open' : 'closed'
|
|
90
|
+
});
|
|
91
|
+
//更新设备状态,摄像头,麦克风 开启/关闭
|
|
92
|
+
CHANNEL.sendUpdateStreamDeviceStatus(Object.assign({}, initParams, {
|
|
93
|
+
deviceType: dict.getDeviceTypeKey(deviceType),
|
|
94
|
+
deviceStatus: dict.getDeviceStatusKey(operation ? 'open' : 'closed')
|
|
95
|
+
}));
|
|
96
|
+
} else {
|
|
97
|
+
console.log('尚未初始化,无须设备状态同步');
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
*
|
|
102
|
+
* @param {String} userId
|
|
103
|
+
* @param {String} status 流状态
|
|
104
|
+
*/
|
|
105
|
+
function noticeStreamStatus(userId, status) {
|
|
106
|
+
NOTICE.streamStatus({
|
|
107
|
+
userId,
|
|
108
|
+
status
|
|
109
|
+
});
|
|
110
|
+
defaultApi.writeLog(`sdk stream status userId: ${JSON.stringify(userId)} ${status}`);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function generateStreamId(userId, groupId) {
|
|
114
|
+
if (!window.zbzt_sdk_init_params) {
|
|
115
|
+
console.log('缺少初始化参数,无法生成streamId');
|
|
116
|
+
}
|
|
117
|
+
const initParams = window.zbzt_sdk_init_params;
|
|
118
|
+
if (!initParams) {
|
|
119
|
+
return '';
|
|
120
|
+
}
|
|
121
|
+
// TODO 测试用
|
|
122
|
+
// if (initParams.sdkName === 'talrtc') {
|
|
123
|
+
// initParams.institutionId = 'd46144';
|
|
124
|
+
// }
|
|
125
|
+
return util.getStreamId({
|
|
126
|
+
...initParams,
|
|
127
|
+
userId,
|
|
128
|
+
groupId
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function caculateDeatailArgs(baseArgs, cloudData) {
|
|
133
|
+
try {
|
|
134
|
+
const commonArgs = {
|
|
135
|
+
userId: baseArgs.userId,
|
|
136
|
+
streamId: util.getStreamId(baseArgs),
|
|
137
|
+
userName: baseArgs.userName || '',
|
|
138
|
+
sid: baseArgs.sid,
|
|
139
|
+
role: baseArgs.role,
|
|
140
|
+
roomId: baseArgs.roomId + '',
|
|
141
|
+
confId: confId,
|
|
142
|
+
userAvatar: baseArgs.userAvatar || '',
|
|
143
|
+
userToken: baseArgs.userToken || '',
|
|
144
|
+
devices: baseArgs.devices,
|
|
145
|
+
env: baseArgs.env,
|
|
146
|
+
businessLinesType: baseArgs.businessLinesType,
|
|
147
|
+
institutionId: baseArgs.institutionId,
|
|
148
|
+
//站立模式:0 / 坐立模式:1
|
|
149
|
+
mode: baseArgs.mode,
|
|
150
|
+
live_id: baseArgs.liveId,
|
|
151
|
+
// 课堂模式,0=小组课/1=新小班
|
|
152
|
+
classMode: +baseArgs.classMode,
|
|
153
|
+
//数据上报班课类型
|
|
154
|
+
liveType: +baseArgs.liveType,
|
|
155
|
+
//是否开启转推功能
|
|
156
|
+
isTurnPush: baseArgs.isTurnPush || false,
|
|
157
|
+
// isSetAEC: baseArgs.isSetAEC || false,
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
//从云控返回值中获取直播相关配置
|
|
161
|
+
const liveConfig = {
|
|
162
|
+
//大画面视频采集码率(取值范围:40kb~2000kb)
|
|
163
|
+
// captureBitrate: +cloudData.captureBitrate,
|
|
164
|
+
//大画面视频采集帧率(取值范围:5~30)
|
|
165
|
+
// captureFps: +cloudData.captureFps,
|
|
166
|
+
//大画面视频编码分辨率
|
|
167
|
+
encodedResolutionWidth: +cloudData.encodedResolution.split('*')[0],
|
|
168
|
+
encodedResolutionHeight: +cloudData.encodedResolution.split('*')[1],
|
|
169
|
+
// 预览画面视频采集码率(取值范围:40kb~300kb)
|
|
170
|
+
encodeCaptureBitrate: +cloudData.encodedBitrate,
|
|
171
|
+
encodeCaptureFps: +cloudData.encodedFps,
|
|
172
|
+
// 预览画面视频采集帧率(取值范围:5~15)
|
|
173
|
+
previewCaptureFps: +cloudData.previewFps,
|
|
174
|
+
// 预览视频编码分辨率
|
|
175
|
+
previewResolutionWidth: +cloudData.previewResolution.split('*')[0],
|
|
176
|
+
previewResolutionHeight: +cloudData.previewResolution.split('*')[1],
|
|
177
|
+
//rtc同屏分辨率
|
|
178
|
+
screenSameResolutionWidth: cloudData.screenSameResolution ? +cloudData.screenSameResolution.split('*')[0] : 1280,
|
|
179
|
+
screenSameResolutionHeight: cloudData.screenSameResolution ? +cloudData.screenSameResolution.split('*')[1] : 720,
|
|
180
|
+
//rtc同屏帧率 码率
|
|
181
|
+
screenSameFps: cloudData.screenSameFps ? +cloudData.screenSameFps : 15,
|
|
182
|
+
screenSameBitrate: cloudData.screenSameBitrate ? +cloudData.screenSameBitrate : 512000,
|
|
183
|
+
// 转推Rtmp地址
|
|
184
|
+
recordUrl: cloudData.recordUrl,
|
|
185
|
+
aecMode: cloudData.aecMode != null ? cloudData.aecMode : -1,
|
|
186
|
+
noiseSuppressMode: cloudData.noiseSuppressMode != null ? cloudData.noiseSuppressMode : -1
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
const detailArgs = {
|
|
190
|
+
talrtc: Object.assign({}, commonArgs, liveConfig, {
|
|
191
|
+
appId: cloudData.appId,
|
|
192
|
+
usersign: 'testsign',
|
|
193
|
+
teacherId: baseArgs.teacherId,
|
|
194
|
+
}),
|
|
195
|
+
nertc: Object.assign({}, commonArgs, liveConfig, {
|
|
196
|
+
appId: cloudData.appId,
|
|
197
|
+
usersign: 'testsign',
|
|
198
|
+
teacherId: baseArgs.teacherId,
|
|
199
|
+
}),
|
|
200
|
+
volcrtc: Object.assign({}, commonArgs, liveConfig, {
|
|
201
|
+
appId: cloudData.appId,
|
|
202
|
+
usersign: 'testsign',
|
|
203
|
+
teacherId: baseArgs.teacherId,
|
|
204
|
+
}),
|
|
205
|
+
trtc: Object.assign({}, commonArgs, liveConfig, {
|
|
206
|
+
appId: cloudData.appId,
|
|
207
|
+
usersign: cloudData.txRtcKey,
|
|
208
|
+
}),
|
|
209
|
+
zego: Object.assign({}, commonArgs, liveConfig, {
|
|
210
|
+
appId: parseInt(cloudData.appId)|| 2251703116,
|
|
211
|
+
appSignature: cloudData.appKey|| 'uYsmfJ4F8ERzRNC4ug6lWB/vfU6ffg+/ETRF14vjzs4=',
|
|
212
|
+
businessType: 0,
|
|
213
|
+
nNetType: 1,
|
|
214
|
+
})
|
|
215
|
+
|
|
216
|
+
};
|
|
217
|
+
return detailArgs;
|
|
218
|
+
} catch (error) {
|
|
219
|
+
console.error(error);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* SDK 方法
|
|
225
|
+
*/
|
|
226
|
+
const zbztsdk = {
|
|
227
|
+
version: version,
|
|
228
|
+
notice: null,
|
|
229
|
+
// 打开监听log
|
|
230
|
+
openListenerLog: false,
|
|
231
|
+
//端上初始化时传的false
|
|
232
|
+
autoChangeSdk: true,
|
|
233
|
+
log_id:null,
|
|
234
|
+
setConfig(options) {
|
|
235
|
+
Object.assign(sdkConfig, options);
|
|
236
|
+
Object.assign(this, options);
|
|
237
|
+
},
|
|
238
|
+
USER_LOCATION,
|
|
239
|
+
deviceStatus: {},
|
|
240
|
+
enableLog(enable = true) {
|
|
241
|
+
defaultApi.writeLog(`sdk action: enableLog ${JSON.stringify(enable)}`);
|
|
242
|
+
config.weblog = !!enable;
|
|
243
|
+
},
|
|
244
|
+
|
|
245
|
+
async deviceCheckerInit(cb) {
|
|
246
|
+
if (typeof cb !== 'function') {
|
|
247
|
+
defaultApi.writeLog(`sdk action: deviceCheckerInit need a callback function, but received: ${typeof cb}`, null, 'error');
|
|
248
|
+
throw new Error('deviceCheckerInit need a callback function');
|
|
249
|
+
}
|
|
250
|
+
NOTICE.setEmitter({
|
|
251
|
+
emit: cb.bind(zbztsdk)
|
|
252
|
+
});
|
|
253
|
+
window.zbztAVSDK_init_sdk_type = null;
|
|
254
|
+
},
|
|
255
|
+
stopCheckDevice() {
|
|
256
|
+
defaultApi.writeLog('sdk action: stopCheckDevice');
|
|
257
|
+
},
|
|
258
|
+
async init(args, dealSDKMsg) {
|
|
259
|
+
if (sdk_status !== -1) {
|
|
260
|
+
console.log('not allow init');
|
|
261
|
+
dealSDKMsg({
|
|
262
|
+
type: 'error',
|
|
263
|
+
data: {
|
|
264
|
+
message: 'should not start init before init finished'
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
defaultApi.writeLog(`sdk action: init zbzt_live_sdk_version : ${version}`);
|
|
270
|
+
defaultApi.writeLog(`sdk action: init args : ${JSON.stringify(args)}`);
|
|
271
|
+
try {
|
|
272
|
+
let argsCopy = JSON.parse(JSON.stringify(args));
|
|
273
|
+
delete argsCopy.cloudData;
|
|
274
|
+
defaultApi.writeLog(`sdk action: init_argsCopy_args : ${JSON.stringify(argsCopy)}`);
|
|
275
|
+
} catch (e) {};
|
|
276
|
+
this.log_id = 0;
|
|
277
|
+
sdk_status = 0;
|
|
278
|
+
// 初始化参数存入共享
|
|
279
|
+
window.zbzt_sdk_init_params = args;
|
|
280
|
+
// 设置confId
|
|
281
|
+
confId = util.getConfId(args.institutionId, args.roomId);
|
|
282
|
+
//使用初始化传入的 env, isHttps 参数
|
|
283
|
+
Object.assign(sdkConfig, args);
|
|
284
|
+
|
|
285
|
+
NOTICE.setEmitter({
|
|
286
|
+
emit: dealSDKMsg.bind(zbztsdk)
|
|
287
|
+
});
|
|
288
|
+
// zbztsdk.notice = dealSDKMsg;
|
|
289
|
+
|
|
290
|
+
const reqParam = {
|
|
291
|
+
clientType: 'web',
|
|
292
|
+
roomType: 7,
|
|
293
|
+
institutionId: args.institutionId + '',
|
|
294
|
+
roomId: args.roomId + '',
|
|
295
|
+
userType: args.role,
|
|
296
|
+
userId: args.userId + '',
|
|
297
|
+
teacherId: args.teacherId + ''
|
|
298
|
+
};
|
|
299
|
+
window.zbzt_sdk_req_get_cloud_params = reqParam;
|
|
300
|
+
let cloudData;
|
|
301
|
+
if (args.cloudData && args.cloudData.sdkName && args.cloudData.encodedResolution && args.cloudData.previewResolution) {
|
|
302
|
+
cloudData = args.cloudData;
|
|
303
|
+
} else {
|
|
304
|
+
defaultApi.writeLog(`sdk_init: getCloudData reqParam : ${JSON.stringify(reqParam)}`);
|
|
305
|
+
let cloudResponse;
|
|
306
|
+
try {
|
|
307
|
+
cloudResponse = await getCloudData(reqParam);
|
|
308
|
+
} catch (error) {
|
|
309
|
+
return retryInit('getCloudData', 'init', args, dealSDKMsg);
|
|
310
|
+
}
|
|
311
|
+
defaultApi.writeLog(`sdk_init: cloudResponse : ${JSON.stringify(cloudResponse)}`);
|
|
312
|
+
if (cloudResponse.code === 0 && cloudResponse.data) {
|
|
313
|
+
cloudData = cloudResponse.data;
|
|
314
|
+
} else {
|
|
315
|
+
defaultApi.writeLog(`sdk_init: get cloudResponse error: ${JSON.stringify(cloudResponse)}`);
|
|
316
|
+
return false;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
defaultApi.writeLog(`sdk_init: cloudData : ${JSON.stringify(cloudData)}`);
|
|
320
|
+
window.zbzt_sdk_cloud_data = cloudData;
|
|
321
|
+
const detailArgs = caculateDeatailArgs(args, cloudData);
|
|
322
|
+
|
|
323
|
+
let sdk_type = cloudData.sdkName;
|
|
324
|
+
// let sdk_type = 'zego';
|
|
325
|
+
Object.assign(window.zbzt_sdk_init_params, cloudData);
|
|
326
|
+
//通知业务层,初始化完成
|
|
327
|
+
NOTICE.sdkStatus({
|
|
328
|
+
sdk_type,
|
|
329
|
+
status: 'before_init'
|
|
330
|
+
});
|
|
331
|
+
defaultApi.writeLog(`sdk status : before_init , sdk_type : ${sdk_type}`);
|
|
332
|
+
await zbztAVSDK.init(sdk_type, detailArgs).catch(error => {
|
|
333
|
+
defaultApi.writeLog(`sdk init AVSDK init_failed ${JSON.stringify(error)}`);
|
|
334
|
+
return;
|
|
335
|
+
});
|
|
336
|
+
defaultApi.writeLog(`sdk status : setAudioCallbackType , sdk_type : ${sdk_type}`);
|
|
337
|
+
try {
|
|
338
|
+
// dataReport.joinRoom({initParams: JSON.stringify(args)});
|
|
339
|
+
dataReport.joinRoom({initParams: args});
|
|
340
|
+
} catch (e) {};
|
|
341
|
+
defaultApi.writeLog(`sdk status : init_finished , sdk_type : ${sdk_type}`);
|
|
342
|
+
//通知业务层,初始化完成
|
|
343
|
+
NOTICE.sdkStatus({
|
|
344
|
+
sdk_type,
|
|
345
|
+
status: 'init_finished'
|
|
346
|
+
});
|
|
347
|
+
try{
|
|
348
|
+
dataReport.initFinished({code:0});
|
|
349
|
+
}catch (e){ }
|
|
350
|
+
sdk_status = 1;
|
|
351
|
+
sdkRetryCount = 0;
|
|
352
|
+
|
|
353
|
+
// 缓存初始化信息
|
|
354
|
+
windowObjArr[0].forEach(item => {
|
|
355
|
+
if (window[item] !== undefined) {
|
|
356
|
+
localStorage.setItem(item, JSON.stringify(window[item]));
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
windowObjArr[1].forEach(item => {
|
|
360
|
+
if (window[item] !== undefined) {
|
|
361
|
+
localStorage.setItem(item, window[item]);
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
//进入信道房间
|
|
366
|
+
// enterChannelRoom({...args, chatUrl: cloudData.chatUrl}, dealSDKMsg);
|
|
367
|
+
// sendInitChannelMsg(args);
|
|
368
|
+
CHANNEL.joinRoom({...args, chatUrl: cloudData.chatUrl, guid: window.zbzt_sdk_init_params.guid}, dealSDKMsg, cloudData.chatType);
|
|
369
|
+
},
|
|
370
|
+
|
|
371
|
+
// 恢复sdk
|
|
372
|
+
async recoverSdk(args, dealSDKMsg) {
|
|
373
|
+
defaultApi.writeLog(`sdk action : recoverSdk , args : ${JSON.stringify(args)}`);
|
|
374
|
+
// 恢复全局变量
|
|
375
|
+
windowObjArr[0].forEach(item => {
|
|
376
|
+
const obj = localStorage.getItem(item);
|
|
377
|
+
if (obj && obj.indexOf('{') > -1) {
|
|
378
|
+
try {
|
|
379
|
+
window[item] = JSON.parse(obj);
|
|
380
|
+
} catch (error) {
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
let cloudData;
|
|
385
|
+
if (args.cloudData) {
|
|
386
|
+
cloudData = args.cloudData;
|
|
387
|
+
} else {
|
|
388
|
+
try {
|
|
389
|
+
cloudData = JSON.parse(localStorage.getItem('zbzt_sdk_cloud_data'));
|
|
390
|
+
} catch (error) {
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
windowObjArr[1].forEach(item => {
|
|
394
|
+
window[item] = localStorage.getItem(item);
|
|
395
|
+
});
|
|
396
|
+
window.zbzt_sdk_init_params = args;
|
|
397
|
+
|
|
398
|
+
defaultApi.writeLog('sdk action : recoverSdk , set window params finished');
|
|
399
|
+
|
|
400
|
+
// try {
|
|
401
|
+
// await getLogAddress();
|
|
402
|
+
// await getAndSetInitParams({institutionId: args.institutionId, userId: args.userId});
|
|
403
|
+
// } catch (error) {
|
|
404
|
+
// return retryInit('getAndSetInitParams', 'init', args, dealSDKMsg);
|
|
405
|
+
// }
|
|
406
|
+
|
|
407
|
+
//使用初始化传入的 env, isHttps 参数
|
|
408
|
+
Object.assign(sdkConfig, args);
|
|
409
|
+
|
|
410
|
+
zbztsdk.notice = dealSDKMsg;
|
|
411
|
+
|
|
412
|
+
const detailArgs = caculateDeatailArgs(args, cloudData);
|
|
413
|
+
|
|
414
|
+
await zbztAVSDK.recoverSdk(detailArgs);
|
|
415
|
+
|
|
416
|
+
sdk_status = 1;
|
|
417
|
+
|
|
418
|
+
//通知业务层,初始化完成
|
|
419
|
+
NOTICE.sdkStatus({
|
|
420
|
+
sdk_type: window.zbztAVSDK_init_sdk_type,
|
|
421
|
+
status: 'init_finished'
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
defaultApi.writeLog('sdk action : recoverSdk finished');
|
|
425
|
+
|
|
426
|
+
//进入信道房间
|
|
427
|
+
// enterChannelRoom({...args, chatUrl: cloudData.chatUrl}, dealSDKMsg);
|
|
428
|
+
// sendInitChannelMsg(args);
|
|
429
|
+
CHANNEL.joinRoom({...args, chatUrl: cloudData.chatUrl}, dealSDKMsg, cloudData.chatType);
|
|
430
|
+
},
|
|
431
|
+
|
|
432
|
+
// 接收到信道消息,进行切换SDK操作
|
|
433
|
+
// from 0:云控 1:重试 2: 上层调用
|
|
434
|
+
async changeSDK(from = 0) {
|
|
435
|
+
if (!window.zbzt_sdk_init_params || !window.zbzt_sdk_req_get_cloud_params) {
|
|
436
|
+
console.log('缺少初始化参数,无法切换SDK');
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
//重试(2)不走下一步,否则会陷入死循环,如果是reJoin(1)来的,自动走切sdk逻辑,不触发start_sdk_change回调直接切
|
|
440
|
+
if (from < 1) {
|
|
441
|
+
// 通知业务层,切换之前(授课业务逻辑需要,比如老师主动调切sdk,云控走的切sdk全部由老师主动切,修复连麦崩溃)
|
|
442
|
+
NOTICE.sdkStatus({
|
|
443
|
+
sdk_type: window.zbztAVSDK_init_sdk_type,
|
|
444
|
+
status: 'start_sdk_change'
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
defaultApi.writeLog('sdk status : start_sdk_change');
|
|
448
|
+
if (from === 0 && !this.autoChangeSdk) {
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
const initParams = window.zbzt_sdk_init_params;
|
|
452
|
+
let nowSdk = window.zbztAVSDK_init_sdk_type;
|
|
453
|
+
let cloudData;
|
|
454
|
+
//请求云控获取更新后的SDK配置相关信息
|
|
455
|
+
let cloudResponse;
|
|
456
|
+
try {
|
|
457
|
+
cloudResponse = await getCloudData(window.zbzt_sdk_req_get_cloud_params);
|
|
458
|
+
} catch (error)
|
|
459
|
+
{
|
|
460
|
+
defaultApi.writeLog(`changeSDK: getCloudData error ${JSON.stringify(error)}`);
|
|
461
|
+
return retryInit('getCloudData', 'changeSDK');
|
|
462
|
+
};
|
|
463
|
+
cloudData = cloudResponse.data;
|
|
464
|
+
|
|
465
|
+
if (cloudData) {
|
|
466
|
+
const changeSDKParam = caculateDeatailArgs(initParams, cloudData);
|
|
467
|
+
const sdk_type = cloudData.sdkName;
|
|
468
|
+
|
|
469
|
+
window.zbztAVSDK_init_params = changeSDKParam;
|
|
470
|
+
|
|
471
|
+
if (window.zbztAVSDK_init_sdk_type === sdk_type && sdk_type !== 'talrtc') {
|
|
472
|
+
defaultApi.writeLog(`sdk: change sdk action , target is the same as local , will not change sdk to ${sdk_type}`);
|
|
473
|
+
window.target_sdk_type = null;
|
|
474
|
+
return;
|
|
475
|
+
} else {
|
|
476
|
+
window.target_sdk_type = sdk_type;
|
|
477
|
+
defaultApi.writeLog(`sdk action: changeSDK to sdk_type : ${sdk_type}, sdk status : start_change `);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
// 通知业务层,切换之前
|
|
481
|
+
NOTICE.sdkStatus({
|
|
482
|
+
sdk_type: window.zbztAVSDK_init_sdk_type,
|
|
483
|
+
target_sdk_type: sdk_type,
|
|
484
|
+
status: 'before_sdk_change'
|
|
485
|
+
});
|
|
486
|
+
defaultApi.writeLog(`sdk status : before_sdk_change to sdk_type : ${sdk_type}`);
|
|
487
|
+
|
|
488
|
+
sdk_status = 0;
|
|
489
|
+
|
|
490
|
+
try {
|
|
491
|
+
CHANNEL.sendRemoveStream(window.zbzt_sdk_init_params);
|
|
492
|
+
CHANNEL.sendLeave(window.zbzt_sdk_init_params);
|
|
493
|
+
await zbztAVSDK.changeSDK({
|
|
494
|
+
sdk_type
|
|
495
|
+
});
|
|
496
|
+
} catch (error) {
|
|
497
|
+
defaultApi.writeLog(`changeSDK error : ${JSON.stringify(error)}`);
|
|
498
|
+
window.target_sdk_type = null;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
if (mirrorStatus !== null) {
|
|
502
|
+
// 如果之前有镜像,切sdk之后,重新设置镜像
|
|
503
|
+
await zbztAVSDK.setMirrorStatus(mirrorStatus);
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
try {
|
|
507
|
+
dataReport.sdkChange({
|
|
508
|
+
from: nowSdk,
|
|
509
|
+
to: sdk_type
|
|
510
|
+
});
|
|
511
|
+
} catch (e){};
|
|
512
|
+
|
|
513
|
+
sdkRetryCount = 0;
|
|
514
|
+
sdk_status = 1;
|
|
515
|
+
window.target_sdk_type = null;
|
|
516
|
+
// 通知业务层,切换完成
|
|
517
|
+
NOTICE.sdkStatus({
|
|
518
|
+
sdk_type,
|
|
519
|
+
status: 'sdk_changed'
|
|
520
|
+
});
|
|
521
|
+
defaultApi.writeLog(`sdk status : sdk_changed , sdk_type : ${sdk_type}`);
|
|
522
|
+
|
|
523
|
+
//切换SDK 完成后,先发送 join消息
|
|
524
|
+
CHANNEL.sendJoin(initParams);
|
|
525
|
+
|
|
526
|
+
// 打开本地摄像头, 并开始推流后, 老师视频和麦克风状态变为'开启', 即true
|
|
527
|
+
await zbztsdk.openOrCloseCamera(userAndDeviceStatusInfo.camera);
|
|
528
|
+
await zbztsdk.openOrCloseMicrophone(userAndDeviceStatusInfo.microPhone);
|
|
529
|
+
|
|
530
|
+
if (userAndDeviceStatusInfo.isPushingFlow) {
|
|
531
|
+
await zbztsdk.startPushFlow();
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
const videoSrc = await zbztsdk.getOrLocateVideo({
|
|
535
|
+
isLocal: true,
|
|
536
|
+
});
|
|
537
|
+
NOTICE.updateLocalPreview({
|
|
538
|
+
videoSrc: videoSrc
|
|
539
|
+
});
|
|
540
|
+
defaultApi.writeLog(`sdk update_local_preview , videoSrc : ${videoSrc} `);
|
|
541
|
+
// }
|
|
542
|
+
}
|
|
543
|
+
},
|
|
544
|
+
changeGroup(groupId, channelToken) {
|
|
545
|
+
return this.changeRoom(groupId, channelToken);
|
|
546
|
+
},
|
|
547
|
+
|
|
548
|
+
//alias changeGroup
|
|
549
|
+
async changeRoom(roomId, channelToken) {
|
|
550
|
+
if (!channelToken) {
|
|
551
|
+
console.warn('changeRoom param: channelToken is required !');
|
|
552
|
+
defaultApi.writeLog('changeRoom param: channelToken is required !');
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
defaultApi.writeLog(`sdk action : changeRoom to roomId : ${roomId}`);
|
|
557
|
+
|
|
558
|
+
//业务层停止所有拉流
|
|
559
|
+
window.zbzt_sdk_init_params.roomId = roomId;
|
|
560
|
+
const initParams = window.zbzt_sdk_init_params;
|
|
561
|
+
|
|
562
|
+
// 通知业务层,room 切换之前
|
|
563
|
+
zbztsdk.notice({
|
|
564
|
+
type: 'sdk_status',
|
|
565
|
+
data: {
|
|
566
|
+
sdk_type: window.zbztAVSDK_init_sdk_type,
|
|
567
|
+
target_room_id: roomId,
|
|
568
|
+
status: 'before_room_change'
|
|
569
|
+
}
|
|
570
|
+
});
|
|
571
|
+
defaultApi.writeLog(`sdk status : before_room_change to roomId ${roomId}`);
|
|
572
|
+
//广播 leave 消息
|
|
573
|
+
CHANNEL.sendLeave(initParams);
|
|
574
|
+
//断开信道
|
|
575
|
+
CHANNEL.leaveRoom(initParams);
|
|
576
|
+
defaultApi.writeLog('channle status : leave channel room invoked');
|
|
577
|
+
//退出当前流媒体房间
|
|
578
|
+
await zbztAVSDK.leaveRoom();
|
|
579
|
+
|
|
580
|
+
|
|
581
|
+
//获取新小组的云控数据
|
|
582
|
+
let reqParam = {
|
|
583
|
+
clientType: 'pc',
|
|
584
|
+
roomType: 7,
|
|
585
|
+
institutionId: initParams.institutionId + '',
|
|
586
|
+
roomId: initParams.roomId + '',
|
|
587
|
+
userType: initParams.role,
|
|
588
|
+
userId: initParams.userId + '',
|
|
589
|
+
teacherId: initParams.teacherId + ''
|
|
590
|
+
};
|
|
591
|
+
reqParam.sign = util.getVerifySign(reqParam);
|
|
592
|
+
reqParam.main = 2;
|
|
593
|
+
//暂存请求云控所需参数,为切换SDK作预备
|
|
594
|
+
window.zbzt_sdk_req_get_cloud_params = reqParam;
|
|
595
|
+
const cloudResponse = await getCloudData(window.zbzt_sdk_req_get_cloud_params);
|
|
596
|
+
const cloudData = cloudResponse.data;
|
|
597
|
+
const sdk_type = cloudData.sdkName;
|
|
598
|
+
//SDK重新初始化
|
|
599
|
+
const detailArgs = caculateDeatailArgs(initParams, cloudData);
|
|
600
|
+
await zbztAVSDK.init(sdk_type, detailArgs);
|
|
601
|
+
|
|
602
|
+
//重新进入信道
|
|
603
|
+
initParams.channelToken = channelToken;
|
|
604
|
+
// enterChannelRoom({...initParams, chatUrl: cloudData.chatUrl});
|
|
605
|
+
defaultApi.writeLog('channle status : enter channel room invoked');
|
|
606
|
+
// sendInitChannelMsg(initParams);
|
|
607
|
+
CHANNEL.joinRoom({...args, chatUrl: cloudData.chatUrl}, dealSDKMsg, cloudData.chatType);
|
|
608
|
+
|
|
609
|
+
// 通知业务层,room 切换之前
|
|
610
|
+
zbztsdk.notice({
|
|
611
|
+
type: 'sdk_status',
|
|
612
|
+
data: {
|
|
613
|
+
sdk_type: window.zbztAVSDK_init_sdk_type,
|
|
614
|
+
room_id: roomId,
|
|
615
|
+
status: 'room_changed'
|
|
616
|
+
}
|
|
617
|
+
});
|
|
618
|
+
defaultApi.writeLog(`sdk status : room_changed ,roomId ${roomId}`);
|
|
619
|
+
|
|
620
|
+
},
|
|
621
|
+
async setCameraDevice(deviceId) {
|
|
622
|
+
defaultApi.writeLog(`sdk action : setCameraDevice --start,deviceId ${deviceId}`);
|
|
623
|
+
await zbztAVSDK.setCameraDevice(deviceId,'client');
|
|
624
|
+
defaultApi.writeLog(`sdk action : setCameraDevice --end,deviceId ${deviceId}`);
|
|
625
|
+
|
|
626
|
+
},
|
|
627
|
+
|
|
628
|
+
async getCameraDeviceList() {
|
|
629
|
+
defaultApi.writeLog('sdk action : getCameraDeviceList ');
|
|
630
|
+
const devices = await zbztAVSDK.getCameraDeviceList();
|
|
631
|
+
defaultApi.writeLog(`sdk action : getCameraDeviceList result ${JSON.stringify(devices)}`);
|
|
632
|
+
return devices;
|
|
633
|
+
},
|
|
634
|
+
|
|
635
|
+
async openOrCloseCamera(operation) {
|
|
636
|
+
defaultApi.writeLog(`sdk action : openOrCloseCamera ${operation} --start`);
|
|
637
|
+
await zbztAVSDK.openOrCloseCamera(operation);
|
|
638
|
+
try {
|
|
639
|
+
dataReport.deviceChange({
|
|
640
|
+
device_type: 1,
|
|
641
|
+
code: operation? 1 : 0,
|
|
642
|
+
device_name: window.zbztAVSDK_device_checker_init.camera.name,
|
|
643
|
+
device_id: window.zbztAVSDK_device_checker_init.camera.use
|
|
644
|
+
});
|
|
645
|
+
} catch (e){};
|
|
646
|
+
userAndDeviceStatusInfo.camera = operation;
|
|
647
|
+
//记录摄像头状态,用作推流类型上报,是否推视频
|
|
648
|
+
this.deviceStatus.camera = operation;
|
|
649
|
+
sdk_status === 1 && sendDeviceStatus('video', operation);
|
|
650
|
+
defaultApi.writeLog(`sdk action : openOrCloseCamera ${operation} --end`);
|
|
651
|
+
},
|
|
652
|
+
|
|
653
|
+
//推不推画面
|
|
654
|
+
async setPushStreamVideo(operation) {
|
|
655
|
+
await zbztAVSDK.setPushStreamVideo(operation);
|
|
656
|
+
defaultApi.writeLog(`sdk action : setPushStreamVideo ${operation} `);
|
|
657
|
+
},
|
|
658
|
+
|
|
659
|
+
//看或不看指定用户的视频
|
|
660
|
+
async setVideoMute(userId, operation, groupId) {
|
|
661
|
+
const streamId = generateStreamId(userId, groupId);
|
|
662
|
+
await zbztAVSDK.setVideoMute(streamId, operation);
|
|
663
|
+
defaultApi.writeLog(`sdk action : setVideoMute userId ${userId}, groupId ${groupId}, operation ${operation}, streamId ${streamId}`);
|
|
664
|
+
},
|
|
665
|
+
|
|
666
|
+
async getOrLocateVideo(args) {
|
|
667
|
+
defaultApi.writeLog(`sdk action : getOrLocateVideo --start args : ${JSON.stringify(args)}`);
|
|
668
|
+
const videoSrc = await zbztAVSDK.getOrLocateVideo({
|
|
669
|
+
domId: args.domId,
|
|
670
|
+
isLocal: args.isLocal,
|
|
671
|
+
streamId: args.streamId || (args.userId && generateStreamId(args.userId, args.groupId)),
|
|
672
|
+
});
|
|
673
|
+
defaultApi.writeLog(`sdk getOrLocateVideo successfully, videoSrc : ${videoSrc} `);
|
|
674
|
+
return videoSrc;
|
|
675
|
+
},
|
|
676
|
+
|
|
677
|
+
async linkMicReport(args) {
|
|
678
|
+
defaultApi.writeLog(`sdk action : linkMicReport args : ${JSON.stringify(args)}`);
|
|
679
|
+
const {name, pull_uid, trace_id} = args;
|
|
680
|
+
let pull_uid1 = [];
|
|
681
|
+
pull_uid.forEach( item => {
|
|
682
|
+
pull_uid1.push(item+'');
|
|
683
|
+
});
|
|
684
|
+
if (dataReport.hasOwnProperty(name)) {
|
|
685
|
+
dataReport[name]({pull_uid:pull_uid1,trace_id});
|
|
686
|
+
};
|
|
687
|
+
},
|
|
688
|
+
|
|
689
|
+
/**
|
|
690
|
+
* 开始推流
|
|
691
|
+
* @param {string} streamid 流唯一标识
|
|
692
|
+
* @param {0 | 1} idx 0: 启动摄像头 1: 启动屏幕共享
|
|
693
|
+
* @returns
|
|
694
|
+
*/
|
|
695
|
+
async startPushFlow(streamid, idx) {
|
|
696
|
+
defaultApi.writeLog(`sdk action : startPushFlow streamId:${streamid} idx: ${idx}`);
|
|
697
|
+
try {
|
|
698
|
+
// dataReport.startPublish({publish_streamid:window.zbztAVSDK_init_params.rtc.streamId});
|
|
699
|
+
streamid&&idx ? dataReport.startPublish({publish_rtc_streamid:streamid}) : dataReport.startPublish() ;
|
|
700
|
+
} catch (e) {};
|
|
701
|
+
await zbztAVSDK.startPushFlow(streamid, idx);
|
|
702
|
+
// 不重新推流此情况不适用,推流状态跟着设备开关情况改变,以下仅用作数据上报
|
|
703
|
+
// console.log('push_type000',this.deviceStatus.camera,this.deviceStatus.microphone);
|
|
704
|
+
if(this.deviceStatus.camera && this.deviceStatus.microphone) {
|
|
705
|
+
this.deviceStatus.stream_type = 'both';
|
|
706
|
+
} else if(!this.deviceStatus.camera && this.deviceStatus.microphone) {
|
|
707
|
+
this.deviceStatus.stream_type = 'audio';
|
|
708
|
+
} else if(this.deviceStatus.camera && !this.deviceStatus.microphone) {
|
|
709
|
+
this.deviceStatus.stream_type = 'video';
|
|
710
|
+
} else {
|
|
711
|
+
this.deviceStatus.stream_type = 'none';
|
|
712
|
+
}
|
|
713
|
+
const initParams = window.zbzt_sdk_init_params;
|
|
714
|
+
//rtc同屏流不走信道 !1
|
|
715
|
+
if(!idx) {
|
|
716
|
+
CHANNEL.sendAddStream(initParams);
|
|
717
|
+
userAndDeviceStatusInfo.isPushingFlow = true;
|
|
718
|
+
}
|
|
719
|
+
},
|
|
720
|
+
|
|
721
|
+
async stopPushFlow(idx, streamid) {
|
|
722
|
+
defaultApi.writeLog(`sdk action : stopPushFlow streamid:${streamid} idx:${idx}`);
|
|
723
|
+
await zbztAVSDK.stopPushFlow(idx, streamid);
|
|
724
|
+
try {
|
|
725
|
+
streamid && idx ? dataReport.stopPublish({ stop_rtc_streamid: streamid }) : dataReport.stopPublish();
|
|
726
|
+
// dataReport.stopPublish({});
|
|
727
|
+
} catch (error) { };
|
|
728
|
+
if(window.zbzt_sdk_init_params.isTurnPush) {
|
|
729
|
+
zbztAVSDK.turnPush('stop');
|
|
730
|
+
};
|
|
731
|
+
if(!idx) {
|
|
732
|
+
userAndDeviceStatusInfo.isPushingFlow = false;
|
|
733
|
+
CHANNEL.sendRemoveStream(window.zbzt_sdk_init_params);
|
|
734
|
+
}
|
|
735
|
+
},
|
|
736
|
+
|
|
737
|
+
async initPullFlow(args) {
|
|
738
|
+
defaultApi.writeLog(`sdk action : initPullFlow ,${JSON.stringify(args)}`);
|
|
739
|
+
const streamId = args.streamId || generateStreamId(args.userId, args.groupId);
|
|
740
|
+
let {mute, audioOnly} = args;
|
|
741
|
+
let streamType = 'none';
|
|
742
|
+
|
|
743
|
+
if(mute && audioOnly) {
|
|
744
|
+
streamType = 'none';
|
|
745
|
+
} else if (mute && !audioOnly) {
|
|
746
|
+
streamType = 'video';
|
|
747
|
+
} else if (!mute && audioOnly) {
|
|
748
|
+
streamType = 'audio';
|
|
749
|
+
} else {
|
|
750
|
+
streamType = 'both';
|
|
751
|
+
};
|
|
752
|
+
const result = zbztAVSDK.initPullFlow({
|
|
753
|
+
...args,
|
|
754
|
+
streamId
|
|
755
|
+
});
|
|
756
|
+
// defaultApi.writeLog(`sdk action : initPullFlow——result ,${JSON.stringify(result)}`);
|
|
757
|
+
try {
|
|
758
|
+
dataReport.startPull({pull_uid: args.userId || util.getUidByStreamId(streamId), pull_streamid: streamId, stream_type: streamType});
|
|
759
|
+
} catch (e) {};
|
|
760
|
+
const {
|
|
761
|
+
videoSrc,
|
|
762
|
+
playerId
|
|
763
|
+
} = await result.videoSrc;
|
|
764
|
+
defaultApi.writeLog(`sdk initPullFlow ${JSON.stringify(args)}, streamId : ${streamId}, result :${result.sdk_type}: ${videoSrc} type:${streamType} playerId:${playerId}`);
|
|
765
|
+
if (args.needPlayerId) {
|
|
766
|
+
return {
|
|
767
|
+
videoSrc,
|
|
768
|
+
playerId,
|
|
769
|
+
streamId,
|
|
770
|
+
...args
|
|
771
|
+
};
|
|
772
|
+
}
|
|
773
|
+
return videoSrc;
|
|
774
|
+
},
|
|
775
|
+
|
|
776
|
+
async startPullFlow(userId, groupId) {
|
|
777
|
+
if (typeof userId !== 'number' && typeof userId !== 'string') {
|
|
778
|
+
defaultApi.writeLog(`sdk action : startPullFlow ,userId : ${JSON.stringify(userId)}, param error`);
|
|
779
|
+
return;
|
|
780
|
+
} else {
|
|
781
|
+
defaultApi.writeLog(`sdk action : startPullFlow ,userId : ${JSON.stringify(userId)}, begin`);
|
|
782
|
+
}
|
|
783
|
+
const streamId = generateStreamId(userId, groupId);
|
|
784
|
+
await zbztAVSDK.startPullFlow(streamId);
|
|
785
|
+
// userAndDeviceStatusInfo.ignoreList.delete(userId)
|
|
786
|
+
noticeStreamStatus(userId, 'stream_recover');
|
|
787
|
+
defaultApi.writeLog(`sdk action : startPullFlow ,userId ${userId}, notice: stream_recover`);
|
|
788
|
+
},
|
|
789
|
+
|
|
790
|
+
async stopPullFlow(userId, groupId, recovery, streamid) {
|
|
791
|
+
// const {userId, groupId, recovery, streamid} = args;
|
|
792
|
+
if (typeof userId !== 'number' && typeof userId !== 'string') {
|
|
793
|
+
defaultApi.writeLog(`sdk action : stopPullFlow ,userId : ${userId}, groupId: ${groupId}, param error`);
|
|
794
|
+
return;
|
|
795
|
+
} else {
|
|
796
|
+
defaultApi.writeLog(`sdk action : stopPullFlow ,userId : ${userId}, groupId: ${groupId}, begin`);
|
|
797
|
+
}
|
|
798
|
+
const streamId = streamid || generateStreamId(userId, groupId);
|
|
799
|
+
await zbztAVSDK.stopPullFlow(streamId, recovery);
|
|
800
|
+
try {
|
|
801
|
+
dataReport.stopPull({pull_uid:userId,pull_streamid:streamId});
|
|
802
|
+
} catch (e) {};
|
|
803
|
+
noticeStreamStatus(userId, 'stream_stopped');
|
|
804
|
+
defaultApi.writeLog(`sdk action : stopPullFlow ,userId : ${userId}, groupId: ${groupId}, notice: stream_stopped`);
|
|
805
|
+
},
|
|
806
|
+
|
|
807
|
+
/**
|
|
808
|
+
* @function 暂停拉所有的流
|
|
809
|
+
* @return Promise | void
|
|
810
|
+
*/
|
|
811
|
+
async stopAllPullFlow() {
|
|
812
|
+
defaultApi.writeLog('sdk action : stopAllPullFlow begin');
|
|
813
|
+
await zbztAVSDK.stopAllPullFlow();
|
|
814
|
+
defaultApi.writeLog('sdk action : stopAllPullFlow end');
|
|
815
|
+
},
|
|
816
|
+
|
|
817
|
+
async playDestroy(userId, groupId) {
|
|
818
|
+
if (typeof userId !== 'number' && typeof userId !== 'string') {
|
|
819
|
+
defaultApi.writeLog(`sdk action : playDestroy ,userId : ${userId}, groupId: ${groupId}, param error`);
|
|
820
|
+
return;
|
|
821
|
+
} else {
|
|
822
|
+
defaultApi.writeLog(`sdk action : playDestroy ,userId : ${userId}, groupId: ${groupId}, begin`);
|
|
823
|
+
}
|
|
824
|
+
const streamId = generateStreamId(userId, groupId);
|
|
825
|
+
await zbztAVSDK.playDestroy(streamId);
|
|
826
|
+
noticeStreamStatus(userId, 'stream_destroy');
|
|
827
|
+
defaultApi.writeLog(`sdk action : playDestroy ,userId : ${userId}, groupId: ${groupId}, notice: stream_destroy`);
|
|
828
|
+
},
|
|
829
|
+
|
|
830
|
+
async changePullFlow(args) {
|
|
831
|
+
defaultApi.writeLog(`sdk action : changePullFlow ,${JSON.stringify(args)}`);
|
|
832
|
+
const streamId = generateStreamId(args.userId, args.groupId);
|
|
833
|
+
const toStreamId = generateStreamId(args.toUserId, args.toGroupId);
|
|
834
|
+
const result = zbztAVSDK.changePullFlow({
|
|
835
|
+
toDomId: args.toDomId,
|
|
836
|
+
streamId,
|
|
837
|
+
toStreamId
|
|
838
|
+
});
|
|
839
|
+
const {
|
|
840
|
+
videoSrc,
|
|
841
|
+
playerId
|
|
842
|
+
} = await result;
|
|
843
|
+
defaultApi.writeLog(`sdk changePullFlow ${JSON.stringify(args)}, streamId : ${streamId}, toStreamId : ${toStreamId}, result :${result.sdk_type}: ${videoSrc}`);
|
|
844
|
+
if (args.needPlayerId) {
|
|
845
|
+
return {
|
|
846
|
+
videoSrc,
|
|
847
|
+
playerId
|
|
848
|
+
};
|
|
849
|
+
}
|
|
850
|
+
return videoSrc;
|
|
851
|
+
},
|
|
852
|
+
|
|
853
|
+
async getSpeakerDeviceList() {
|
|
854
|
+
defaultApi.writeLog('sdk action : getSpeakerDeviceList');
|
|
855
|
+
const devices = await zbztAVSDK.getSpeakerDeviceList();
|
|
856
|
+
defaultApi.writeLog(`sdk action : getSpeakerDeviceList ${JSON.stringify(devices)}`);
|
|
857
|
+
return devices;
|
|
858
|
+
},
|
|
859
|
+
|
|
860
|
+
async setSpeakerDevice(deviceId) {
|
|
861
|
+
defaultApi.writeLog(`sdk action : setSpeakerDevice deviceId:${deviceId}`);
|
|
862
|
+
await zbztAVSDK.setSpeakerDevice(deviceId, 'client');
|
|
863
|
+
},
|
|
864
|
+
|
|
865
|
+
async getSpeakerDevice() {
|
|
866
|
+
defaultApi.writeLog('sdk action : getSpeakerDevice');
|
|
867
|
+
return zbztAVSDK.getSpeakerDevice();
|
|
868
|
+
},
|
|
869
|
+
|
|
870
|
+
async getSpeakerVolume() {
|
|
871
|
+
defaultApi.writeLog('sdk action : getSpeakerVolume ');
|
|
872
|
+
return await zbztAVSDK.getSpeakerVolume();
|
|
873
|
+
},
|
|
874
|
+
|
|
875
|
+
async setSpeakerVolume(volume) {
|
|
876
|
+
await zbztAVSDK.setSpeakerVolume(volume);
|
|
877
|
+
defaultApi.writeLog(`sdk action : setSpeakerVolume ${volume}`);
|
|
878
|
+
|
|
879
|
+
},
|
|
880
|
+
|
|
881
|
+
async setSpeakerMute(mute) {
|
|
882
|
+
await zbztAVSDK.setSpeakerMute(mute);
|
|
883
|
+
try {
|
|
884
|
+
dataReport.deviceChange({
|
|
885
|
+
device_type: 3,
|
|
886
|
+
code: mute ? 0 :1,
|
|
887
|
+
device_name: window.zbztAVSDK_device_checker_init.speaker.name,
|
|
888
|
+
device_id: window.zbztAVSDK_device_checker_init.speaker.use
|
|
889
|
+
});
|
|
890
|
+
} catch (e){};
|
|
891
|
+
defaultApi.writeLog(`sdk action : setSpeakerMute ${mute}`);
|
|
892
|
+
},
|
|
893
|
+
|
|
894
|
+
async openOrCloseCameraAndMicrophone(type) {
|
|
895
|
+
await zbztAVSDK.openOrCloseCameraAndMicrophone(type);
|
|
896
|
+
defaultApi.writeLog(`sdk action : openOrCloseCameraAndMicrophone ${type}`);
|
|
897
|
+
},
|
|
898
|
+
|
|
899
|
+
async getAppVolume() {
|
|
900
|
+
const volume = await zbztAVSDK.getAppVolume();
|
|
901
|
+
defaultApi.writeLog(`sdk action : getAppVolume ${volume}`);
|
|
902
|
+
return volume;
|
|
903
|
+
},
|
|
904
|
+
|
|
905
|
+
async setAppVolume(volume) {
|
|
906
|
+
await zbztAVSDK.setAppVolume(volume);
|
|
907
|
+
defaultApi.writeLog(`sdk action : setAppVolume ${volume}`);
|
|
908
|
+
|
|
909
|
+
},
|
|
910
|
+
|
|
911
|
+
async setAppMute(mute) {
|
|
912
|
+
await zbztAVSDK.setAppMute(mute);
|
|
913
|
+
defaultApi.writeLog(`sdk action : setAppMute ${mute}`);
|
|
914
|
+
},
|
|
915
|
+
|
|
916
|
+
async getMicrophoneDeviceList() {
|
|
917
|
+
defaultApi.writeLog('sdk action : getMicrophoneDeviceList');
|
|
918
|
+
const devices = await zbztAVSDK.getMicrophoneDeviceList();
|
|
919
|
+
defaultApi.writeLog(`sdk action : getMicrophoneDeviceList ${JSON.stringify(devices)}`);
|
|
920
|
+
return devices;
|
|
921
|
+
},
|
|
922
|
+
|
|
923
|
+
async setMicrophoneDevice(deviceId) {
|
|
924
|
+
defaultApi.writeLog(`sdk action : setMicrophoneDevice ${deviceId}`);
|
|
925
|
+
await zbztAVSDK.setMicrophoneDevice(deviceId, 'client');
|
|
926
|
+
},
|
|
927
|
+
|
|
928
|
+
async openOrCloseMicrophone(operation) {
|
|
929
|
+
defaultApi.writeLog(`sdk action : openOrCloseMicrophone ${operation} --start`);
|
|
930
|
+
await zbztAVSDK.openOrCloseMicrophone(operation);
|
|
931
|
+
try {
|
|
932
|
+
dataReport.deviceChange({
|
|
933
|
+
device_type: 2,
|
|
934
|
+
code: operation ? 1 : 0,
|
|
935
|
+
device_name: window.zbztAVSDK_device_checker_init.microphone.name,
|
|
936
|
+
device_id: window.zbztAVSDK_device_checker_init.microphone.use
|
|
937
|
+
});
|
|
938
|
+
} catch (e){};
|
|
939
|
+
userAndDeviceStatusInfo.microPhone = operation;
|
|
940
|
+
//记录麦克风状态,用作推流类型上报,是否推声音
|
|
941
|
+
this.deviceStatus.microphone = operation;
|
|
942
|
+
sdk_status === 1 && sendDeviceStatus('audio', operation);
|
|
943
|
+
defaultApi.writeLog(`sdk action : openOrCloseMicrophone ${operation} --end`);
|
|
944
|
+
|
|
945
|
+
},
|
|
946
|
+
|
|
947
|
+
//听或不听指定用户的声音
|
|
948
|
+
async setAudioMute(userId, mute, groupId, streamid) {
|
|
949
|
+
defaultApi.writeLog(`sdk action : setAudioMute userId ${userId}, mute ${mute}, groupId ${groupId}, streamid ${streamid}`);
|
|
950
|
+
const streamId = streamid || generateStreamId(userId, groupId);
|
|
951
|
+
await zbztAVSDK.setAudioMute(streamId, mute);
|
|
952
|
+
},
|
|
953
|
+
|
|
954
|
+
/**
|
|
955
|
+
* @function 是否拉取音频流--通过播放器id控制
|
|
956
|
+
* @param operation:Boolean,必选,true | false
|
|
957
|
+
* @param playerId:Number,必选,播放器id
|
|
958
|
+
* @return Promise | void
|
|
959
|
+
*/
|
|
960
|
+
async pullAudioFlow(streamid, operation) {
|
|
961
|
+
defaultApi.writeLog(`sdk action : pullAudioFlow --start ${operation}, streamid ${streamid}`);
|
|
962
|
+
await zbztAVSDK.pullAudioFlow(streamid, operation);
|
|
963
|
+
defaultApi.writeLog(`sdk action : pullAudioFlow --end ${operation}, streamid ${streamid}`);
|
|
964
|
+
|
|
965
|
+
},
|
|
966
|
+
|
|
967
|
+
async getMicrophoneVolume() {
|
|
968
|
+
defaultApi.writeLog('sdk action : getMicrophoneVolume');
|
|
969
|
+
return await zbztAVSDK.getMicrophoneVolume();
|
|
970
|
+
},
|
|
971
|
+
|
|
972
|
+
async setMicrophoneVolume(volume, mute) {
|
|
973
|
+
await zbztAVSDK.setMicrophoneVolume(volume, mute);
|
|
974
|
+
defaultApi.writeLog(`sdk action : setMicrophoneVolume ${volume} ${mute}`);
|
|
975
|
+
|
|
976
|
+
},
|
|
977
|
+
|
|
978
|
+
async setMicrophoneMute(mute) {
|
|
979
|
+
await zbztAVSDK.setMicrophoneMute(mute);
|
|
980
|
+
defaultApi.writeLog(`sdk action : setMicrophoneMute ${mute}`);
|
|
981
|
+
},
|
|
982
|
+
|
|
983
|
+
async leaveRoom(type) {
|
|
984
|
+
//未初始化完成,无须卸载
|
|
985
|
+
// if (sdk_status === -1) {
|
|
986
|
+
// zbztsdk.notice({
|
|
987
|
+
// type: 'error',
|
|
988
|
+
// data: {
|
|
989
|
+
// message: 'should not leaveRoom before init finished'
|
|
990
|
+
// }
|
|
991
|
+
// });
|
|
992
|
+
// return;
|
|
993
|
+
// }
|
|
994
|
+
defaultApi.writeLog('sdk action : leaveRoom');
|
|
995
|
+
// if (window.zbzt_sdk_init_params.role === 'student') {
|
|
996
|
+
CHANNEL.sendRemoveStream(window.zbzt_sdk_init_params);
|
|
997
|
+
// }
|
|
998
|
+
CHANNEL.sendLeave(window.zbzt_sdk_init_params);
|
|
999
|
+
CHANNEL.leaveRoom();
|
|
1000
|
+
// 重置设备检测初始化状态
|
|
1001
|
+
await zbztAVSDK.leaveRoom(type);
|
|
1002
|
+
|
|
1003
|
+
windowObjArr[0].concat(windowObjArr[1]).forEach(item => {
|
|
1004
|
+
localStorage.removeItem(item);
|
|
1005
|
+
});
|
|
1006
|
+
|
|
1007
|
+
sdk_status = -1;
|
|
1008
|
+
try {
|
|
1009
|
+
dataReport.leaveRoom();
|
|
1010
|
+
} catch (e) {};
|
|
1011
|
+
defaultApi.writeLog('sdk leaveRoom end ,sdk status : uninstall_finished');
|
|
1012
|
+
//通知业务层,卸载完成
|
|
1013
|
+
NOTICE.sdkStatus({
|
|
1014
|
+
sdk_type: window.zbztAVSDK_init_sdk_type,
|
|
1015
|
+
status: 'uninstall_finished'
|
|
1016
|
+
});
|
|
1017
|
+
window.zbztAVSDK_device_checker_init = null;
|
|
1018
|
+
},
|
|
1019
|
+
|
|
1020
|
+
//崩溃后的销毁引擎,反初始化
|
|
1021
|
+
async deinit() {
|
|
1022
|
+
defaultApi.writeLog('sdk action : deinit');
|
|
1023
|
+
await zbztAVSDK.deinit();
|
|
1024
|
+
},
|
|
1025
|
+
|
|
1026
|
+
/**
|
|
1027
|
+
* @function 转推,录课
|
|
1028
|
+
* @param type:String 动作类型,必选,'start' | 'stop' | 'pause' | 'resume'
|
|
1029
|
+
* @return Promise | void
|
|
1030
|
+
*/
|
|
1031
|
+
async turnPush(cmd) {
|
|
1032
|
+
await zbztAVSDK.turnPush(cmd);
|
|
1033
|
+
defaultApi.writeLog(`sdk action : turnPush ${cmd}`);
|
|
1034
|
+
},
|
|
1035
|
+
|
|
1036
|
+
openMicVolumeCb(open) {
|
|
1037
|
+
zbztAVSDK.openMicVolumeCb(open);
|
|
1038
|
+
defaultApi.writeLog(`sdk action : openMicVolumeCb ${open}`);
|
|
1039
|
+
},
|
|
1040
|
+
// 开始混流--已废弃
|
|
1041
|
+
startMixtStream(args) {
|
|
1042
|
+
zbztAVSDK.startMixtStream(args);
|
|
1043
|
+
defaultApi.writeLog(`sdk action : startMixtStream, args: ${JSON.stringify(args)}`);
|
|
1044
|
+
},
|
|
1045
|
+
// 结束混流--已废弃
|
|
1046
|
+
stopMixtStream(args) {
|
|
1047
|
+
zbztAVSDK.stopMixtStream(args);
|
|
1048
|
+
defaultApi.writeLog(`sdk action : stopMixtStream, args: ${JSON.stringify(args)}`);
|
|
1049
|
+
},
|
|
1050
|
+
|
|
1051
|
+
mixedstuVideo(stuArray) {
|
|
1052
|
+
zbztAVSDK.mixedstuVideo(stuArray);
|
|
1053
|
+
defaultApi.writeLog(`sdk action : mixedstuVideo, stuArray: ${stuArray}`);
|
|
1054
|
+
},
|
|
1055
|
+
|
|
1056
|
+
/**
|
|
1057
|
+
* @function 单路流录制
|
|
1058
|
+
* @param args:Object
|
|
1059
|
+
* {
|
|
1060
|
+
* type: String,必选,'start' | 'stop'
|
|
1061
|
+
* groupId: String, 可选,分组id
|
|
1062
|
+
* userId: String, 可选,用户id
|
|
1063
|
+
* }
|
|
1064
|
+
*/
|
|
1065
|
+
singleRecord(args) {
|
|
1066
|
+
args.streamId = this.getStreamInfo(args.userId, args.groupId).streamId;
|
|
1067
|
+
zbztAVSDK.singleRecord(args);
|
|
1068
|
+
defaultApi.writeLog(`sdk action : singleRecord, args: ${JSON.stringify(args)}`);
|
|
1069
|
+
},
|
|
1070
|
+
//开启拉流音量监听
|
|
1071
|
+
startSoundLevelMonitor() {
|
|
1072
|
+
defaultApi.writeLog('sdk action : startSoundLevelMonitor --start');
|
|
1073
|
+
zbztAVSDK.startSoundLevelMonitor();
|
|
1074
|
+
defaultApi.writeLog('sdk action : startSoundLevelMonitor --end');
|
|
1075
|
+
},
|
|
1076
|
+
/**
|
|
1077
|
+
* @function 多路转推
|
|
1078
|
+
* @param args:Object
|
|
1079
|
+
* {
|
|
1080
|
+
* type: String,必选,'start' | 'stop'
|
|
1081
|
+
* groupId: String, 可选,分组id
|
|
1082
|
+
* userId: String, 可选,用户id
|
|
1083
|
+
* }
|
|
1084
|
+
*/
|
|
1085
|
+
async recordPublish(args) {
|
|
1086
|
+
args.streamId = this.getStreamInfo(args.userId, args.groupId).streamId;
|
|
1087
|
+
zbztAVSDK.recordPublishTarget(args);
|
|
1088
|
+
defaultApi.writeLog(`sdk action : recordPublish, args: ${JSON.stringify(args)}`);
|
|
1089
|
+
},
|
|
1090
|
+
|
|
1091
|
+
/**
|
|
1092
|
+
* @function 获取视频快照截图所需的 id 数据
|
|
1093
|
+
* @param userId:String 用户 ID
|
|
1094
|
+
* @param roomId:String 房间 ID
|
|
1095
|
+
*/
|
|
1096
|
+
getStreamInfo(userId, roomId) {
|
|
1097
|
+
const streamId = generateStreamId(userId, roomId);
|
|
1098
|
+
defaultApi.writeLog(`sdk action :getStreamInfo --start, userId : ${userId}, roomId: ${roomId}`);
|
|
1099
|
+
if (!userId || userId == window.zbzt_sdk_init_params.userId) {
|
|
1100
|
+
switch (window.current_sdk_type) {
|
|
1101
|
+
case 'rtc':
|
|
1102
|
+
try{
|
|
1103
|
+
dataReport.takeSnapShot({snapshootId:streamId});
|
|
1104
|
+
}catch(e){}
|
|
1105
|
+
return {
|
|
1106
|
+
streamId,
|
|
1107
|
+
snapshootId: streamId
|
|
1108
|
+
};
|
|
1109
|
+
break;
|
|
1110
|
+
case 'zego':
|
|
1111
|
+
try{
|
|
1112
|
+
dataReport.takeSnapShot({getStreamInfoZego:streamId,snapshootId:-1});
|
|
1113
|
+
}catch(e){}
|
|
1114
|
+
return {
|
|
1115
|
+
streamId,
|
|
1116
|
+
snapshootId: -1
|
|
1117
|
+
};
|
|
1118
|
+
break;
|
|
1119
|
+
case 'nertc':
|
|
1120
|
+
case 'volcrtc':
|
|
1121
|
+
case 'talrtc':
|
|
1122
|
+
try {
|
|
1123
|
+
dataReport.takeSnapShot({snapshootId:streamId});
|
|
1124
|
+
} catch (e) {}
|
|
1125
|
+
return {
|
|
1126
|
+
streamId,
|
|
1127
|
+
snapshootId: -2
|
|
1128
|
+
};
|
|
1129
|
+
case 'trtc':
|
|
1130
|
+
try {
|
|
1131
|
+
dataReport.takeSnapShot({snapshootId:streamId});
|
|
1132
|
+
} catch (e) {}
|
|
1133
|
+
return {
|
|
1134
|
+
streamId,
|
|
1135
|
+
snapshootId: -3
|
|
1136
|
+
};
|
|
1137
|
+
default:
|
|
1138
|
+
break;
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
let snapshootId = zbztAVSDK.getSnapshootId(streamId);
|
|
1142
|
+
defaultApi.writeLog(`sdk action :getStreamInfo, userId : ${userId}, snapshootId: ${snapshootId}`);
|
|
1143
|
+
return {
|
|
1144
|
+
streamId,
|
|
1145
|
+
snapshootId
|
|
1146
|
+
};
|
|
1147
|
+
},
|
|
1148
|
+
|
|
1149
|
+
getAllChannelIndex() {
|
|
1150
|
+
let channelMap = zbztAVSDK.getAllChannelIndex();
|
|
1151
|
+
return channelMap;
|
|
1152
|
+
},
|
|
1153
|
+
|
|
1154
|
+
/**
|
|
1155
|
+
* @function 记录日志
|
|
1156
|
+
* @param productName:String 产品名称,必选
|
|
1157
|
+
* @param type:String 日志类型,可选,default : 'info', 'debug' | 'info' | 'warnning' | 'error' | 'critical',
|
|
1158
|
+
* @param content:String | Object 日志记录主要内容
|
|
1159
|
+
*/
|
|
1160
|
+
log(productName, content, type = 'info') {
|
|
1161
|
+
if (!productName) {
|
|
1162
|
+
defaultApi.writeLog('sdk action :log methods invoked error, no productName');
|
|
1163
|
+
return;
|
|
1164
|
+
}
|
|
1165
|
+
defaultApi.writeLog(content, productName, type);
|
|
1166
|
+
},
|
|
1167
|
+
/**
|
|
1168
|
+
* @function 设置摄像头参数
|
|
1169
|
+
* @param width:Number 分辨率宽,必选,推荐 1280
|
|
1170
|
+
* @param height:Number 分辨率高,必选,推荐 720
|
|
1171
|
+
* @param frameRate:Number 帧率,必选,推荐 15
|
|
1172
|
+
* @return Promise | void
|
|
1173
|
+
*/
|
|
1174
|
+
setCameraParams(args) {
|
|
1175
|
+
defaultApi.writeLog(`sdk action: setCameraParam, args: ${JSON.stringify(args)}`);
|
|
1176
|
+
return zbztAVSDK.setCameraParams(args);
|
|
1177
|
+
},
|
|
1178
|
+
|
|
1179
|
+
setEncodeParams(args) {
|
|
1180
|
+
defaultApi.writeLog(`sdk action: setEncodeParams, args: ${JSON.stringify(args)}`);
|
|
1181
|
+
return zbztAVSDK.setEncodeParams(args);
|
|
1182
|
+
},
|
|
1183
|
+
|
|
1184
|
+
setBitRate(bitrate) {
|
|
1185
|
+
defaultApi.writeLog(`sdk action: setBitRate, bitrate: ${bitrate}`);
|
|
1186
|
+
return zbztAVSDK.setBitRate(bitrate);
|
|
1187
|
+
},
|
|
1188
|
+
|
|
1189
|
+
/**
|
|
1190
|
+
* @function 本地视频录制
|
|
1191
|
+
* @param type 开始/结束
|
|
1192
|
+
* @param path 录制路径
|
|
1193
|
+
* @return Promise | void
|
|
1194
|
+
*/
|
|
1195
|
+
localRecordVideo(type, path) {
|
|
1196
|
+
defaultApi.writeLog(`sdk action: localRecordVideo, type: ${type}, path ${path}`);
|
|
1197
|
+
return zbztAVSDK.localRecordVideo(type, path);
|
|
1198
|
+
},
|
|
1199
|
+
/**
|
|
1200
|
+
* @function 本地音频录制
|
|
1201
|
+
* @param type 开始/结束
|
|
1202
|
+
* @param path 录制路径
|
|
1203
|
+
* @return Promise | void
|
|
1204
|
+
*/
|
|
1205
|
+
localRecordAudio(type, path) {
|
|
1206
|
+
defaultApi.writeLog(`sdk action: localRecordAudio, type: ${type}, path ${path}`);
|
|
1207
|
+
return zbztAVSDK.localRecordAudio(type, path);
|
|
1208
|
+
},
|
|
1209
|
+
/**
|
|
1210
|
+
* @function 开始连麦
|
|
1211
|
+
* @param mode:number 采集器默认, 默认0=站立 1=坐立
|
|
1212
|
+
* @return Promise | void
|
|
1213
|
+
*/
|
|
1214
|
+
async teacherStartLinkMic(mode) {
|
|
1215
|
+
defaultApi.writeLog(`sdk action: teacherStartLinkMic, mode: ${mode}`);
|
|
1216
|
+
try {
|
|
1217
|
+
dataReport.avConnect({
|
|
1218
|
+
sdk_type: window.zbztAVSDK_init_sdk_type,
|
|
1219
|
+
type: 1,
|
|
1220
|
+
mode
|
|
1221
|
+
});
|
|
1222
|
+
} catch (e) {};
|
|
1223
|
+
await zbztAVSDK.teacherStartLinkMic(mode);
|
|
1224
|
+
// if (mode === 0) {
|
|
1225
|
+
// await zbztAVSDK.startPreview();
|
|
1226
|
+
// }
|
|
1227
|
+
return this.startPushFlow();
|
|
1228
|
+
},
|
|
1229
|
+
/**
|
|
1230
|
+
* @function 结束连麦
|
|
1231
|
+
* @param mode:number 采集器默认, 默认0=站立 1=坐立
|
|
1232
|
+
* @return Promise | void
|
|
1233
|
+
*/
|
|
1234
|
+
async teacherStopLinkMic(mode) {
|
|
1235
|
+
defaultApi.writeLog(`sdk action: teacherStopLinkMic, mode: ${mode}`);
|
|
1236
|
+
try {
|
|
1237
|
+
dataReport.avConnect({
|
|
1238
|
+
sdk_type: window.zbztAVSDK_init_sdk_type,
|
|
1239
|
+
type: 0,
|
|
1240
|
+
mode
|
|
1241
|
+
});
|
|
1242
|
+
} catch (e) {};
|
|
1243
|
+
await zbztAVSDK.teacherStopLinkMic(mode);
|
|
1244
|
+
if (mode === 0) {
|
|
1245
|
+
await zbztAVSDK.stopPreview();
|
|
1246
|
+
}
|
|
1247
|
+
return this.stopPushFlow();
|
|
1248
|
+
},
|
|
1249
|
+
getSdkStatus() {
|
|
1250
|
+
return sdk_status;
|
|
1251
|
+
},
|
|
1252
|
+
// 获取截屏窗位置
|
|
1253
|
+
//设置采集扬声器声音
|
|
1254
|
+
setSpeakerCapture(deviceId, speaker){
|
|
1255
|
+
defaultApi.writeLog(`sdk action: setSpeakerCapture, deviceId: ${deviceId}, speaker: ${speaker}`);
|
|
1256
|
+
return zbztAVSDK.setSpeakerCapture(deviceId, speaker);
|
|
1257
|
+
},
|
|
1258
|
+
/**
|
|
1259
|
+
* @function 设置混流和背景色
|
|
1260
|
+
* @param { number } type 0=不拼接/1=截屏窗+背景图/2=截屏窗+背景图+头像
|
|
1261
|
+
* @param { number } id 需要混合的采集器id
|
|
1262
|
+
* @param { object } rgb
|
|
1263
|
+
* @param { number } rgb.r
|
|
1264
|
+
* @param { number } rgb.g
|
|
1265
|
+
* @param { number } rgb.b
|
|
1266
|
+
* @return: Promise
|
|
1267
|
+
*/
|
|
1268
|
+
setMixStream(type, id, rgb) {
|
|
1269
|
+
defaultApi.writeLog(`sdk action: setMixStream, type: ${type}, id: ${id}, rgb: ${JSON.stringify(rgb)}`);
|
|
1270
|
+
return zbztAVSDK.setMixStream(type, id, rgb);
|
|
1271
|
+
},
|
|
1272
|
+
/**
|
|
1273
|
+
* @function 采集器截图
|
|
1274
|
+
* @param { string } fileName 文件名,需要后缀名。例如:333.jpg
|
|
1275
|
+
* @return: Promise
|
|
1276
|
+
*/
|
|
1277
|
+
captureSnapShot(fileName) {
|
|
1278
|
+
defaultApi.writeLog(`sdk action: captureSnapShot, fileName: ${fileName}`);
|
|
1279
|
+
return zbztAVSDK.captureSnapShot(fileName);
|
|
1280
|
+
},
|
|
1281
|
+
/**
|
|
1282
|
+
* @function 播放器截图
|
|
1283
|
+
* @param { string } streamId 播放器id
|
|
1284
|
+
* @param { string } fileName 文件名,需要后缀名。例如:333.jpg
|
|
1285
|
+
* @return { Promise<ImageData> }
|
|
1286
|
+
*/
|
|
1287
|
+
playerSnapShot(streamId, fileName) {
|
|
1288
|
+
defaultApi.writeLog(`sdk action: playerSnapShot, id: ${streamId} fileName: ${fileName}`);
|
|
1289
|
+
return zbztAVSDK.playerSnapShot(streamId, fileName);
|
|
1290
|
+
},
|
|
1291
|
+
|
|
1292
|
+
/**
|
|
1293
|
+
* @function 设置预览镜像状态
|
|
1294
|
+
* @param { boolean } type true=开启 false=关闭
|
|
1295
|
+
* @return: Promise
|
|
1296
|
+
*/
|
|
1297
|
+
setMirrorStatus(type) {
|
|
1298
|
+
defaultApi.writeLog(`sdk action: setMirrorStatus, type: ${type}`);
|
|
1299
|
+
if (type !== undefined && type !== null) {
|
|
1300
|
+
mirrorStatus = type;
|
|
1301
|
+
}
|
|
1302
|
+
return zbztAVSDK.setMirrorStatus(type);
|
|
1303
|
+
},
|
|
1304
|
+
/**
|
|
1305
|
+
* @function 设置拉流镜像状态
|
|
1306
|
+
* @param { boolean } type true=开启 false=关闭
|
|
1307
|
+
* @return: Promise
|
|
1308
|
+
*/
|
|
1309
|
+
setPlayViewMirror(type, id) {
|
|
1310
|
+
defaultApi.writeLog(`sdk action: setPlayViewMirror, type: ${type}, id: ${id}`);
|
|
1311
|
+
return zbztAVSDK.setPlayViewMirror(type, id);
|
|
1312
|
+
},
|
|
1313
|
+
|
|
1314
|
+
/**
|
|
1315
|
+
* @function 设置推流镜像状态
|
|
1316
|
+
* @param { boolean } id 采集器Id
|
|
1317
|
+
* @param { boolean } mode 1=开启 0=关闭
|
|
1318
|
+
* @return: Promise
|
|
1319
|
+
*/
|
|
1320
|
+
setPushViewMirror(mode) {
|
|
1321
|
+
defaultApi.writeLog(`sdk action: setPushViewMirror, mode: ${mode}`);
|
|
1322
|
+
if (mode !== undefined && mode !== null) {
|
|
1323
|
+
mirrorStatus = mode;
|
|
1324
|
+
}
|
|
1325
|
+
return zbztAVSDK.setPushViewMirror(mode);
|
|
1326
|
+
},
|
|
1327
|
+
|
|
1328
|
+
/**
|
|
1329
|
+
* @function 开启美颜
|
|
1330
|
+
* @return: Promise
|
|
1331
|
+
*/
|
|
1332
|
+
startSenseMe() {
|
|
1333
|
+
defaultApi.writeLog('sdk action: startSenseMe');
|
|
1334
|
+
return zbztAVSDK.startSenseMe();
|
|
1335
|
+
},
|
|
1336
|
+
/**
|
|
1337
|
+
* @function 设置美颜参数
|
|
1338
|
+
* * @param { number } type //美颜类型,1、红润强度,3、磨皮强度,4、美白强度,5、大眼,6、瘦脸,7、小脸,8、对比度强度,9、饱和度强度
|
|
1339
|
+
* * @param { number } value //美颜数值,有效值范围0~100
|
|
1340
|
+
* @return: Promise
|
|
1341
|
+
*/
|
|
1342
|
+
setBeautifyParam(type, value) {
|
|
1343
|
+
defaultApi.writeLog(`sdk action: setBeautifyParam, type: ${type},value: ${value}`);
|
|
1344
|
+
return zbztAVSDK.setBeautifyParam(type, value);
|
|
1345
|
+
},
|
|
1346
|
+
/**
|
|
1347
|
+
* @function 关闭美颜
|
|
1348
|
+
* @return: Promise
|
|
1349
|
+
*/
|
|
1350
|
+
endSenseMe() {
|
|
1351
|
+
defaultApi.writeLog('sdk action: endSenseMe');
|
|
1352
|
+
return zbztAVSDK.endSenseMe();
|
|
1353
|
+
},
|
|
1354
|
+
|
|
1355
|
+
/**
|
|
1356
|
+
* @function zego40路拉流混音接口
|
|
1357
|
+
* @param { number } mixMode //混流模式 0=关闭混流 1=开启混流
|
|
1358
|
+
* @param { array } userIdArr //要突出声音的userId的数组集合
|
|
1359
|
+
* @return: Promise
|
|
1360
|
+
*/
|
|
1361
|
+
setAudioMixMode(mixMode, userIdArr) {
|
|
1362
|
+
let streamIdArr = [];
|
|
1363
|
+
if(userIdArr.length > 0) {
|
|
1364
|
+
userIdArr.forEach(item => {
|
|
1365
|
+
streamIdArr.push(generateStreamId(item));
|
|
1366
|
+
});
|
|
1367
|
+
}
|
|
1368
|
+
defaultApi.writeLog(`sdk action: setAudioMixMode mixMode:${mixMode} userIdArr:${userIdArr} streamIdArr:${streamIdArr}`);
|
|
1369
|
+
return zbztAVSDK.setAudioMixMode(mixMode, streamIdArr);
|
|
1370
|
+
},
|
|
1371
|
+
|
|
1372
|
+
//获取TalMedia.dll版本号&&获取zegoAvkit.dll版本号
|
|
1373
|
+
getSDKVersion() {
|
|
1374
|
+
defaultApi.writeLog('sdk action: getSDKVersion');
|
|
1375
|
+
return zbztAVSDK.getSDKVersion();
|
|
1376
|
+
},
|
|
1377
|
+
|
|
1378
|
+
//获取摄像头所支持的分辨率
|
|
1379
|
+
getCameraSupportedResolution(deviceId) {
|
|
1380
|
+
defaultApi.writeLog(`sdk action: getCameraSupportedResolution deviceId: ${deviceId}`);
|
|
1381
|
+
return zbztAVSDK.getCameraSupportedResolution(deviceId);
|
|
1382
|
+
},
|
|
1383
|
+
//开启rtc同屏
|
|
1384
|
+
startMultiScreen() {
|
|
1385
|
+
defaultApi.writeLog('sdk action: startMultiScreen');
|
|
1386
|
+
return zbztAVSDK.startMultiScreen();
|
|
1387
|
+
},
|
|
1388
|
+
//开启高光时刻
|
|
1389
|
+
startHighlight(enable) {
|
|
1390
|
+
defaultApi.writeLog(`sdk action: startHighlight enable:${enable}`);
|
|
1391
|
+
return zbztAVSDK.enableHighlight(enable);
|
|
1392
|
+
},
|
|
1393
|
+
//开启外部音频采集
|
|
1394
|
+
startAudioExCapture() {
|
|
1395
|
+
defaultApi.writeLog('sdk action: startAudioExCapture');
|
|
1396
|
+
return zbztAVSDK.startAudioExCapture();
|
|
1397
|
+
},
|
|
1398
|
+
|
|
1399
|
+
//RTC同屏 辅助通道音频类型
|
|
1400
|
+
setAUXAudioType(type) {
|
|
1401
|
+
defaultApi.writeLog('sdk action: setAUXAudioType');
|
|
1402
|
+
return zbztAVSDK.setAUXAudioType(type);
|
|
1403
|
+
},
|
|
1404
|
+
|
|
1405
|
+
//RTC同屏 录制通道音频类型
|
|
1406
|
+
setThirdAudioType(type) {
|
|
1407
|
+
defaultApi.writeLog('sdk action: setThirdAudioType');
|
|
1408
|
+
return zbztAVSDK.setThirdAudioType(type);
|
|
1409
|
+
},
|
|
1410
|
+
|
|
1411
|
+
|
|
1412
|
+
//发送sei
|
|
1413
|
+
sendMediaSideInfo(info) {
|
|
1414
|
+
defaultApi.writeLog('sdk action: sendMediaSideInfo');
|
|
1415
|
+
return zbztAVSDK.sendMediaSideInfo(info);
|
|
1416
|
+
},
|
|
1417
|
+
|
|
1418
|
+
/**
|
|
1419
|
+
* @function 开始录制
|
|
1420
|
+
* @param {number} 录制文件类型 可选,默认mp4
|
|
1421
|
+
* @param {number} 录制文件名称 可选
|
|
1422
|
+
* @returns {Promise<any>}
|
|
1423
|
+
*/
|
|
1424
|
+
async startCaptureRecord(fileType = 2, fileName, idx = 2) {
|
|
1425
|
+
defaultApi.writeLog(`sdk action: startCaptureRecord fileType:${fileType} fileName:${fileName} idx:${idx}`);
|
|
1426
|
+
// 格式化fileType
|
|
1427
|
+
fileType = Number(fileType);
|
|
1428
|
+
if(fileType !== 1 && fileType !== 2){
|
|
1429
|
+
fileType = 2;
|
|
1430
|
+
}
|
|
1431
|
+
// 格式化idx
|
|
1432
|
+
if (idx !==0 && idx !== 1 && idx !== 2) {
|
|
1433
|
+
idx = 2;
|
|
1434
|
+
}
|
|
1435
|
+
const result = await zbztAVSDK.startRecord(fileName, fileType, idx);
|
|
1436
|
+
await zbztAVSDK.startCapture(idx);
|
|
1437
|
+
return result;
|
|
1438
|
+
},
|
|
1439
|
+
/**
|
|
1440
|
+
* @function 结束录制
|
|
1441
|
+
* @param {number} 录制推流通道 idx 必选
|
|
1442
|
+
* @return: Promise
|
|
1443
|
+
*/
|
|
1444
|
+
async stopCaptureRecord(idx = 2) {
|
|
1445
|
+
await zbztAVSDK.stopRecord(idx);
|
|
1446
|
+
return zbztAVSDK.stopCapture(idx);
|
|
1447
|
+
},
|
|
1448
|
+
/**
|
|
1449
|
+
* @function 切换sdk类型
|
|
1450
|
+
* @return: Promise
|
|
1451
|
+
*/
|
|
1452
|
+
// async changeSdkType(institutionId, sdkName, roomId) {
|
|
1453
|
+
// defaultApi.writeLog(`sdk action: changeSdkType, institutionId: ${institutionId}, sdkName: ${sdkName}, roomId: ${roomId}`);
|
|
1454
|
+
// let code;
|
|
1455
|
+
// let param = {
|
|
1456
|
+
// institutionId,
|
|
1457
|
+
// sdkName,
|
|
1458
|
+
// roomId,
|
|
1459
|
+
// workCode:0
|
|
1460
|
+
// };
|
|
1461
|
+
// let res = await changeSdkInRoom(param);
|
|
1462
|
+
// defaultApi.writeLog(`sdk action: changeSdkType, sdk切换${res.code == 0 ? '成功' : '失败'}, ${JSON.stringify(res)}`);
|
|
1463
|
+
// code = res.code == 0 ? 0 : 1; //0切换成功 ,1切换失败
|
|
1464
|
+
// return code ;
|
|
1465
|
+
// },
|
|
1466
|
+
async changeSdkType(institutionId, sdkName, teacherId, liveId) {
|
|
1467
|
+
defaultApi.writeLog(`sdk action: changeSdkType, institutionId: ${institutionId}, sdkName: ${sdkName}, teacherId: ${teacherId}, liveId: ${liveId}`);
|
|
1468
|
+
let code;
|
|
1469
|
+
let param = {
|
|
1470
|
+
institutionId,
|
|
1471
|
+
sdkName,
|
|
1472
|
+
lectureStreamId:`lecturer_${teacherId}_${liveId}`,
|
|
1473
|
+
workCode:0
|
|
1474
|
+
};
|
|
1475
|
+
let res = await changeSdkInRoom(param);
|
|
1476
|
+
defaultApi.writeLog(`sdk action: changeSdkType, sdk切换${res.code == 0 ? '成功' : '失败'}, ${JSON.stringify(res)}`);
|
|
1477
|
+
code = res.code == 0 ? 0 : 1; //0切换成功 ,1切换失败
|
|
1478
|
+
return code ;
|
|
1479
|
+
},
|
|
1480
|
+
};
|
|
1481
|
+
|
|
1482
|
+
window.zbztsdk = zbztsdk;
|
|
1483
|
+
|
|
1484
|
+
export default zbztsdk;
|