FlashToolComponet.js
61.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
/**
* 获取flash的音视频设备信息和监课音频消息播放都使用这个
* Created by hoopoe8 on 2017/5/2.
*/
import Loger from "../Loger";
import xdyVideo from '../libs/xdyVideo';
import xdysdk from "../libs/xdysdk";
import H5Seting from "./H5Seting";
let loger = Loger.getLoger('PC-FlashToolComponet');
const FlashToolComponetLog = 'PC-FlashToolComponet';
const store = require('../libs/store');
class FlashToolComponet {
constructor() {
this.flashId = "";//swf的标识
this.isMainFlash = false;//是否设置为主flash文件
this.swfUrl = '';
this.divName = "";
this.flashCallback = null;
this.publishTimer = 0;//重推流的计时器
this.isInPublish = false;//当前是否正在推流中
this.publishType = "";//当前推流的类型
this.flashObj = null;//flash对象
this.publishResult = {}; //从sdk获取的推流数据
this.mediaId = 0;//默认是0
this.rtmpURL = '';//推流或播流的地址
this.nodeId = 0;//使用者的nodeId
this.userName = "";
this.userId = "";
this.userRole = "";
this.myUserRole = "";//当前播放器使用者的身份
this.screenWidth = 0;
this.screenHeight = 0;
this.showFullBtn = false;//是否显示全屏按钮
this.isPublishVideo = true;//包含视频
this.isPublishAudio = true;//包含音频
this.status = 0;//媒体的播放状态 0停止 1播放 2暂停
this.seek = 0;
this.mediaVolume = 60;//媒体音量
this.backgroundColor = 0x353536;//
this.autoShowLayout = false;//自动调整显示布局
this.leftGap = FlashToolComponet.LEFT_GAP;
this.topGap = FlashToolComponet.TOP_GAP;
this.layoutType = FlashToolComponet.LAYOUT_V;
this.layoutGapV = FlashToolComponet.LAYOUT_GAP_V;
this.layoutGapH = FlashToolComponet.LAYOUT_GAP_H;
this.mediaType = FlashToolComponet.VIDEO;
this.videoImage = '';
this.audioImage = '';
this.audioBtnImage = '';
this.videoBtnImage = '';
this.stopPublishImage = '';
this.playersDataList = [];//flash中的播放器列表数据
this.docNoteCallback = null;//获取文档note信息的回调函数
this.onselfFlashSettingCallback = null;
this.otherFlashSettingCallback = null;
this.historyPlayDataList = {};//记录播放器没有创建完成之前记录的需要播放的数据
}
//viewName (div的id名称);_width(视频的宽度),_height(视频的高度)
init(_params) {
if (_params) {
//this.type = _params.type || "video";
this.swfUrl = _params.swfUrl;
this.divName = "" + _params.divName;
this.flashCallback = _params.callBack;
this.layoutType = _params.layoutType || FlashToolComponet.LAYOUT_V;
this.videoImage = _params.videoImage || "";
this.audioImage = _params.audioImage || '';
this.audioBtnImage = _params.audioBtnImage || '';
this.videoBtnImage = _params.videoBtnImage || '';
this.stopPublishImage = _params.stopPublishImage || '';
this.playersDataList = _params.playersDataList || [];
this.autoShowLayout = _params.autoShowLayout || false;
if (_params.backgroundColor) {
this.backgroundColor = _params.backgroundColor;
}
/* [
{mediaType: FlashToolComponet.VIDEO, width: 320, height: 240, showFullBtn: false, level: 1},
{mediaType: FlashToolComponet.VIDEO, width: 320, height: 240, showFullBtn: false, level: 0}
]*/
}
this.flashObj = null;
this.publishResult = {};
loger.log("init->divName:" + this.divName, "mediaId:", this.mediaId);
let div = document.getElementById(this.divName);
if (div) {
//创建flash
this.creatFlash();
} else {
loger.error("创建Flash时必须传递一个div的id,不能传递class");
alert("创建Flash播放器时必须传递一个div的id,不能传递class");
}
}
//JS发送数据到flash
js2native(_param) {
let msg = "";
try {
msg = JSON.stringify({
type: parseInt(_param.type),
data: _param.data || {}
});
} catch (err) {
loger.warn("JS发送数据到flash->数据转换为JSON失败");
}
if (this.flashObj && this.flashObj._js2native) {
loger.log("JS发送数据到flash->" + this.swfUrl);
this.flashObj._js2native(msg);
} else {
loger.warn("JS发送数据到flash->flash对象不存在或_js2native无效");
}
}
//创建FLASH
creatFlash() {
loger.log("创建flash->", this.mediaId);
if (this.flashObj) {
loger.log("已经创建了flashObj");
return;
}
xdyVideo(
this.swfUrl,
this.divName,
'100%',
'100%',
this.creatFlashSuccess.bind(this),
this.flashAddEventListener.bind(this),
this.logCallback.bind(this)
);
}
//创建flash对象完成
creatFlashSuccess(error, publishflash, info) {
if (error) {
let pluginsInfo = navigator.plugins['Shockwave Flash'];
if (!pluginsInfo) {
loger.error('flash被禁用');
if (this.flashCallback) {
this.flashCallback({
type: FlashToolComponet.TYPE_30
});
}
}
return loger.error('js->页面创建flash失败->', error);
}
this.flashObj = publishflash;
//flash加载完成,设置播放器布局
this.setVideoConfigData();
let infoObj = {};
if (info) {
infoObj = JSON.parse(info) || {};
this.flashId = infoObj.data.flashId || "";
}
console.warn('flash创建完成->infoObj', "this.flashId:" + this.flashId, "this.isMainFlash:" + this.isMainFlash, infoObj);
/* if (this.flashId == 'flashSettingTools') {
FlashToolComponet.flashSetingToolsSwf = this;
if (FlashToolComponet.isFlashGetDefaultSetting) {
loger.log('FlashSetingTools 已经创建过,不需要再设置')
return;
FlashToolComponet.isFlashGetDefaultSetting = true;
//本地存储
FlashToolComponet.userDeviceInfo.deviceInfo.cameras = infoObj.cameras;
FlashToolComponet.userDeviceInfo.deviceInfo.microphones = infoObj.microphones;
FlashToolComponet.userDeviceInfo.deviceInfo.curCamera = infoObj.curCamera;
FlashToolComponet.userDeviceInfo.deviceInfo.curMicrophone = infoObj.curMicrophone;
FlashToolComponet.userDeviceInfo.deviceInfo.curVideoQuality = infoObj.curVideoQuality;
FlashToolComponet.userDeviceInfo.deviceInfo.micCode = infoObj.micCode;
FlashToolComponet.userDeviceInfo.deviceInfo.micGain = infoObj.micGain;
FlashToolComponet.userDeviceInfo.deviceInfo.speakerVolume = infoObj.speakerVolume;
FlashToolComponet.userDeviceInfo.deviceInfo.videoQuality = infoObj.videoQuality;
//发送给SDK
xdysdk.api('setDeviceInfo', {
videoQuality: FlashToolComponet.videoInfo.videoQuality,
curVideoQuality: FlashToolComponet.videoInfo.curVideoQuality,
fps: FlashToolComponet.videoInfo.fps,
gop: FlashToolComponet.videoInfo.gop,
cameras: FlashToolComponet.userDeviceInfo.deviceInfo.cameras || [],
microphones: FlashToolComponet.userDeviceInfo.deviceInfo.microphones || [],
curCamera: FlashToolComponet.userDeviceInfo.deviceInfo.curCamera || '',
curMicrophone: FlashToolComponet.userDeviceInfo.deviceInfo.curMicrophone || '',
micGain: FlashToolComponet.userDeviceInfo.deviceInfo.micGain || 50,
speakerVolume: FlashToolComponet.userDeviceInfo.deviceInfo.speakerVolume || 50
});
}
} else if (this.flashId == "flashPlayer") {
//其他flash加载完不做全局设置
//更新设备信息
if (this.isMainFlash) {
//把当前flash设置为主flash文件
FlashToolComponet.flashPlayerSwf = this;
}
this.setFlashDeviceInfo(FlashToolComponet.userDeviceInfo);
}*/
if (this.flashId == "flashPlayer") {
if (this.isMainFlash) {
console.log("flash返回的设备信息->", infoObj);
//本地存储
FlashToolComponet.userDeviceInfo.deviceInfo.cameras = infoObj.data.cameras;
FlashToolComponet.userDeviceInfo.deviceInfo.microphones = infoObj.data.microphones;
let curCamera = FlashToolComponet.userDeviceInfo.deviceInfo.curCamera;
if (infoObj.data.cameras.length > 0 && infoObj.data.cameras.indexOf(curCamera) < 0) {
FlashToolComponet.userDeviceInfo.deviceInfo.curCamera = infoObj.data.cameras[0] || "";
}
let curMicrophone = FlashToolComponet.userDeviceInfo.deviceInfo.curMicrophone;
if (infoObj.data.microphones.length > 0 && infoObj.data.microphones.indexOf(curMicrophone) < 0) {
FlashToolComponet.userDeviceInfo.deviceInfo.curMicrophone = infoObj.data.microphones[0] || "";
}
//如果用户没有摄像头和麦克,需要弹窗提示
if (!infoObj.data.cameras || infoObj.data.cameras.length < 1) {
loger.warn("摄像头获取失败->");
if (this.flashCallback) {
this.flashCallback({
type: FlashToolComponet.TYPE_24
});
}
}
if (!infoObj.data.microphones || infoObj.data.microphones.length < 1) {
loger.warn("麦克风获取失败->");
if (this.flashCallback) {
this.flashCallback({
type: FlashToolComponet.TYPE_25
});
}
}
//FlashToolComponet.userDeviceInfo.deviceInfo.curCamera = infoObj.curCamera;
//FlashToolComponet.userDeviceInfo.deviceInfo.curMicrophone = infoObj.curMicrophone;
//FlashToolComponet.userDeviceInfo.deviceInfo.curVideoQuality = infoObj.curVideoQuality;
//FlashToolComponet.userDeviceInfo.deviceInfo.micCode = infoObj.micCode;
//FlashToolComponet.userDeviceInfo.deviceInfo.micGain = infoObj.micGain;
//FlashToolComponet.userDeviceInfo.deviceInfo.speakerVolume = infoObj.speakerVolume;
//FlashToolComponet.userDeviceInfo.deviceInfo.videoQuality = infoObj.videoQuality;
FlashToolComponet.sendDeviceInfo2sdk();
FlashToolComponet.saveLocalStore();
////发送给SDK
//xdysdk.api('setDeviceInfo', {
// videoQuality: FlashToolComponet.videoInfo.videoQuality,
// curVideoQuality: FlashToolComponet.videoInfo.curVideoQuality,
// fps: FlashToolComponet.videoInfo.fps,
// gop: FlashToolComponet.videoInfo.gop,
//
// cameras: FlashToolComponet.userDeviceInfo.deviceInfo.cameras || [],
// microphones: FlashToolComponet.userDeviceInfo.deviceInfo.microphones || [],
// curCamera: FlashToolComponet.userDeviceInfo.deviceInfo.curCamera || '',
// curMicrophone: FlashToolComponet.userDeviceInfo.deviceInfo.curMicrophone || '',
// micGain: FlashToolComponet.userDeviceInfo.deviceInfo.micGain || 50,
// speakerVolume: FlashToolComponet.userDeviceInfo.deviceInfo.speakerVolume || 50
//});
//
}
this.setFlashDeviceInfo(FlashToolComponet.userDeviceInfo);
}
//加载完成的flash添加到队列中
FlashToolComponet.list[this.divName] = this;
//flash加载完,需要回调自己加载完成的消息
loger.log(this.swfUrl + '->flash加载->完成->flashId:' + this.flashId);
if (this.flashCallback) {
this.flashCallback({
type: FlashToolComponet.TYPE_0
});
}
this.playHistroyMedia();
}
//播放flash未创建之前收到的播放消息
playHistroyMedia() {
console.warn(this.swfUrl + '->flash加载->完成->检查是否需要播放视频->this.historyPlayDataList:', this.historyPlayDataList);
//flash加载完成之后,尝试播放视频,因为在加载flash加载完成之前可能收到播放的地址
for (let k in this.historyPlayDataList) {
let item = this.historyPlayDataList[k];
if (item && item.rtmpURL) {
if (item.mediaType == FlashToolComponet.MEDIA_SHARE) {
//媒体播放,媒体共享的时候
this.playMediaUrl({
rtmpUrl: item.rtmpURL,
mediaId: item.mediaId,
mediaType: item.mediaType || FlashToolComponet.MEDIA_SHARE,
nodeId: item.nodeId || 0,
userRole: item.userRole || 'normal',
screenWidth: item.screenWidth || 0,
screenHeight: item.screenHeight || 0,
showFullBtn: item.showFullBtn || false,
status: item.status,
seek: item.seek,
mediaVolume: item.mediaVolume
})
} else {
//拉流播放(正常拉流和屏幕共享拉流)
this.playMedia({
rtmpUrl: item.rtmpURL,
mediaId: item.mediaId,
mediaType: item.mediaType,
nodeId: item.nodeId,
userRole: item.userRole,
screenWidth: item.screenWidth || 0,
screenHeight: item.screenHeight || 0,
showFullBtn: item.showFullBtn || false
});
}
}
}
}
//监听消息
flashAddEventListener(_callbackMsgStr) {
//console.log("flashAddEventListener",msg);
let _callbackMsgObj = JSON.parse(_callbackMsgStr);
//{"type":52,"data":{"type":52,"activityLevel":0}}
switch (_callbackMsgObj.type) {
case FlashToolComponet.TYPE_1:
loger.log("获取文档note完成->");
if (this.docNoteCallback) {
this.docNoteCallback(_callbackMsgObj.data);
}
break;
case FlashToolComponet.TYPE_2:
loger.log("播放流成功");
break;
case FlashToolComponet.TYPE_3:
loger.log("flash->加载完成", msg);
let cameraMicInfo = msg.data.msg;
if (cameraMicInfo) {
FlashToolComponet.userDeviceInfo.deviceInfo.cameras = cameraMicInfo.cameras || [];
FlashToolComponet.userDeviceInfo.deviceInfo.microphones = cameraMicInfo.microphones || [];
FlashToolComponet.saveLocalStore();
FlashToolComponet.sendDeviceInfo2sdk();
}
if (this.flashCallback) {
this.flashCallback({
type: FlashToolComponet.TYPE_3
});
}
break;
case FlashToolComponet.TYPE_5:
loger.log(this.swfUrl + "->主动->flash停止推流");
break;
case FlashToolComponet.TYPE_9:
//设备发生改变->设置flash设备信息-.返回
loger.log(this.swfUrl + "->flash中保存设备设置信息完成->");
break;
case FlashToolComponet.TYPE_10:
//flash推流成功,需要把消息同步给sdk
/* loger.log("flash推流成功,需要把消息同步给sdk", _callbackMsgObj.data);
let _successErrorResult;
this.publishType=_callbackMsgObj.data.mediaType;
if (_callbackMsgObj.data.mediaType == FlashToolComponet.AUDIO) {
_successErrorResult = xdysdk.api("publishAudio", _callbackMsgObj.data);
} else {
_successErrorResult = xdysdk.api("publishVideo", _callbackMsgObj.data);
}
this.isInPublish=true;
if (_successErrorResult.code == 0) {
loger.log("flash推流成功-->同步消息成功");
if (this.flashCallback) {
this.flashCallback({
type: FlashToolComponet.TYPE_10
});
}
} else if (_successErrorResult.code == 1) {
loger.log("flash推流成功-->同步消息失败-->关闭推流");
//this.stopMedia(_callbackMsgObj.data.mediaId);
this.dispatchClickStopPublish(_callbackMsgObj.data);
}*/
break;
case FlashToolComponet.TYPE_12:
FlashToolComponet.flashSettingChange(_callbackMsgObj.data.msg);
if (this.onselfFlashSettingCallback) {
this.onselfFlashSettingCallback(_callbackMsgObj.data.msg)
}
break;
case FlashToolComponet.TYPE_13:
// console.log("更改用户设备信息->", _callbackMsgObj.data.msg);
if (this.otherFlashSettingCallback) {
this.otherFlashSettingCallback(_callbackMsgObj.data.msg)
}
break;
case FlashToolComponet.TYPE_14:
//设置窗口关闭
if (this.flashCallback) {
this.flashCallback(_callbackMsgObj.data);
}
//关闭设置面板的时候要停止摄像头和麦克风检测
if (FlashToolComponet.flashPlayerSwf) {
FlashToolComponet.flashPlayerSwf.closeCamera();
FlashToolComponet.flashPlayerSwf.closeMicrophone();
}
break;
case FlashToolComponet.TYPE_15:
//返回设备的系统信息
loger.warn("返回设备的系统信息->", _callbackMsgObj.data);
break;
case FlashToolComponet.TYPE_16:
loger.warn("设置面板点击了测试MS速度->", _callbackMsgObj.data);
if (this.flashCallback) {
this.flashCallback(_callbackMsgObj.data);
}
break;
case FlashToolComponet.TYPE_17:
loger.warn("设置面板测试MS速度完成返回->", _callbackMsgObj);
if (this.flashCallback) {
this.flashCallback(_callbackMsgObj);
}
break;
case FlashToolComponet.TYPE_18:
//监听媒体播放器返回的消息
if (this.flashCallback) {
this.flashCallback(_callbackMsgObj.data);
}
break;
case FlashToolComponet.TYPE_20:
loger.warn("摄像头麦克风权限没有开启->");
if (this.flashCallback) {
this.flashCallback(_callbackMsgObj);
}
H5Seting.showSecurityPanelSeting();
break;
case FlashToolComponet.TYPE_21:
// {"result":0,"errmsg":"","msg":{"info":"音量检测","volumeLeve":0},"type":21}
//loger.warn("返回音量检测->",_callbackMsgObj);
if (this.flashCallback) {
this.flashCallback(_callbackMsgObj);
}
break;
case FlashToolComponet.TYPE_24:
//摄像头获取失败
if (this.flashCallback) {
this.flashCallback({
type: FlashToolComponet.TYPE_24
});
}
break;
case FlashToolComponet.TYPE_25:
//麦克风获取失败
if (this.flashCallback) {
this.flashCallback({
type: FlashToolComponet.TYPE_25
});
}
break;
case FlashToolComponet.TYPE_27:
//摄像头被占用
if (this.flashCallback) {
this.flashCallback({
type: FlashToolComponet.TYPE_27
});
}
break;
case FlashToolComponet.TYPE_31:
//flash的摄像头权限已经允许
if (this.flashCallback) {
this.flashCallback(_callbackMsgObj);
}
break;
case FlashToolComponet.TYPE_42:
//显示摄像头图像
H5Seting.updateCameraImage(_callbackMsgObj.data);
break;
case FlashToolComponet.TYPE_52:
//更新当前麦克风音量检测
//loger.log("更新当前麦克风音量检测->",_callbackMsgObj.data.msg.activityLevel);
if (FlashToolComponet.flashSetingToolsSwf) {
FlashToolComponet.flashSetingToolsSwf.showMicrophoneLevel(_callbackMsgObj.data.activityLevel);
}
H5Seting.updateMicrophoneActivityLevel(_callbackMsgObj.data);
break;
case FlashToolComponet.TYPE_62:
//更新当前扬声器音量检测
//loger.log("更新当前麦克风音量检测->",_callbackMsgObj.data.msg.activityLevel);
if (FlashToolComponet.flashSetingToolsSwf) {
FlashToolComponet.flashSetingToolsSwf.showSpeakerLevel(_callbackMsgObj.data.activityLevel);
}
H5Seting.updateSpeakerTestActivityLevel(_callbackMsgObj.data);
break;
case FlashToolComponet.TYPE_101:
loger.log("收到点击视频推流消息");
this.getPublishPathAndPublish({mediaType: FlashToolComponet.VIDEO, playerId: _callbackMsgObj.data.playerId});
break;
case FlashToolComponet.TYPE_102:
loger.log("收到点击音频推流消息");
this.getPublishPathAndPublish({mediaType: FlashToolComponet.AUDIO, playerId: _callbackMsgObj.data.playerId});
break;
case FlashToolComponet.TYPE_103:
loger.log("收到点击停止推流消息", _callbackMsgObj.data);
this.stopPublish(_callbackMsgObj.data);
break;
case FlashToolComponet.TYPE_105:
loger.warn("无法推流->没有空闲的播放器");
if (this.flashCallback) {
this.flashCallback({
type: FlashToolComponet.TYPE_105
});
}
break;
default :
loger.log("default->", _callbackMsgObj.data.type);
break
}
}
//log
logCallback(_callbackData) {
console.warn(this.divName + "->" + this.swfUrl + '->', _callbackData);
xdysdk.api('addWarn', "[flash]" + _callbackData);
}
//获取本地存储的数据
static getLocalStore(_callback) {
loger.log("获取本地设备数据->");
store.get('settings', (err, data) => {
if (!err && data) {
console.log('获取本地设备数据完成->', data);
FlashToolComponet.userDeviceInfo = data;
} else {
console.log('获取本地设备数据失败->', err);
}
//无论成功失败都要回调
if (_callback) {
_callback(data);
}
})
}
//存储数据到本地
static saveLocalStore(_data, _callback) {
console.log("存储数据到本地->", FlashToolComponet.userDeviceInfo);
FlashToolComponet.userDeviceInfo.actionType = "";//保存数据的时候 指令不需要保存
store.set('settings', FlashToolComponet.userDeviceInfo, (err, data) => {
if (!err) {
console.log('保存本地设备数据完成->', data);
} else {
console.log('保存本地设备数据失败->', err);
}
//无论成功失败都要回调
if (_callback) {
_callback();
}
})
}
//flash设置发生改变(自己设置了设置面板或者是别人设置了自己的设备属性)
static flashSettingChange(_data, _isRepublish = true) {
loger.log('flash设置发生改变->_isRepublish', _isRepublish, _data);
FlashToolComponet.isRepublish = _isRepublish;
if (_data) {
//保存最新数据
FlashToolComponet.userDeviceInfo = _data;
//更新sdk数据
FlashToolComponet.sendDeviceInfo2sdk();
FlashToolComponet.saveLocalStore();
}
}
static flashSettingChangeSelf(_data, _isRepublish = true) {
loger.log('h5设置发生改变->_isRepublish', _isRepublish, _data);
FlashToolComponet.isRepublish = _isRepublish;
if (_data) {
//保存最新数据
//console.log("userDeviceInfo.nodeData",_data)
FlashToolComponet.userDeviceInfo.nodeData = _data;
FlashToolComponet.userDeviceInfo.actionType = _data.actionType || "";
FlashToolComponet.userDeviceInfo.deviceInfo.cameras = _data.cameras;
FlashToolComponet.userDeviceInfo.deviceInfo.microphones = _data.microphones;
FlashToolComponet.userDeviceInfo.deviceInfo.curCamera = _data.curCamera;
FlashToolComponet.userDeviceInfo.deviceInfo.curMicrophone = _data.curMicrophone;
FlashToolComponet.userDeviceInfo.deviceInfo.micCode = _data.micCode;
FlashToolComponet.userDeviceInfo.deviceInfo.speakerVolume = _data.speakerVolume;
FlashToolComponet.userDeviceInfo.deviceInfo.micGain = _data.micGain;
FlashToolComponet.userDeviceInfo.deviceInfo.micNoise = _data.micNoise;
FlashToolComponet.userDeviceInfo.deviceInfo.autoGain = _data.autoGain;
FlashToolComponet.userDeviceInfo.deviceInfo.videoQuality = _data.videoQuality;
FlashToolComponet.userDeviceInfo.deviceInfo.curVideoQuality = _data.curVideoQuality;
FlashToolComponet.videoInfo.curVideoQuality = _data.curVideoQuality;
//更新sdk数据
FlashToolComponet.sendDeviceInfo2sdk();
FlashToolComponet.saveLocalStore();
}
}
get publishResultObj() {
return this.publishResult;
}
//发送最新的设备信息到sdk,同时更新各flash设备信息
static sendDeviceInfo2sdk() {
let deviceInfo = FlashToolComponet.userDeviceInfo.deviceInfo;
loger.log('sendDeviceInfo2sdk--->', deviceInfo);
xdysdk.api('setDeviceInfo', {
videoQuality: parseInt(deviceInfo.videoQuality),
cameras: deviceInfo.cameras || [],
microphones: deviceInfo.microphones || [],
curCamera: deviceInfo.curCamera || '',
curMicrophone: deviceInfo.curMicrophone || '',
curVideoQuality: parseInt(deviceInfo.curVideoQuality),
micGain: deviceInfo.micGain || 70,
micNoise: deviceInfo.micNoise || 70,
autoGain: Boolean(deviceInfo.autoGain),
speakerVolume: deviceInfo.speakerVolume || 80
});
//console.log(FlashToolComponet.list);
let flashList = FlashToolComponet.list;
for (let i in flashList) {
let flashItem = flashList[i];
if (flashItem) {
flashItem.updateDeviceInfo(FlashToolComponet.userDeviceInfo);
}
}
}
static setMediaVideoConfig(_fps, _gop, _videoQuality) {
loger.warn("保存从Sass获取的音视频信息-->videoQuality:" + _videoQuality, 'fps:' + _fps, 'gop:' + _gop);
FlashToolComponet.userDeviceInfo.deviceInfo.fps = _fps || 15;//帧频
FlashToolComponet.userDeviceInfo.deviceInfo.gop = _gop || 3;//帧频
FlashToolComponet.userDeviceInfo.deviceInfo.videoQuality = parseInt(_videoQuality);//帧频
FlashToolComponet.userDeviceInfo.deviceInfo.curVideoQuality = parseInt(_videoQuality);//帧频
//音视频属性,不缓存,每次都是从sass获取的
FlashToolComponet.videoInfo.fps = _fps || 15;//帧频
FlashToolComponet.videoInfo.gop = _gop || 3;//帧频
FlashToolComponet.videoInfo.videoQuality = parseInt(_videoQuality);//帧频
FlashToolComponet.videoInfo.curVideoQuality = parseInt(_videoQuality);//帧频
//获取本地设置的数据
FlashToolComponet.getLocalStore(function () {
//先把本地数据取出来,再设置
FlashToolComponet.userDeviceInfo.deviceInfo.fps = _fps || 15;//帧频
FlashToolComponet.userDeviceInfo.deviceInfo.gop = _gop || 3;//帧频
FlashToolComponet.userDeviceInfo.deviceInfo.videoQuality = parseInt(_videoQuality);//帧频
FlashToolComponet.userDeviceInfo.deviceInfo.curVideoQuality = parseInt(_videoQuality);//帧频
//音视频属性,不缓存,每次都是从sass获取的
FlashToolComponet.videoInfo.fps = _fps || 15;//帧频
FlashToolComponet.videoInfo.gop = _gop || 3;//帧频
FlashToolComponet.videoInfo.videoQuality = parseInt(_videoQuality);//帧频
FlashToolComponet.videoInfo.curVideoQuality = parseInt(_videoQuality);//帧频
//本地数据获取完成之后,发送到SDK更新
FlashToolComponet.sendDeviceInfo2sdk();
});
}
//更新flash播放器中的设备信息
updateDeviceInfo(_data) {
loger.log(this.divName + "->更新设备信息---->", _data);
if (_data) {
//FlashToolComponet.userDeviceInfo=_data;
console.log(FlashToolComponet.userDeviceInfo);
switch (_data.actionType) {
case FlashToolComponet.CHANGE_CAMERA:
loger.log("actionType-->切换摄像头", _data.actionType);
this.setFlashDeviceInfo(FlashToolComponet.userDeviceInfo);
break;
case FlashToolComponet.CHANGE_RESOLUTION:
loger.log("actionType-->切换分辨率", _data.actionType);
this.setFlashDeviceInfo(FlashToolComponet.userDeviceInfo);
break;
case FlashToolComponet.CHANGE_MICROPHONE:
loger.log("actionType-->切换麦克风", _data.actionType);
this.setFlashDeviceInfo(FlashToolComponet.userDeviceInfo);
break;
case FlashToolComponet.CHANGE_MICROPHONE_CODE:
loger.log("actionType-->切换麦克风模式", _data.actionType);
this.setFlashDeviceInfo(FlashToolComponet.userDeviceInfo);
break;
case FlashToolComponet.CHANGE_MICROPHONE_GAIN:
loger.log("actionType-->更改麦克风音量", _data.actionType);
this.setFlashDeviceInfo(FlashToolComponet.userDeviceInfo);
break;
case FlashToolComponet.CHANGE_MICROPHONE_NOISE:
loger.log("actionType-->更改麦克风回声降噪值", _data.actionType);
this.setFlashDeviceInfo(FlashToolComponet.userDeviceInfo);
break;
case FlashToolComponet.CHANGE_MICROPHONE_AUTO_GAIN:
loger.log("actionType-->更改麦克风自动调节音量", _data.actionType);
this.setFlashDeviceInfo(FlashToolComponet.userDeviceInfo);
break;
case FlashToolComponet.CHANGE_SPEAKER_VOLUME:
loger.log("actionType-->更改扬声器音量", _data.actionType);
this.setFlashDeviceInfo(FlashToolComponet.userDeviceInfo);
break;
default :
loger.log("actionType-->其他", _data.actionType);
break;
}
}
}
//调用flash中的点击按钮推流事件
dispatchClickPublish(_data) {
//默认按点击视频推流处理
let _type = FlashToolComponet.TYPE_101;
if (_data.mediaType == FlashToolComponet.AUDIO) {
//音频推流
_type = FlashToolComponet.TYPE_102;
}
this.isInPublish = true;//点击推流,先把状态设为推流状态;没成功的时候再设置为false
this.userName = _data.userName || "";
this.userRole = _data.userRole || "normal"
this.nodeId = _data.nodeId || 0;
this.js2native({
type: _type,
data: _data
});
}
//调用flash中的点击按钮停止推流事件
dispatchClickStopPublish(_data) {
this.userName = _data.userName || "";
this.userRole = _data.userRole || "normal"
this.nodeId = _data.nodeId || 0;
this.isInPublish = false;
this.publishType = "";
//点击停止推流
this.js2native({
type: FlashToolComponet.TYPE_103,
data: _data
});
}
//MS切换后,如果当前自己正在推流,需要重新推流
changeMsAndRePublish(_data) {
if (!_data) {
return;
}
loger.warn("MS切换后,如果当前自己正在推流,需要重新推流", this.isInPublish, _data);
if (this.isInPublish) {
clearTimeout(this.publishTimer);
//先停止当前的推流
this.dispatchClickStopPublish(_data);
this.publishTimer = setTimeout(()=> {
//调用flash中的点击按钮推流事件
if (this.publishType == FlashToolComponet.AUDIO) {
_data.mediaType = FlashToolComponet.AUDIO;
} else {
_data.mediaType = FlashToolComponet.VIDEO;
}
this.dispatchClickPublish(_data);
}, 2000);
}
}
//停止推流
stopPublish(_param) {
if (_param) {
this.publishType = "";
if (_param.mediaType == FlashToolComponet.AUDIO) {
this.isInPublish = false;
xdysdk.api("unPublishAudio", {"nodeId": 0, "mediaId": parseInt(_param.mediaId)});
} else {
this.isInPublish = false;
xdysdk.api("unPublishVideo", {"nodeId": 0, "mediaId": parseInt(_param.mediaId)});
}
}
}
//获取推流地址并且推流
getPublishPathAndPublish(_param) {
if (_param) {
let publishResult = this.getPublishPath(_param);
publishResult.playerId = _param.playerId || 0;//要推流的flash播放器id
publishResult.userName = this.userName || "";
publishResult.userRole = this.myUserRole
publishResult.nodeId = this.nodeId || 0;
//code为0,代表成功
if (publishResult.code == 0) {
//修改推流消息的流程,
// 1.之前的逻辑是先推流成功后再广播发布消息
// 2.新的逻辑为先广播发布消息后推流,如果推流失败再广播失败的消息
//广播消息
this.sendPublishMessage2sdk(publishResult);
//推流
this.publishVideoAudio(publishResult);
} else if (publishResult.code == 1) {
loger.log("获取推流地址失败==>", publishResult);
if (this.flashCallback) {
this.flashCallback({
type: FlashToolComponet.TYPE_106
});
}
}
}
}
//发送推流成功的消息给SDK
sendPublishMessage2sdk(_data) {
if (!_data) {
loger.warn("发送推流消息给SDK失败->数据无效", _data);
return;
}
loger.log("发送推流成功的消息给SDK", _data);
let _successErrorResult = null;
this.publishType = _data.mediaType;
if (_data.mediaType == FlashToolComponet.AUDIO) {
_successErrorResult = xdysdk.api("publishAudio", _data);
} else {
_successErrorResult = xdysdk.api("publishVideo", _data);
}
this.isInPublish = true;
if (_successErrorResult.code == 0) {
loger.log("flash推流成功-->同步消息成功");
if (this.flashCallback) {
this.flashCallback({
type: FlashToolComponet.TYPE_10
});
}
} else if (_successErrorResult.code == 1) {
loger.log("flash推流成功-->同步消息失败-->关闭推流");
//this.stopMedia(_callbackMsgObj.data.mediaId);
this.dispatchClickStopPublish(_data);
}
}
//获取音视频推流地址
getPublishPath(_param) {
let result = {};
if (_param.mediaType == FlashToolComponet.AUDIO) {
result = xdysdk.api("getAudioPublishPath", {"type": "live"});
result.isPublishVideo = false;
result.isPublishAudio = true;
} else {
result = xdysdk.api("getVideoPublishPath", {"type": "live"});
result.isPublishVideo = true;
result.isPublishAudio = true;
}
result.mediaType = _param.mediaType;
console.log("获取音视频推流地址->", result);
return result;
}
//开始推流 _isPublishVideo(是否包含视频);_isPublishAudio(是否包含音频)
startPublishMediaStream(_data) {
if (!_data) {
loger.log("startPublishMediaStream->参数错误:", _data);
}
this.mediaType = _data.mediaType;
this.nodeId = _data.nodeId || 0;
this.userRole = _data.userRole || 'normal';
if (this.mediaType == FlashToolComponet.AUDIO) {
this.isPublishVideo = false;
this.isPublishAudio = true;
this.publishResult = xdysdk.api("getAudioPublishPath", {"type": "live"});
} else {
this.isPublishVideo = true;
this.isPublishAudio = true;
this.publishResult = xdysdk.api("getVideoPublishPath", {"type": "live"});
}
//loger.log("getVideoPublishPath->", this.publishResult);
//code为0,代表成功
if (this.publishResult.code == 0) {
if (this.flashObj) {
//loger.log("已经创建了flashObj");
this.publishURL(this.publishResult.mediaId, this.publishResult.publishUrl);
} else {
this._checkFlashPlugings();
}
} else if (this.publishResult.code == 1) {
loger.log("获取推流地址失败==>", this.publishResult.data);
}
}
//推流
publishVideoAudio(_publishData) {
/* code:0
data:""
isPublishAudio:true
isPublishVideo:true
mediaId:983041
publishUrl:"rtmp://123.56.69.230:7080/live/h5dev_1299232248_8ab3b0ed5a3a92200ee_983041_1499767762"
userId:"8ab3b0ed5a3a92200ee"
userName:"base"
userRole:"host"*/
this._checkFlashPlugings();
loger.warn("当前推流数据->_publishData->", _publishData);
this.js2native({
type: FlashToolComponet.TYPE_10,
data: {
fps: FlashToolComponet.videoInfo.fps || 15,
gop: FlashToolComponet.videoInfo.gop || 3,
videoQuality: FlashToolComponet.videoInfo.videoQuality,
curVideoQuality: FlashToolComponet.videoInfo.curVideoQuality,
cameraName: FlashToolComponet.userDeviceInfo.deviceInfo.curCamera,
microphoneName: FlashToolComponet.userDeviceInfo.deviceInfo.curMicrophone,
speakerVolume: FlashToolComponet.userDeviceInfo.deviceInfo.speakerVolume,
micCode: FlashToolComponet.userDeviceInfo.deviceInfo.micCode,
micGain: FlashToolComponet.userDeviceInfo.deviceInfo.micGain,
micNoise: FlashToolComponet.userDeviceInfo.deviceInfo.micNoise,
autoGain: FlashToolComponet.userDeviceInfo.deviceInfo.autoGain,
video: _publishData.isPublishVideo,
audio: _publishData.isPublishAudio,
url: _publishData.publishUrl,
mediaId: _publishData.mediaId,
mediaType: _publishData.mediaType,
userName: _publishData.userName,
userId: _publishData.userId,
userRole: _publishData.userRole,
nodeId: _publishData.nodeId,
playerId: _publishData.playerId
}
})
}
//推流
publishURL(_mediaId, rtmpURL, _mediaType, _isPublishVideo = true, _isPublishAudio = true) {
if (this.flashObj._js2native) {
this.mediaId = _mediaId;
this.rtmpURL = rtmpURL;
loger.warn("当前推流地址->publishURL->", this.rtmpURL);
this.js2native({
type: FlashToolComponet.TYPE_10,
data: {
fps: FlashToolComponet.videoInfo.fps || 15,
gop: FlashToolComponet.videoInfo.gop || 3,
videoQuality: FlashToolComponet.videoInfo.videoQuality,
curVideoQuality: FlashToolComponet.videoInfo.curVideoQuality,
cameraName: FlashToolComponet.userDeviceInfo.deviceInfo.curCamera,
microphoneName: FlashToolComponet.userDeviceInfo.deviceInfo.curMicrophone,
speakerVolume: FlashToolComponet.userDeviceInfo.deviceInfo.speakerVolume,
micCode: FlashToolComponet.userDeviceInfo.deviceInfo.micCode,
micGain: FlashToolComponet.userDeviceInfo.deviceInfo.micGain,
micNoise: FlashToolComponet.userDeviceInfo.deviceInfo.micNoise,
autoGain: FlashToolComponet.userDeviceInfo.deviceInfo.autoGain,
video: _isPublishVideo,
audio: _isPublishAudio,
url: rtmpURL,
mediaId: _mediaId,
mediaType: _mediaType,
userName: this.userName,
userId: this.userId,
userRole: this.userRole
}
})
} else {
this.rtmpURL = '';
this.mediaId = 0;
this.nodeId = 0;
loger.log("publishURL->_js2native无效");
}
}
//设置flash的播放器的数据
setVideoConfigData() {
this.js2native({
type: FlashToolComponet.TYPE_4,
data: {
backgroundColor: this.backgroundColor,
leftGap: this.leftGap,
topGap: this.topGap,
layoutGapV: this.layoutGapV,
layoutGapH: this.layoutGapH,
layoutType: this.layoutType,
videoImage: this.videoImage,
audioImage: this.audioImage,
audioBtnImage: this.audioBtnImage,
videoBtnImage: this.videoBtnImage,
stopPublishImage: this.stopPublishImage,
playersDataList: this.playersDataList,
autoShowLayout: this.autoShowLayout
}
});
}
//设备信息发生改变,设置flash播放器设备信息
setFlashDeviceInfo(_userDeviceInfo) {
this.js2native({
type: FlashToolComponet.TYPE_9,
data: {
isRepublish: FlashToolComponet.isRepublish,
url: this.rtmpURL,
userDeviceInfo: _userDeviceInfo
}
});
}
//播放音视频
playMedia(_data) {
if (!_data) {
loger.warn("playMedia->参数错误", _data);
return;
}
this.rtmpURL = _data.rtmpUrl;
this.mediaId = _data.mediaId;
this.mediaType = _data.mediaType || FlashToolComponet.VIDEO;
this.nodeId = _data.nodeId || 0;
this.userRole = _data.userRole || 'normal';
this.userId = _data.userId || '0';
this.userName = _data.userName || '';
this.screenWidth = _data.screenWidth || 0;
this.screenHeight = _data.screenHeight || 0;
this.showFullBtn = _data.showFullBtn || false;
let deviceType = 0;//默认按PC的处理
if (_data.deviceType == 0) {
deviceType = 0;
} else {
deviceType = parseInt(_data.deviceType);//按移动设备的推流处理
}
if (!this.rtmpURL) {
loger.log("播放音视频->失败->地址无效", this.rtmpURL);
return;
}
if (this.flashObj) {
loger.warn("当前播放音视频======>");
this.js2native({
type: FlashToolComponet.TYPE_2,
data: {
fps: FlashToolComponet.videoInfo.fps || 15,
gop: FlashToolComponet.videoInfo.gop || 3,
videoQuality: FlashToolComponet.videoInfo.videoQuality,
curVideoQuality: FlashToolComponet.videoInfo.curVideoQuality,
cameraName: FlashToolComponet.userDeviceInfo.deviceInfo.curCamera,
microphoneName: FlashToolComponet.userDeviceInfo.deviceInfo.curMicrophone,
speakerVolume: FlashToolComponet.userDeviceInfo.deviceInfo.speakerVolume || 80,
micCode: FlashToolComponet.userDeviceInfo.deviceInfo.micCode,
micGain: FlashToolComponet.userDeviceInfo.deviceInfo.micGain,
micNoise: FlashToolComponet.userDeviceInfo.deviceInfo.micNoise,
autoGain: FlashToolComponet.userDeviceInfo.deviceInfo.autoGain,
url: this.rtmpURL,
mediaType: this.mediaType,
mediaId: this.mediaId,
//播放的媒体的宽高,屏幕共享的时候需要这两个参数
screenWidth: this.screenWidth,
screenHeight: this.screenHeight,
showFullBtn: this.showFullBtn,//是否显示全屏控制的按钮
userName: this.userName,
userId: this.userId,
nodeId: this.nodeId || 0,
userRole: this.userRole,
deviceType: deviceType,
optionJsonData: _data.optionJsonData
}
});
} else {
loger.warn(this.swfUrl, "播放音视频->flashObj->没有创建->请检查浏览器是否禁用了flash或者禁止弹框,设置之后再重新打开网页!");
this._checkFlashPlugings();
this.historyPlayDataList[this.mediaId] = {
rtmpURL: this.rtmpURL,
mediaId: this.mediaId,
mediaType: this.mediaType || FlashToolComponet.VIDEO,
nodeId: this.nodeId || 0,
userRole: this.userRole || 'normal',
screenWidth: this.screenWidth || 0,
screenHeight: this.screenHeight || 0,
showFullBtn: this.showFullBtn || false,
status: this.status || 1,
seek: this.seek || 0,
mediaVolume: this.mediaVolume || 0,
deviceType: deviceType,
optionJsonData: _data.optionJsonData
}
}
}
//播放媒体文件
playMediaUrl(_data) {
if (!_data) {
loger.warn("播放媒体文件->参数错误", _data);
return;
}
this.rtmpURL = _data.rtmpUrl;
this.mediaId = _data.mediaId;
this.mediaType = _data.mediaType || FlashToolComponet.VIDEO;
this.nodeId = _data.nodeId || 0;
this.userRole = _data.userRole || 'normal';
this.screenWidth = _data.screenWidth || 0;
this.screenHeight = _data.screenHeight || 0;
this.showFullBtn = _data.showFullBtn || false;
this.status = _data.status || 1;
this.seek = _data.seek || 0;
this.mediaVolume = _data.mediaVolume || 0;//媒体音量
if (!this.rtmpURL) {
loger.log("播放媒体文件->失败->地址无效", this.rtmpURL);
return;
}
if (this.flashObj) {
loger.warn("当前播放媒体文件======>");
this.js2native({
type: FlashToolComponet.TYPE_18,
data: {
fps: FlashToolComponet.videoInfo.fps || 15,
gop: FlashToolComponet.videoInfo.gop || 3,
videoQuality: FlashToolComponet.videoInfo.videoQuality,
curVideoQuality: FlashToolComponet.videoInfo.curVideoQuality,
cameraName: FlashToolComponet.userDeviceInfo.deviceInfo.curCamera,
microphoneName: FlashToolComponet.userDeviceInfo.deviceInfo.curMicrophone,
speakerVolume: FlashToolComponet.userDeviceInfo.deviceInfo.speakerVolume || 80,
micCode: FlashToolComponet.userDeviceInfo.deviceInfo.micCode,
micGain: FlashToolComponet.userDeviceInfo.deviceInfo.micGain,
micNoise: FlashToolComponet.userDeviceInfo.deviceInfo.micNoise,
autoGain: FlashToolComponet.userDeviceInfo.deviceInfo.autoGain,
url: this.rtmpURL,
mediaType: this.mediaType,
status: this.status,
seek: this.seek,
mediaVolume: this.mediaVolume,
//播放的媒体的宽高,屏幕共享的时候需要这两个参数
screenWidth: this.screenWidth,
screenHeight: this.screenHeight,
showFullBtn: this.showFullBtn //是否显示全屏控制的按钮
}
})
} else {
loger.warn(this.swfUrl, "播放音视频->flashObj->没有创建->请检查浏览器是否禁用了flash或者禁止弹框,设置之后再重新打开网页!");
this.historyPlayDataList[this.mediaId] = {
rtmpURL: this.rtmpURL,
mediaId: this.mediaId,
mediaType: this.mediaType || FlashToolComponet.VIDEO,
nodeId: this.nodeId || 0,
userRole: this.userRole || 'normal',
screenWidth: this.screenWidth || 0,
screenHeight: this.screenHeight || 0,
showFullBtn: this.showFullBtn || false,
status: this.status || 1,
seek: this.seek || 0,
mediaVolume: this.mediaVolume || 0
}
}
}
//停止flash中播放器-/播流/媒体播放...
stopFlashPlay(_data) {
loger.log("flash停止推流或播放->", _data);
this.js2native({
type: FlashToolComponet.TYPE_5,
data: _data
});
}
////停止推流或播放(旧版接口)
//stopMedia(_mediaId) {
// if (!this.rtmpURL) {
// loger.warn("停止推流或播放-->当前没有在播放或推流->不需要停止", this.rtmpURL);
// return;
// }
// if (_mediaId != this.mediaId) {
// loger.warn("停止推流或播放-->mediaId不正确->不需要停止", _mediaId, this.mediaId);
// return;
// }
// this.rtmpURL = '';
// this.mediaId = 0;
// this.nodeId = 0;
// this.screenWidth = 0;
// this.screenHeight = 0;
// this.showFullBtn = false;
//
// loger.log("stopMedia->清除数据>");
// //this._checkFlashPlugings();
// this.js2native({
// type: FlashToolComponet.TYPE_5,
// data: {
// mediaId: 0,
// nodeId: 0
// }
// });
// delete this.historyPlayDataList[_mediaId];
//}
//设置背景图片
setPoster(_videoImage, audioImage) {
console.log(this.swfUrl + '->setPoster');
if (!_videoImage) {
loger.log("设置播放器图片->地址无效", _videoImage);
}
if (!audioImage) {
loger.log("设置播放器图片->地址无效", audioImage);
}
if (this.flashObj) {
this.js2native({
type: FlashToolComponet.TYPE_11,
data: {
videoImage: _videoImage,
audioImage: audioImage
}
});
} else {
loger.log("设置播放器图片->失败->播放器对象不存在");
}
}
//获取文档note信息 8a2589d656c3d3120156c4d28ea70652
getDocNoteInfo(_docId, callback) {
this.docNoteCallback = callback;
this._checkFlashPlugings();
if (this.flashObj) {
this.js2native({
type: FlashToolComponet.TYPE_1,
data: {
docId: _docId,
}
});
} else {
loger.log("获取文档note信息->失败->FLASH对象不存在");
if (this.docNoteCallback) {
this.docNoteCallback({docId: "", docNoteArr: []});
}
}
}
//测试ms网速
flashTestMsBW(_msTestData) {
loger.log('测试ms网速', _msTestData);
this._checkFlashPlugings();
if (this.flashObj) {
this.js2native({
type: FlashToolComponet.TYPE_16,
data: {
msTestData: _msTestData.data
}
});
} else {
loger.log("测试ms网速->失败->FLASH对象不存在");
}
}
//显示MS测速结果
flashShowMsTestBWcallBack(_param) {
loger.log("显示MS测速结果");
H5Seting.updateMsDetection(_param.data.data);
}
//自己的设置设备信息
flashSetingDeviceOnsSelf(_userInfo, _callback) {
console.log('flashSetingDeviceOnsSelf-', _userInfo);
this.onselfFlashSettingCallback = _callback;
this.otherFlashSettingCallback = null;
if (this.flashObj) {
let info = "";
/* try {
info = JSON.stringify({
type: FlashToolComponet.TYPE_12,
data: {
nodeData: _userInfo.nodeData //用本地的数据
}
});
} catch (err) {
loger.warn("开始自己的设备设置->JOSN转换失败", err);
}
console.log("开始自己的设备设置->", info);
if (this.flashObj._js2native) {
this.flashObj._js2native(info);
}*/
this.js2native({
type: FlashToolComponet.TYPE_12,
data: {
nodeData: _userInfo.nodeData //用本地的数据
}
})
//打开自己设置面板的时候开启音视频检测
if (FlashToolComponet.flashPlayerSwf) {
loger.log("打开自己设置面板的时候开启音视频检测");
FlashToolComponet.flashPlayerSwf.openCamera("", "", 200, true, 160, 120);
FlashToolComponet.flashPlayerSwf.openMicrophone();
} else {
loger.warn("打开自己设置面板的时候开启音视频检测->失败->flashPlayerSwf", FlashToolComponet.flashPlayerSwf);
}
} else {
loger.log("自己的设备设置->失败->FLASH对象不存在");
}
}
//其他人的设置设备信息
flashSetingDeviceOther(_userInfo, _callback) {
console.log('flashSetingDeviceOther-', _userInfo);
this.otherFlashSettingCallback = _callback;
this.onselfFlashSettingCallback = null;
this.js2native({
type: FlashToolComponet.TYPE_13,
data: {
nodeData: _userInfo.nodeData
}
});
/* if (this.flashObj) {
let info = JSON.stringify({
type: FlashToolComponet.TYPE_13,
data: {
nodeData: _userInfo.nodeData
}
});
loger.log("设置其他人设备设置->");
if (this.flashObj._js2native) {
this.flashObj._js2native(info);
}
} else {
loger.log("设置其他人设备设置->失败->FLASH对象不存在");
}*/
}
//打开摄像头获取图像
openCamera(_imageBase64Str, _cameraName, _delay, _isShow, _width, _height) {
this._checkFlashPlugings();
this.js2native({
type: FlashToolComponet.TYPE_40,
data: {
cameraName: _cameraName || "",
imageBase64Str: _imageBase64Str || "",
delay: _delay || 400,
isShow: _isShow,
width: _width || 160,
height: _height || 120
}
});
/* if (this.flashObj) {
let info = JSON.stringify({
type: FlashToolComponet.TYPE_40,
data: {
cameraName: _cameraName || "",
imageBase64Str: _imageBase64Str || "",
delay: _delay || 400,
isShow: _isShow,
width: _width || 160,
height: _height || 120
}
});
//loger.log("打开摄像头->");
if (this.flashObj._js2native) {
this.flashObj._js2native(info);
}
} else {
loger.log("打开摄像头->失败->FLASH对象不存在");
}*/
}
//停止摄像头更新图像
closeCamera(_data) {
this.js2native({
type: FlashToolComponet.TYPE_41,
data: {
cameraName: ""
}
});
/* if (this.flashObj) {
let info = JSON.stringify({
type: FlashToolComponet.TYPE_41,
data: {
cameraName: ""
}
});
loger.log("停止摄像头->");
if (this.flashObj._js2native) {
this.flashObj._js2native(info);
}
} else {
loger.log("停止摄像头->失败->FLASH对象不存在");
}*/
}
//打开麦克风检测音量
openMicrophone(_micName, _micGain) {
this._checkFlashPlugings();
this.js2native({
type: FlashToolComponet.TYPE_50,
data: {
micName: _micName || "",
micGain: parseInt(_micGain) || 0
}
});
/* if (this.flashObj) {
let info = JSON.stringify({
type: FlashToolComponet.TYPE_50,
data: {
micName: _micName || "",
micGain: parseInt(_micGain) || 0
}
});
//loger.log("打开摄像头->");
if (this.flashObj._js2native) {
this.flashObj._js2native(info);
}
} else {
loger.log("打开麦克风检测音量->失败->FLASH对象不存在");
}*/
}
//停止麦克风检测音量
closeMicrophone(_data) {
this.js2native({
type: FlashToolComponet.TYPE_51,
data: {
micName: ""
}
});
/* if (this.flashObj) {
let info = JSON.stringify({
type: FlashToolComponet.TYPE_51,
data: {
micName: ""
}
});
loger.log("停止麦克风检测音量->");
if (this.flashObj._js2native) {
this.flashObj._js2native(info);
}
} else {
loger.log("停止麦克风检测音量->失败->FLASH对象不存在");
}*/
}
//显示当前麦克风音量
showMicrophoneLevel(_activityLevel) {
this._checkFlashPlugings();
this.js2native({
type: FlashToolComponet.TYPE_52,
data: {
activityLevel: _activityLevel || 0
}
});
/*if (this.flashObj) {
let info = JSON.stringify({
type: FlashToolComponet.TYPE_52,
data: {
activityLevel: _activityLevel || 0
}
});
//loger.log("打开摄像头->");
if (this.flashObj._js2native) {
this.flashObj._js2native(info);
}
} else {
loger.log("显示当前麦克风音量->失败->FLASH对象不存在");
}*/
}
//打开扬声器检测音量
openSpeakerTest(_musicUrl, _micGain) {
this._checkFlashPlugings();
this.js2native({
type: FlashToolComponet.TYPE_60,
data: {
musicUrl: _musicUrl || "sound.mp3",
micGain: _micGain || 50
}
});
/* if (this.flashObj) {
let info = JSON.stringify({
type: FlashToolComponet.TYPE_60,
data: {
musicUrl: _musicUrl || "sound.mp3",
micGain: _micGain || 50
}
});
//loger.log("打开摄像头->");
if (this.flashObj._js2native) {
this.flashObj._js2native(info);
}
} else {
loger.log("打开扬声器检测音量->失败->FLASH对象不存在");
}*/
}
//停止扬声器检测
closeSpeakerTest() {
this.js2native({
type: FlashToolComponet.TYPE_61,
data: {
micName: ""
}
});
/* if (this.flashObj) {
let info = JSON.stringify({
type: FlashToolComponet.TYPE_61,
data: {
micName: ""
}
});
loger.log("停止扬声器检测音量->");
if (this.flashObj._js2native) {
this.flashObj._js2native(info);
}
} else {
loger.log("停止扬声器检测音量->失败->FLASH对象不存在");
}*/
}
//显示当前麦克风音量
showSpeakerLevel(_activityLevel) {
this.js2native({
type: FlashToolComponet.TYPE_52,
data: {
activityLevel: _activityLevel || 0
}
});
/* if (this.flashObj) {
let info = JSON.stringify({
type: FlashToolComponet.TYPE_52,
data: {
activityLevel: _activityLevel || 0
}
});
//loger.log("打开摄像头->");
if (this.flashObj._js2native) {
this.flashObj._js2native(info);
}
} else {
loger.log("显示当前麦克风音量->失败->FLASH对象不存在");
}*/
}
_checkFlashPlugings() {
//检查flash插件是否被禁用并弹出提示
if (!this.flashObj) {
loger.warn("flashObj->没有创建->请检查浏览器是否禁用了flash或者禁止弹框,设置之后再重新打开网页!");
if (this.flashCallback) {
this.flashCallback({
type: FlashToolComponet.TYPE_30
});
}
return false;
} else {
return true;
}
}
}
FlashToolComponet.isRepublish = true;
FlashToolComponet.isFlashGetDefaultSetting = false;//flash是否获取默认设置完成
FlashToolComponet.list = {};//页面所有flash文件列表
FlashToolComponet.flashSetingToolsSwf = null;
FlashToolComponet.flashPlayerSwf = null;
FlashToolComponet.userDeviceInfo = {
"actionType": "",
"nodeData": {},
"deviceInfo": {
"cameras": [],
"curMicrophone": "",
"microphones": [],
"curCamera": "",
"micCode": 0,
"fps": 15,
"speakerVolume": 80,
"micGain": 70,
"micNoise": 70,
"autoGain": true,
"gop": 3,
"videoQuality": 1,//默认值
"curVideoQuality": 1 //默认值
}
};
FlashToolComponet.videoInfo = {
"micGain": 70,
"micNoise": 70,
"autoGain": true,
"gop": 3,
"videoQuality": 1,//默认值
"curVideoQuality": 1 //默认值
};
FlashToolComponet.prototype.TYPE_0 = FlashToolComponet.TYPE_0 = 0;//FLASH创建完成(所有设置完成)
FlashToolComponet.prototype.TYPE_1 = FlashToolComponet.TYPE_1 = 1;//获取文档note信息
FlashToolComponet.prototype.TYPE_2 = FlashToolComponet.TYPE_2 = 2;//播放音视频
FlashToolComponet.prototype.TYPE_3 = FlashToolComponet.TYPE_3 = 3;//flash->loading完成
FlashToolComponet.prototype.TYPE_4 = FlashToolComponet.TYPE_4 = 4;//设置flash的播放器布局
FlashToolComponet.prototype.TYPE_5 = FlashToolComponet.TYPE_5 = 5;//停止音视频/推流
FlashToolComponet.prototype.TYPE_9 = FlashToolComponet.TYPE_9 = 9;//设备信息发生改变-
FlashToolComponet.prototype.TYPE_10 = FlashToolComponet.TYPE_10 = 10;//推流
FlashToolComponet.prototype.TYPE_11 = FlashToolComponet.TYPE_11 = 11;//设置flash背景图片
FlashToolComponet.prototype.TYPE_12 = FlashToolComponet.TYPE_12 = 12;//设置自己的设备
FlashToolComponet.prototype.TYPE_13 = FlashToolComponet.TYPE_13 = 13;//设置别人的设备
FlashToolComponet.prototype.TYPE_14 = FlashToolComponet.TYPE_14 = 14;//设置窗口关闭
FlashToolComponet.prototype.TYPE_15 = FlashToolComponet.TYPE_15 = 15;//返回当前设备的系统信息(摄像头、麦克风...)
FlashToolComponet.prototype.TYPE_16 = FlashToolComponet.TYPE_16 = 16;//MS网络测速,flash发送给js消息去测速
FlashToolComponet.prototype.TYPE_17 = FlashToolComponet.TYPE_17 = 17;//MS网络测速,js测速完成发送结果给flash
FlashToolComponet.prototype.TYPE_18 = FlashToolComponet.TYPE_18 = 18;//播放媒体文件
FlashToolComponet.prototype.TYPE_20 = FlashToolComponet.TYPE_20 = 20;//摄像头麦克风权限被禁
FlashToolComponet.prototype.TYPE_21 = FlashToolComponet.TYPE_21 = 21;//音量检测
FlashToolComponet.prototype.TYPE_22 = FlashToolComponet.TYPE_22 = 22;//重新推流
FlashToolComponet.prototype.TYPE_24 = FlashToolComponet.TYPE_24 = 24;//摄像头获取失败
FlashToolComponet.prototype.TYPE_25 = FlashToolComponet.TYPE_25 = 25;//麦克风获取失败
FlashToolComponet.prototype.TYPE_26 = FlashToolComponet.TYPE_26 = 26;//没有摄像头
FlashToolComponet.prototype.TYPE_27 = FlashToolComponet.TYPE_27 = 27;//摄像头占用
FlashToolComponet.prototype.TYPE_28 = FlashToolComponet.TYPE_28 = 28;//没有麦克风
FlashToolComponet.prototype.TYPE_29 = FlashToolComponet.TYPE_29 = 29;//麦克风被占用
FlashToolComponet.prototype.TYPE_30 = FlashToolComponet.TYPE_30 = 30;//flash插件被禁用
FlashToolComponet.prototype.TYPE_31 = FlashToolComponet.TYPE_31 = 31;//摄像头和麦克风权限已经允许
FlashToolComponet.prototype.TYPE_40 = FlashToolComponet.TYPE_40 = 40;//打开摄像头
FlashToolComponet.prototype.TYPE_41 = FlashToolComponet.TYPE_41 = 41;//关闭摄像头
FlashToolComponet.prototype.TYPE_42 = FlashToolComponet.TYPE_42 = 42;//显示摄像头图像
FlashToolComponet.prototype.TYPE_50 = FlashToolComponet.TYPE_50 = 50;//开始麦克风检测
FlashToolComponet.prototype.TYPE_51 = FlashToolComponet.TYPE_51 = 51;//停止麦克风检测
FlashToolComponet.prototype.TYPE_52 = FlashToolComponet.TYPE_52 = 52;//更新麦克风数据
FlashToolComponet.prototype.TYPE_60 = FlashToolComponet.TYPE_60 = 60;//开始测试音检测
FlashToolComponet.prototype.TYPE_61 = FlashToolComponet.TYPE_61 = 61;//停止测试音检测
FlashToolComponet.prototype.TYPE_62 = FlashToolComponet.TYPE_62 = 62;//更新测试音数据
FlashToolComponet.prototype.TYPE_101 = FlashToolComponet.TYPE_101 = 101;//点击视频推流按钮
FlashToolComponet.prototype.TYPE_102 = FlashToolComponet.TYPE_102 = 102;//点击音频推流按钮
FlashToolComponet.prototype.TYPE_103 = FlashToolComponet.TYPE_103 = 103;//点击停止推流
FlashToolComponet.prototype.TYPE_104 = FlashToolComponet.TYPE_104 = 104;//停止播放
FlashToolComponet.prototype.TYPE_105 = FlashToolComponet.TYPE_105 = 105;//推流时发现没有空闲的播放器
FlashToolComponet.prototype.TYPE_106 = FlashToolComponet.TYPE_106 = 106;//不能再打开更多设备
FlashToolComponet.prototype.CHANGE_CAMERA = FlashToolComponet.CHANGE_CAMERA = "changeCamera";//
FlashToolComponet.prototype.CHANGE_MICROPHONE = FlashToolComponet.CHANGE_MICROPHONE = "changeMicrophone";//
FlashToolComponet.prototype.CHANGE_RESOLUTION = FlashToolComponet.CHANGE_RESOLUTION = "changeResolution";//
FlashToolComponet.prototype.CHANGE_SPEAKER_VOLUME = FlashToolComponet.CHANGE_SPEAKER_VOLUME = "changeSpeakerVolume";//
FlashToolComponet.prototype.CHANGE_MICROPHONE_GAIN = FlashToolComponet.CHANGE_MICROPHONE_GAIN = "changeMicrophoneGain";//
FlashToolComponet.prototype.CHANGE_MICROPHONE_CODE = FlashToolComponet.CHANGE_MICROPHONE_CODE = "changeMicrophoneCode";
FlashToolComponet.prototype.CHANGE_MICROPHONE_NOISE = FlashToolComponet.CHANGE_MICROPHONE_NOISE = "changeMicrophoneNoise";
FlashToolComponet.prototype.CHANGE_MICROPHONE_AUTO_GAIN = FlashToolComponet.CHANGE_MICROPHONE_AUTO_GAIN = "changeMicrophoneAutoGain";
FlashToolComponet.prototype.AUDIO = FlashToolComponet.AUDIO = "audio";
FlashToolComponet.prototype.VIDEO = FlashToolComponet.VIDEO = "video";
FlashToolComponet.prototype.MEDIA_SHARE = FlashToolComponet.MEDIA_SHARE = "media_share";
FlashToolComponet.prototype.SCREEN_SHARE = FlashToolComponet.SCREEN_SHARE = "screen_share";
FlashToolComponet.prototype.AUDIO = FlashToolComponet.AUDIO = "audio";
FlashToolComponet.prototype.AUDIO = FlashToolComponet.AUDIO = "audio";
FlashToolComponet.prototype.LAYOUT_V = FlashToolComponet.LAYOUT_V = "V";//垂直布局
FlashToolComponet.prototype.LAYOUT_H = FlashToolComponet.LAYOUT_H = "H";//水平布局
FlashToolComponet.prototype.LAYOUT_GAP_H = FlashToolComponet.LAYOUT_GAP_H = 6;//水平方向的间隔
FlashToolComponet.prototype.LAYOUT_GAP_V = FlashToolComponet.LAYOUT_GAP_V = 6;//垂直方向的间隔
FlashToolComponet.prototype.LEFT_GAP = FlashToolComponet.LEFT_GAP = 0;//顶部距离
FlashToolComponet.prototype.TOP_GAP = FlashToolComponet.TOP_GAP = 0;//底部距离
export default FlashToolComponet;