index.js
2.4 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
import ProtoBuf from 'protobufjs';
import pro from './pro';
import PduType from './PduType';
import PduConsts from './PduConsts';
let builder = ProtoBuf.newBuilder({ convertFieldsToCamelCase: true });
ProtoBuf.loadProto(pro, builder);
let pdu = builder.build();
// 底层通信层[Firstlayer] - RCSendDataPdu封包
function create_pdu(type, sub_type,
initiator, conference_id, session_id,
channel_id, upward, reliability, priority,
peer, seg) {
var pduMsg = new pdu['RCSendDataPdu']();
pduMsg.set("type", type);
pduMsg.set("subType", sub_type);
pduMsg.set("initiator", initiator);
pduMsg.set("confId", conference_id);//***confId mcu服务用的是这个字段,客户端在其他地方统一为classId
pduMsg.set("sessionId", session_id);
pduMsg.set("channelId", channel_id);
pduMsg.set("upward", upward);
pduMsg.set("reliability", reliability);
pduMsg.set("priority", priority);
pduMsg.set("peer", peer);
pduMsg.set("seg", seg);
return pduMsg;
}
// 底层通信层[Firstlayer] - RCSendDataPdu解包
pdu.decode_pdu = function (buffer) {
return pdu['RCSendDataPdu'].decode(buffer);
};
pdu.create_join_class_request_pdu = function (
sub_type,
initiator,
conference_id,
session_id,
channel_id,
reliability,
priority,
peer,
seg
) {
return create_pdu(PduType.RCPDU_CONNECT_PROVIDER_REQUEST,
sub_type, initiator, conference_id, session_id, channel_id, true,
reliability, priority, peer, seg);
};
//upward 是否向顶层抛 create_uniform_pdu默认为true
pdu.create_uniform_pdu = function (
sub_type,
initiator,
conference_id,
session_id,
channel_id,
reliability,
priority,
peer,
seg
) {
return create_pdu(PduType.RCPDU_UNIFORM_SEND_DATA_REQUEST,
sub_type, initiator, conference_id, session_id, channel_id, true,
reliability, priority, peer, seg);
};
//upward 是否向顶层抛 create_normal_pdu 中由外部定义
pdu.create_normal_pdu = function (
sub_type,
initiator,
conference_id,
session_id,
channel_id,
upward,
reliability,
priority,
peer,
seg
) {
return create_pdu(PduType.RCPDU_SEND_DATA_REQUEST,
sub_type, initiator, conference_id, session_id, channel_id, upward,
reliability, priority, peer, seg);
};
pdu.id2type = function (id) {
for (var type_const in PduType) {
if (PduType[type_const] === id) {
return type_const;
}
}
};
// 合并统一对外
pdu = {...pdu, ...PduType, ...PduConsts };
export default pdu;