util.js
4.15 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
//操作媒体或者屏幕共享
//roomHandle -> pluginHandle
//media -> 媒体参数
//publish -> 确认参数
//errMethod -> 失败函数执行
optionMedia = function (roomHandle, media, publish, errMethod) {
roomHandle.createOffer({
media: media,
simulcast: false,
simulcast2: false,
success: function(jsep) {
roomHandle.send({"message": publish, "jsep": jsep});
},
error: function(error) {
errMethod();
}
});
}
//销毁
//roomHandle -> pluginHandle
//room -> 房间号码
//pin -> 设置的操作密码
optionDestroy = function(roomHandle, room, pin) {
var destroy = {"request" : "destroy","room": room, "secret": pin}
roomHandle.send({"message": destroy, success: function(result) {
}})
}
//在线人数
//roomHandle -> pluginHandle
//room -> 房间号码
//method -> 成功函数执行
listparticipants = function(roomHandle, room, method) {
var body = { "request" : "listparticipants", "room" : room};
roomHandle.send({"message": body, success: function(result) {
var event = result["participants"];
method(event);
}})
}
//初始化
//server -> 服务器地址
//janus -> 服务器会话
//succMethod -> 成功函数执行
//errMethod -> 失败函数执行
//desMethod -> 销毁函数执行
init = function(server, janus, succMethod, errMethod, desMethod) {
Janus.init({debug: "all", callback: function() {
if(!Janus.isWebrtcSupported()) {
bootbox.alert("不支持WebRTC... ");
return;
}
janus = new Janus({
server: server,
success: function() {
succMethod(janus);
},
error: function(error) {
errMethod(error);
},
destroyed: function() {
desMethod();
}
})
}})
}
//创建句柄
//janus -> 服务器会话
//method -> 成功函数执行
attach = function(janus, method) {
janus.attach({
plugin: "janus.plugin.videoroom",
success: function(pluginHandle) {
method(pluginHandle);
}
})
}
//房间是否存在
//roomhandler -> pluginHandle
//room -> 房间号码
//method -> 成功函数执行
exit = function(roomhandler, room, method) {
var exits = {"request": "exists", "room": room};
roomhandler.send({"message": exits, success: function(result) {
var event = result["exists"];
method(event);
}})
}
//创建房间
//roomhandler -> pluginHandle
//create -> create参数
//method -> 成功函数执行
creatRoom = function(roomhandler, create, method) {
Janus.log("插件 (" + roomhandler.getPlugin() + ", id=" + roomhandler.getId() + ")");
roomhandler.send({"message": create, success: function(result) {
var event = result["videoroom"];
method(event);
}})
}
//房间集合
//roomhandler -> pluginHandle
//method -> 成功函数执行
list = function(roomhandler, method) {
var list = {"request": "list"};
roomhandler.send({"message": list, success: function(result) {
var event = result["list"];
method(event);
}
});
}
//创建会话
//janus -> 服务器会话
creatAttach = function(janus, succMethod, errMethod, conMethod, msMethod,
wsMethod,omMethod, olMethod, orMethod, ocMethod) {
janus.attach({
plugin: "janus.plugin.videoroom",
success: function(pluginHandle) {
succMethod(pluginHandle);
},
error: function(error) {
errMethod(error);
},
consentDialog: function(on) {
conMethod(on);
},
mediaState: function(medium, on) {
msMethod(medium, on);
},
webrtcState: function(on) {
wsMethod(on);
},
onmessage: function(msg, jsep) {
omMethod(msg, jsep);
},
onlocalstream: function(stream) {
olMethod(stream);
},
onremotestream: function(stream) {
orMethod(stream);
},
oncleanup: function() {
ocMethod();
}
})
}
//join会议
join = function(roomHandle, register) {
roomHandle.send({"message": register});
}
//configure
configure = function(roomHandle, bitrate) {
var configure = { "request": "configure", "bitrate": bitrate};
roomHandle.send({"message": configure});
}
opentionAnswer = function(roomHandle, jsep, media, succMethod, errMethod) {
roomHandle.createAnswer({
jsep: jsep,
media: media,
success: function(jsep) {
succMethod(jsep);
},
error: function(error) {
errMethod();
}
})
}
jsepSend = function(roomHandle, body, jsep) {
roomHandle.send({"message": body, "jsep": jsep});
}