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.
Files changed (80) hide show
  1. package/.babelrc +8 -0
  2. package/.editorconfig +13 -0
  3. package/.eslintrc.js +29 -0
  4. package/CHANGELOG.md +16 -0
  5. package/README.md +32 -0
  6. package/dist/zbzt-live-sdk.cjs.js +51 -0
  7. package/dist/zbzt-live-sdk.esm.js +51 -0
  8. package/dist/zbzt-live-sdk.umd.js +52 -0
  9. package/dist/zbzt-live-sdk.umd.js.map +1 -0
  10. package/example/app.js +133 -0
  11. package/example/bootstrap-3.4.1/css/bootstrap-theme.css +587 -0
  12. package/example/bootstrap-3.4.1/css/bootstrap-theme.css.map +1 -0
  13. package/example/bootstrap-3.4.1/css/bootstrap-theme.min.css +6 -0
  14. package/example/bootstrap-3.4.1/css/bootstrap-theme.min.css.map +1 -0
  15. package/example/bootstrap-3.4.1/css/bootstrap.css +6834 -0
  16. package/example/bootstrap-3.4.1/css/bootstrap.css.map +1 -0
  17. package/example/bootstrap-3.4.1/css/bootstrap.min.css +6 -0
  18. package/example/bootstrap-3.4.1/css/bootstrap.min.css.map +1 -0
  19. package/example/bootstrap-3.4.1/fonts/glyphicons-halflings-regular.eot +0 -0
  20. package/example/bootstrap-3.4.1/fonts/glyphicons-halflings-regular.svg +288 -0
  21. package/example/bootstrap-3.4.1/fonts/glyphicons-halflings-regular.ttf +0 -0
  22. package/example/bootstrap-3.4.1/fonts/glyphicons-halflings-regular.woff +0 -0
  23. package/example/bootstrap-3.4.1/fonts/glyphicons-halflings-regular.woff2 +0 -0
  24. package/example/bootstrap-3.4.1/js/bootstrap.js +2580 -0
  25. package/example/bootstrap-3.4.1/js/bootstrap.min.js +6 -0
  26. package/example/bootstrap-3.4.1/js/npm.js +13 -0
  27. package/example/css/style.css +18 -0
  28. package/example/index.html +59 -0
  29. package/example/js/jquery-3.7.1.min.js +2 -0
  30. package/example/js/utils.js +25 -0
  31. package/example/js/variables.js +14 -0
  32. package/example/js/zegoApi.js +229 -0
  33. package/example/style.css +25 -0
  34. package/example/test.html +100 -0
  35. package/package.json +60 -0
  36. package/release.js +33 -0
  37. package/rollup-plugin-http.js +49 -0
  38. package/src/channel/getSendMsgParams.js +66 -0
  39. package/src/channel/index.js +135 -0
  40. package/src/channel/pomelo/index.js +182 -0
  41. package/src/channel/pomelo/latestQueue.js +150 -0
  42. package/src/channel/pomelo/polemo.js +730 -0
  43. package/src/channel/pomelo/util.js +54 -0
  44. package/src/channel/sdk-cb.js +73 -0
  45. package/src/channel/stream-msg.js +97 -0
  46. package/src/channel/zbzt/index.js +74 -0
  47. package/src/channel/zbzt/interactWithChannel.js +4 -0
  48. package/src/channel/zbzt/interactWithChannelControl.js +1568 -0
  49. package/src/channel/zbzt/interactWithChannelEntry.js +318 -0
  50. package/src/config/config.js +226 -0
  51. package/src/default/base.js +71 -0
  52. package/src/default/extend.js +36 -0
  53. package/src/default/index.js +10 -0
  54. package/src/live/base.js +43 -0
  55. package/src/live/call-method.js +10 -0
  56. package/src/live/extend.js +53 -0
  57. package/src/live/index.js +10 -0
  58. package/src/network/api.js +56 -0
  59. package/src/network/commonFetch.js +66 -0
  60. package/src/network/dataReport.js +448 -0
  61. package/src/notice.js +418 -0
  62. package/src/tool/base.js +74 -0
  63. package/src/tool/call-method.js +10 -0
  64. package/src/tool/extend.js +42 -0
  65. package/src/tool/index.js +10 -0
  66. package/src/util/bridge.js +87 -0
  67. package/src/util/bridge1.js +46 -0
  68. package/src/util/dict.js +51 -0
  69. package/src/util/sessionStorage.js +29 -0
  70. package/src/util/sha256.js +483 -0
  71. package/src/util/util.js +329 -0
  72. package/src/zbzt-av-sdk/default-sdk.js +192 -0
  73. package/src/zbzt-av-sdk/device.js +86 -0
  74. package/src/zbzt-av-sdk/rtc-sdk.js +2854 -0
  75. package/src/zbzt-av-sdk/talrtc-sdk.js +2620 -0
  76. package/src/zbzt-av-sdk/trtc-sdk.js +1802 -0
  77. package/src/zbzt-av-sdk/zbzt-av-sdk.js +2121 -0
  78. package/src/zbzt-av-sdk/zego-sdk.js +1718 -0
  79. package/src/zbzt-av-sdk/zego-sdk.js.bak +3133 -0
  80. package/src/zbzt-live-sdk.js +1484 -0
package/src/notice.js ADDED
@@ -0,0 +1,418 @@
1
+ /*
2
+ * @Author: why
3
+ * @Date: 2020-07-23 21:02:08
4
+ * @LastEditors: Please set LastEditors
5
+ * @LastEditTime: 2021-06-02 19:05:07
6
+ * @Description:
7
+ */
8
+ import defaultApi from './default/extend';
9
+
10
+ const noWriteLogNoticeNames = ['playerVolumeChanged', 'volume_change', 'real_time_mic_volume', 'pull_quality', 'push_quality', 'push_loss_delay', 'play_loss_delay'];
11
+ /**
12
+ * @function
13
+ */
14
+ let emit;
15
+
16
+ function setEmitter(emitter) {
17
+ emit = emitter.emit;
18
+ }
19
+ function notice(data) {
20
+ try {
21
+ emit(data);
22
+ if (!noWriteLogNoticeNames.includes(data.type)) {
23
+ defaultApi.writeLog(`NOTICE--${JSON.stringify(data)}`);
24
+ }
25
+ } catch (error) {
26
+ console.error('zbzt-live-sdk callback error', data, error);
27
+ }
28
+ }
29
+
30
+ export default {
31
+ noWriteLogNoticeNames,
32
+ setEmitter,
33
+ // sdk状态相关
34
+ // 初始化前
35
+ sdkStatus(data) {
36
+ notice({
37
+ type: 'sdk_status',
38
+ data
39
+ });
40
+ },
41
+ // 切换sdk完成后返回本地预览地址
42
+ updateLocalPreview(data) {
43
+ notice({
44
+ type: 'update_local_preview',
45
+ data
46
+ });
47
+ },
48
+ // 设备热插拔
49
+ hotPlug(data) {
50
+ notice({
51
+ type: 'plug_and_unplug',
52
+ data
53
+ });
54
+ },
55
+ // 设备检测出现问题
56
+ deviceError(data) {
57
+ notice({
58
+ type: 'device_error',
59
+ data
60
+ });
61
+ },
62
+ noDevice(data) {
63
+ notice({
64
+ type: 'no_device',
65
+ data
66
+ });
67
+ },
68
+ useredCamera(data) {
69
+ notice({
70
+ type: 'usered_camera',
71
+ data
72
+ });
73
+ },
74
+ // 播放器音量变化
75
+ playerVolumeChanged(data) {
76
+ notice({
77
+ type: 'playerVolumeChanged',
78
+ data
79
+ });
80
+ },
81
+ // 同playerVolumeChanged
82
+ volumeChange(data) {
83
+ notice({
84
+ type: 'volume_change',
85
+ data
86
+ });
87
+ },
88
+ // 采集器麦克风音量变化
89
+ captureMicVolumeChanged(data) {
90
+ notice({
91
+ type: 'real_time_mic_volume',
92
+ data
93
+ });
94
+ },
95
+ // 扬声器音量变化(设备检测)
96
+ speakerVolumeChanged(data) {
97
+ notice({
98
+ type: 'real_time_speaker_volume',
99
+ data
100
+ });
101
+ },
102
+ // sdk状态变化
103
+ sdkStatus(data) {
104
+ notice({
105
+ type: 'sdk_status',
106
+ data
107
+ });
108
+ },
109
+ // 用户指定扬声器
110
+ speakerChanged(data) {
111
+ notice({
112
+ type: 'speaker_changed',
113
+ data
114
+ });
115
+ },
116
+ // -------------信道消息---------
117
+ // 用户加入房间
118
+ userJoin(data) {
119
+ notice({
120
+ type: 'user_join',
121
+ data
122
+ });
123
+ },
124
+ // 设备状态改变
125
+ deviceStatus(data) {
126
+ notice({
127
+ type: 'device_status',
128
+ data
129
+ });
130
+ },
131
+ // 用户推流
132
+ remoteVideoReady(data) {
133
+ notice({
134
+ type: 'remote_video_ready',
135
+ data
136
+ });
137
+ },
138
+ // 用户停止推流
139
+ remoteVideoRemoved(data) {
140
+ notice({
141
+ type: 'remote_video_removed',
142
+ data
143
+ });
144
+ },
145
+ // 用户推流
146
+ addStream(data) {
147
+ notice({
148
+ type: 'addStream',
149
+ data
150
+ });
151
+ },
152
+ // 用户停止推流
153
+ removeStream(data) {
154
+ notice({
155
+ type: 'removeStream',
156
+ data
157
+ });
158
+ },
159
+ // 表示当前已经有用户在房间,对当前新进入房间用户的进行作出一次响应
160
+ userResponse(data) {
161
+ notice({
162
+ type: 'userResponse',
163
+ data
164
+ });
165
+ },
166
+ // 信道断开
167
+ channelDisconnect() {
168
+ notice({
169
+ type:'channel_disconnect',
170
+ data: {
171
+ message: 'Channel disconnect'
172
+ }
173
+ });
174
+ },
175
+ // 信道重连
176
+ channelReconnect() {
177
+ notice({
178
+ type:'channel_reconnect',
179
+ data: {
180
+ message: 'Channel reconnect'
181
+ }
182
+ });
183
+ },
184
+ pushFlowSuccess(data) {
185
+ notice({
186
+ type:'pushFlowSuccess',
187
+ data
188
+ });
189
+ },
190
+ pullFlowResult(data) {
191
+ notice({
192
+ type:'pullFlowResult',
193
+ data
194
+ });
195
+ },
196
+ pullAudioFlowError(data) {
197
+ notice({
198
+ type:'pullAudioFlowError',
199
+ data
200
+ });
201
+ },
202
+
203
+ // ----------播放器--------
204
+ // 播放出错
205
+ playError(data) {
206
+ notice({
207
+ type:'play_error',
208
+ data
209
+ });
210
+ },
211
+ // 播放出错详细事件
212
+ playErrorDetail(data) {
213
+ notice(data);
214
+ },
215
+ // 视频首帧
216
+ firstVideoSize(data) {
217
+ notice({
218
+ type:'firstVideoSize',
219
+ data
220
+ });
221
+ },
222
+ // 音频首帧
223
+ firstAudioSize(data) {
224
+ notice({
225
+ type:'firstAudioSize',
226
+ data
227
+ });
228
+ },
229
+ //zego 通道id占用尽
230
+ overMaxConnect() {
231
+ notice({
232
+ type: 'overMaxConnect',
233
+ data: {
234
+ message: 'ZEGO:: all uiChnIndexs are used'
235
+ }
236
+ })
237
+ },
238
+ // 拉流质量
239
+ pullQuality(data) {
240
+ notice({
241
+ type:'pull_quality',
242
+ data
243
+ });
244
+ },
245
+ // 推流质量
246
+ pushQuality(data) {
247
+ notice({
248
+ type:'push_quality',
249
+ data
250
+ });
251
+ },
252
+ pushLossAndDelay(data) {
253
+ notice({
254
+ type:'push_loss_delay',
255
+ data
256
+ });
257
+ },
258
+ playLossAndDelay(data) {
259
+ notice({
260
+ type:'play_loss_delay',
261
+ data
262
+ });
263
+ },
264
+ // 更新本地预览视频,在切换SDK完成之后,会重新调起本地摄像头,需要更新本地预览的画面
265
+ updateLocalPreview(data) {
266
+ notice({
267
+ type:'update_local_preview',
268
+ data
269
+ });
270
+ },
271
+ // 网络错误
272
+ networkError() {
273
+ notice({
274
+ type:'network_error',
275
+ data: {
276
+ message: 'Network error'
277
+ }
278
+ });
279
+ },
280
+ // 网络重连
281
+ networkRecovery() {
282
+ notice({
283
+ type:'network_recovery',
284
+ data: {
285
+ message: 'Network recovery'
286
+ }
287
+ });
288
+ },
289
+
290
+ // 录制成功回调
291
+ recordResponse(data) {
292
+ notice({
293
+ type:'record_response',
294
+ data
295
+ });
296
+ },
297
+ streamStatus(data) {
298
+ notice({
299
+ type:'stream_status',
300
+ data
301
+ });
302
+ },
303
+
304
+ // -------信道消息---------
305
+ join(data) {
306
+ notice({
307
+ type: 'user_join',
308
+ data
309
+ });
310
+ },
311
+ joinAck(data) {
312
+ notice({
313
+ type: 'user_response',
314
+ data
315
+ });
316
+ },
317
+ addStream(data) {
318
+ notice({
319
+ type: 'remote_video_ready',
320
+ data
321
+ });
322
+ },
323
+ removeStream(data) {
324
+ notice({
325
+ type: 'remote_video_removed',
326
+ data
327
+ });
328
+ },
329
+ updateStreamDeviceStatus(data) {
330
+ notice({
331
+ type: 'device_status',
332
+ data
333
+ });
334
+ },
335
+ leave(data) {
336
+ notice({
337
+ type: 'user_leave',
338
+ data
339
+ });
340
+ },
341
+ channelDisconnect() {
342
+ notice({
343
+ type: 'channel_disconnect',
344
+ data: {
345
+ message: 'Channel disconnect'
346
+ }
347
+ });
348
+ },
349
+ userDisconnect(data) {
350
+ notice({
351
+ type: 'user_disconnect',
352
+ data
353
+ });
354
+ },
355
+ zegoRecoveryStart(){
356
+ notice({
357
+ type:'zego_recovery_start',
358
+ data: {
359
+ message: 'zego is killed'
360
+ }
361
+ })
362
+ },
363
+ liveRecoveryStart(){
364
+ notice({
365
+ type:'live_recovery_start',
366
+ data: {
367
+ message: 'live is killed'
368
+ }
369
+ })
370
+ },
371
+ seiReceived(data){
372
+ notice({
373
+ type:'sei_received',
374
+ data
375
+ })
376
+ },
377
+ pushStreamError(data){
378
+ notice({
379
+ type:'push_stream_error',
380
+ data
381
+ })
382
+ },
383
+ pushStreamWarning(data){
384
+ notice({
385
+ type:'push_stream_warning',
386
+ data
387
+ })
388
+ },
389
+ pullStreamError(data){
390
+ notice({
391
+ type:'pull_stream_error',
392
+ data
393
+ })
394
+ },
395
+ pullStreamWarning(data){
396
+ notice({
397
+ type:'pull_stream_warning',
398
+ data
399
+ })
400
+ },
401
+ remoteNetworkQuality(data){
402
+ notice({
403
+ type:'remote_network_quality',
404
+ data
405
+ })
406
+ },
407
+ localNetworkQuality(data){
408
+ notice({
409
+ type:'local_network_quality',
410
+ data
411
+ })
412
+ },
413
+ screenShareEnded(){
414
+ notice({
415
+ type:'screen_share_ended'
416
+ });
417
+ }
418
+ };
@@ -0,0 +1,74 @@
1
+ /*
2
+ * @Author: why
3
+ * @Date: 2019-08-08 19:33:44
4
+ * @LastEditors: Please set LastEditors
5
+ * @LastEditTime: 2021-05-24 16:47:40
6
+ * @Description:
7
+ */
8
+ import {toolExt, liveExt} from '../config/config';
9
+ import callMethod from './call-method';
10
+ const EM = window.EM;
11
+ export default {
12
+ // 获取本地CPU内存占比
13
+ getCurCpuMemInfo: () => {
14
+ return callMethod('GetCurCpuMemInfo', null, 'getCurCpuMemInfo');
15
+ },
16
+
17
+ // ping给定的拉流url,调取一次ping30s后返回延迟及丢包信息抛出事件
18
+ startLossDelayPing: (args) => {
19
+ return callMethod('GetLossDelayInfo', args, 'startLossDelayPing');
20
+ },
21
+
22
+ // ping给定的拉流url,调取一次ping30s后返回延迟及丢包信息抛出事件
23
+ startSocialLossDelayPing: (args) => {
24
+ return callMethod('GetSocialLossDelayInfo', args, 'startSocialLossDelayPing');
25
+ },
26
+ // 获取上报公共字段信息
27
+ getCommonData() {
28
+ return callMethod('GetCommonData', {live_ext_ver: liveExt.version}, 'getCommonData');
29
+ },
30
+ // 打开一个路径选择窗口,返回选择的路径信息
31
+ openDialog() {
32
+ return callMethod('OpenDialog', null, 'openDialog');
33
+ },
34
+ // 跳转到给定url
35
+ jumpPage(url) {
36
+ return callMethod('JumpPage', {url}, 'jumpPage');
37
+ },
38
+ // 获取指定磁盘的总容量及剩余容量
39
+ getDiskSenseParameter(driver) {
40
+ return callMethod('GetDiskSenseParameter', {driver}, 'getDiskSenseParameter');
41
+ },
42
+ // 获取系统信息(系统名称,本地时间等)
43
+ getSystemInformation() {
44
+ return callMethod('GetSystemInformation', null, 'getSystemInformation');
45
+ },
46
+ // 获取学生端页面版本号
47
+ getPageVersion() {
48
+ return callMethod('GetPageVersion', null, 'getPageVersion');
49
+ },
50
+ stopLossDelayInfo() {
51
+ return callMethod('StopLossDelayInfo', null);
52
+ },
53
+ /**
54
+ * @function 保存图片至桌面
55
+ * @param { string } buf //base64编码图片数据
56
+ * @param { string } fileName //图片文件名(带格式后缀)
57
+ * @return: Promise
58
+ */
59
+ saveImgToDesktop(buf, fileName) {
60
+ return callMethod('SaveImgToDesktop', {buf, fileName});
61
+ },
62
+ // 初始化
63
+ init(){
64
+ // 加载扩展
65
+ if (EM) {
66
+ // return new Promise(resolve => {
67
+ EM.Load(toolExt.name, toolExt.version, false, ()=>{
68
+ // resolve();
69
+ console.log('loadExt :zbzt_toolExt ......');
70
+ });
71
+ // });
72
+ }
73
+ }
74
+ };
@@ -0,0 +1,10 @@
1
+ /*
2
+ * @Author: why
3
+ * @Date: 2019-08-08 19:33:44
4
+ * @LastEditors: why
5
+ * @LastEditTime: 2019-09-10 17:05:31
6
+ * @Description:
7
+ */
8
+ import {cb} from '../util/bridge1';
9
+ import {toolExt} from '../config/config';
10
+ export default cb(toolExt.name);
@@ -0,0 +1,42 @@
1
+ /*
2
+ * @Author: your name
3
+ * @Date: 2020-07-09 17:07:08
4
+ * @LastEditTime: 2020-10-19 14:20:03
5
+ * @LastEditors: Please set LastEditors
6
+ * @Description: In User Settings Edit
7
+ * @FilePath: \709\zbzt_live_sdk\src\tool\extend.js
8
+ */
9
+ import BASSAPI from './base';
10
+
11
+ export default {
12
+ // 打开对话框用于选取文件路径
13
+ openDialog() {
14
+ return BASSAPI.openDialog();
15
+ },
16
+ // 跳转页面
17
+ jumpPage(url) {
18
+ return BASSAPI.jumpPage(url);
19
+ },
20
+ // 获取指定磁盘的总容量及剩余容量
21
+ getDiskSenseParameter(driver) {
22
+ return BASSAPI.getDiskSenseParameter(driver);
23
+ },
24
+ // 获取系统信息(系统名称,本地时间等)
25
+ getSystemInformation() {
26
+ return BASSAPI.getSystemInformation();
27
+ },
28
+ // 获取cpu信息
29
+ getCurCpuMemInfo() {
30
+ return BASSAPI.getCurCpuMemInfo();
31
+ },
32
+ // 获取cpu信息
33
+ getPageVersion() {
34
+ return BASSAPI.getPageVersion();
35
+ },
36
+ getCommonData() {
37
+ return BASSAPI.getCommonData();
38
+ },
39
+ saveImgToDesktop(buf, fileName){
40
+ return BASSAPI.saveImgToDesktop(buf, fileName);
41
+ }
42
+ };
@@ -0,0 +1,10 @@
1
+ /*
2
+ * @Author: why
3
+ * @Date: 2019-08-08 19:33:44
4
+ * @LastEditors: why
5
+ * @LastEditTime: 2019-09-09 15:02:54
6
+ * @Description:
7
+ */
8
+ import api from './extend';
9
+
10
+ export default api;
@@ -0,0 +1,87 @@
1
+ import {
2
+ extensionInfo, config
3
+ } from '../config/config';
4
+ import dict from '../util/dict';
5
+
6
+ const currentTimeString = () => {
7
+ const timeString = '[' +
8
+ ('' + new Date().getHours()).padStart(2, '0') + ':' +
9
+ ('' + new Date().getMinutes()).padStart(2, '0') + ':' +
10
+ ('' + new Date().getSeconds()).padStart(2, '0') + ':' +
11
+ ('' + new Date().getMilliseconds()).padStart(3, '0') +
12
+ ']';
13
+ return timeString;
14
+ };
15
+
16
+ const callMethod = (name, args, extensionId = 'default_ext') => {
17
+ // EM 是寄宿于端的,浏览器中并不存在,为防止报错需要先进行能力检测
18
+ if (EM) {
19
+ return new Promise((resolve, reject) => {
20
+ EM.CallMethod(
21
+ extensionId,
22
+ name,
23
+ JSON.stringify(args),
24
+ (code, content) => {
25
+ //控制台weblog高优先级
26
+ if (typeof window.zbzt_live_sdk_weblog !== 'undefined') {
27
+ if (window.zbzt_live_sdk_weblog === true) {
28
+ if (name === 'WriteLog' && code == 0) {
29
+ console.log(
30
+ currentTimeString() +
31
+ `${args.msg}`);
32
+ } else {
33
+ console.log(`${name} :
34
+ Time: ${currentTimeString()}
35
+ Param: ${args.msg}
36
+ Code: ${code}
37
+ Message: ${content}`);
38
+ }
39
+ }
40
+ } else {
41
+ //sdk默认输出weblog日志,除非明确禁用;初始化之前默认输出日志,初始化后根据参数规则
42
+ // if (!window.zbzt_sdk_init_params || typeof window.zbzt_sdk_init_params.weblog === 'undefined' || (typeof window.zbzt_sdk_init_params.weblog !== 'undefined' && window.zbzt_sdk_init_params.weblog === true)) {
43
+ if ( config.weblog === true) {
44
+ if (name === 'WriteLog' && code == 0) {
45
+ console.log(
46
+ currentTimeString() +
47
+ `${args.msg}`);
48
+ } else {
49
+ console.log(`${name} :
50
+ Time: ${currentTimeString()}
51
+ Param: ${args.msg}
52
+ Code: ${code}
53
+ Message: ${content}`);
54
+ }
55
+ }
56
+ }
57
+ resolve({
58
+ code,
59
+ content
60
+ });
61
+ });
62
+ });
63
+ }
64
+ };
65
+
66
+ export const writeLog = (msgtype = 'info', msgbody, productName) => {
67
+ msgbody = typeof msgbody === 'string' ? msgbody : JSON.stringify(msgbody);
68
+ const args = {
69
+ //日志级别,0:debug,1:info,2:warnning,3:error,4:critical
70
+ 'type': dict.logMap[msgtype],
71
+ 'msg': `--${productName?'['+productName+']--':''} ${msgbody}`
72
+ };
73
+ callMethod('WriteLog', args);
74
+ };
75
+
76
+ if (window.EM) {
77
+ EM.Load('default_ext',
78
+ extensionInfo.version.default_ext,
79
+ true,
80
+ function (ec, content) {
81
+ writeLog('info', 'Load EC:' + ec + '\nContent:' + content);
82
+ });
83
+ }
84
+
85
+ export default {
86
+ writeLog
87
+ };
@@ -0,0 +1,46 @@
1
+ /*
2
+ * @Author: why
3
+ * @Date: 2019-06-18 11:42:34
4
+ * @LastEditors: Please set LastEditors
5
+ * @LastEditTime: 2020-09-11 11:33:35
6
+ * @Description: this is a bridge for js and app
7
+ */
8
+ import {productName, classType} from '../config/config';
9
+ import defaultApi from '../default';
10
+ const EM = window.EM;
11
+
12
+ // 不需要写日志方法名集合
13
+ const noWriteLogNames = ['GetCurCpuMemInfo', 'WriteLog', 'IsStreamAudioMuted', 'IsStreamVideoMuted'];
14
+
15
+ export const cb = (extName) => {
16
+ // EM 是寄宿于端的,浏览器中并不存在,为防止报错需要先进行能力检测
17
+ if (EM) {
18
+ return function(name, args, sdkName){
19
+ const argsStr = typeof args === 'object' ? JSON.stringify({...args, classType}) : args;
20
+ return new Promise((resolve, reject) => {
21
+ EM.CallMethod(
22
+ extName,
23
+ name,
24
+ argsStr,
25
+ (code, msg) => {
26
+ const msgbody = `${extName}--action: ${sdkName || ''}--${name || name.charAt(0).toLowerCase() + name.slice(1)} Code: ${code}\nMessage: ${msg}\nparams:${JSON.stringify(args)}`;
27
+ if (code === 0) {
28
+ !noWriteLogNames.includes(name) && defaultApi.writeLog && defaultApi.writeLog(msgbody, productName);
29
+ resolve({
30
+ code,
31
+ msg: msg && /\{|\}/g.test(msg) && JSON.parse(msg)
32
+ });
33
+ } else {
34
+ name !== 'WriteLog' && defaultApi.writeLog && defaultApi.writeLog(msgbody, productName, 'error');
35
+ resolve({
36
+ code,
37
+ msg
38
+ });
39
+ }
40
+ });
41
+ }).catch(() => {
42
+ name !== 'WriteLog' && defaultApi.writeLog && defaultApi.writeLog(`${extName}--action: ${sdkName || ''}--${name || name.charAt(0).toLowerCase() + name.slice(1)} Code: ${code}\nMessage: ${msg}\nparams:${JSON.stringify(args)}`, productName, 'error');
43
+ });
44
+ };
45
+ }
46
+ };