说明

  • 大华视频会议系统支持 1 对 1 或 1 对多视频通话
  • 会议系统包括会议管理、设备管理等,设备支持软终端、硬终端等
  • 软终端支持 Android 等
  • 设备加入指定会议 ID 即可,自动开始视频会议「采用aar 集成方式」
  • Java 后端封装会议管理、设备管理等相关接口,并通过 websocket 向软终端发送会议提醒;软终端接收消息,加入会议

后端

VideoCall.java

封装了会话登录,会议创建、删除、分页获取,设备创建、修改、删除、分页获取接口

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
package com.bjtcrj.gms.system.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bjtcrj.gms.common.utils.MD5Util;
import lombok.Data;
import okhttp3.*;
import org.intellij.lang.annotations.Language;

import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import static okhttp3.RequestBody.create;

/**
* 视频会议接口工具
*/
@Data
public class VideoCall {
private static final MediaType JSONTYPE_X_WWW_FORM_URLENCODED = MediaType.get("application/x-www-form-urlencoded; charset=utf-8");

public static final String SERVER = "IP 地址";
public static final Integer PORT = 10555;
private static final String HTTP_SERVER = "http://" + SERVER;
private static final String LOGINURL = HTTP_SERVER + "/login"; //登录
private static final String CONFCREATE = HTTP_SERVER + "/post/conf/confCreate"; //创建会议
private static final String CONFGETBYPAGE = HTTP_SERVER + "/post/conf/confGetByPage"; //分页获取会议信息
private static final String CONFDEL = HTTP_SERVER + "/post/conf/confDel"; //删除会议

private static final String DEVICELIST = HTTP_SERVER + "/post/dev/devGetByPage"; //分页获取设备
private static final String DEVICECREATE = HTTP_SERVER + "/post/dev/devCreate"; //创建设备
private static final String DEVICEMODIFY = HTTP_SERVER + "/post/dev/devModify"; //修改设备
private static final String DEVICEDELETE = HTTP_SERVER + "/post/dev/devDel"; //删除设备

private static final String ADMIN = "admin";
private static final String PASSWORD = "admin123";

private String cookie = "";
private String body = "";
private Result result;

private static OkHttpClient client = new OkHttpClient.Builder()
.connectTimeout(10, TimeUnit.SECONDS)
.readTimeout(20, TimeUnit.SECONDS)
.writeTimeout(20, TimeUnit.SECONDS)
.build();

private static Integer nextId = 0;

// 30 软终端 ID 集合
static {
Result result = null;
result = devList(0, 100);
List<Device> devices = JSON.parseArray(result.getData(), Device.class);
for (Device device : devices) {
String devid = device.getDevid();
if (devid.startsWith("3000")) {
Integer dev = Integer.parseInt(devid);
if (dev > nextId) {
nextId = dev;
}
}
}
nextId++;
}

/**
* 获取设备 ID
*
* @return
*/
public static String getNextId() {
return nextId + "";
}

/**
* 设备 ID 增加
*/
public static void idNext() {
nextId++;
}

private static int getRandomConf() {
return (int) Math.round(Math.random() * 10000);
}

/**
* 创建会议
*
* @param name
* @return
* @throws IOException
*/
public static Result confCreate(String name, List<DeviceT> deviceTList) throws IOException {
String confId = null;
Set<Integer> allConfId = confList(0, 100);
/*if (allConfId == null || allConfId.size() == 0) {
int randomConf = getRandomConf();
confId = String.valueOf(randomConf);

VideoCall login = login();
if (login.result.getResult() != 1) {
//登录失败
return login.result;
}

//登录成功-创建会议
return confCreate(login.cookie, name, confId, deviceTList);
} else {
confId = String.valueOf(allConfId.iterator().next());

Result result = new Result();
result.setSuccess(true);
result.setConfId(confId);
return result;
}*/

int randomConf = getRandomConf();
while (allConfId.contains(randomConf)){
randomConf = getRandomConf();
}
confId = String.valueOf(randomConf);

VideoCall login = login();
if (login.result.getResult() != 1) {
//登录失败
return login.result;
}

//登录成功-创建会议
return confCreate(login.cookie, name, confId, deviceTList);
}

/**
* 分页获取设备
*
* @param page 当前页(从0开始, 0表示第一页)
* @param size 每页数量
* @return
* @throws IOException
*/
public static Result devList(Integer page, Integer size) {
VideoCall login = null;
try {
login = login();
if (login.result.getResult() != 1) {
//登录失败
return login.result;
}

//登录成功-设备列表
return devList(login.cookie, page, size);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}

/**
* 创建设备
*
* @param id
* @param name
* @param pasword
* @return
* @throws IOException
*/
public static Result devCreate(String id, String name, String pasword) throws IOException {
VideoCall login = login();
if (login.result.getResult() != 1) {
//登录失败
return login.result;
}

//登录成功-创建设备
return devCreate(login.cookie, id, name, pasword);
}

/**
* 修改设备
*
* @param id
* @param name
* @param pasword
* @return
* @throws IOException
*/
public static Result devModify(String id, String name, String pasword) throws IOException {
VideoCall login = login();
if (login.result.getResult() != 1) {
//登录失败
return login.result;
}

//登录成功-修改设备
return devModify(login.cookie, id, name, pasword);
}

/**
* 删除设备
*
* @param id
* @return
* @throws IOException
*/
public static Result devDelete(String id) throws IOException {
VideoCall login = login();
if (login.result.getResult() != 1) {
//登录失败
return login.result;
}

//登录成功-删除设备
return devDelete(login.cookie, id);
}

/**
* 登录接口
*
* @return
* @throws IOException
*/
public static VideoCall login() throws IOException {
JSONObject jsonObject = new JSONObject();
jsonObject.put("username", ADMIN);
jsonObject.put("password", MD5Util.md5(PASSWORD));
String data = "data=" + JSON.toJSONString(jsonObject);

RequestBody body = create(data, JSONTYPE_X_WWW_FORM_URLENCODED);
Request request = new Request.Builder()
.url(LOGINURL)
.post(body)
.build();
try (Response response = client.newCall(request).execute()) {
String setCookie = response.header("set-cookie");

VideoCall videoCall = new VideoCall();
videoCall.cookie = setCookie;
videoCall.body = response.body().string();
videoCall.result = JSON.parseObject(videoCall.body, Result.class);
if (videoCall.result.getResult() == 1) {
videoCall.result.setSuccess(true);
} else {
videoCall.result.setSuccess(false);
}
return videoCall;
}
}


private static final String[] layouts = {
//0
"[[0,0,0,1,1]]",
//2分割 1
"[[0,0.25,0,0.5,0.5],[0.5,0.25,0,0.5,0.5]]",
//3分割 2
"[[0.25,0,0,0.5,0.5],[0,0.5,0,0.5,0.5],[0.5,0.5,0,0.5,0.5]]",
//4分割 3
"[[0,0,0,0.5,0.5],[0.5,0,0,0.5,0.5],[0,0.5,0,0.5,0.5],[0.5,0.5,0,0.5,0.5]]",
//5分割 4
"[[0.125,0,0,0.75,0.75],[0,0.75,0,0.25,0.25],[0.25,0.75,0,0.25,0.25],[0.5,0.75,0,0.25,0.25],[0.75,0.75,0,0.25,0.25]]",
//6分割 5
"[[0,0,0,0.666,0.666],[0.666,0,0,0.333,0.333],[0.666,0.333,0,0.333,0.333],[0,0.666,0,0.333,0.333],[0.333,0.666,0,0.333,0.333],[0.666,0.666,0,0.333,0.333]]",
//7分割 6
"[[0,0,0,0.5,0.5],[0.5,0,0,0.5,0.5],[0,0.5,0,0.5,0.5],[0.5,0.5,0,0.25,0.25],[0.5,0.75,0,0.25,0.25],[0.75,0.5,0,0.25,0.25],[0.75,0.75,0,0.25,0.25]]",
//8分割 7
"[[0,0,0,0.75,0.75],[0.75,0,0,0.25,0.25],[0.75,0.25,0,0.25,0.25],[0.75,0.5,0,0.25,0.25],[0,0.75,0,0.25,0.25],[0.25,0.75,0,0.25,0.25],[0.5,0.75,0,0.25,0.25],[0.75,0.75,0,0.25,0.25]]",
//9分割 8
"[[0,0,0,0.333,0.333], [0,0.333,0,0.333,0.333],[0,0.666,0,0.333,0.333],[0.333,0,0,0.333,0.333],[0.333,0.333,0,0.333,0.333],[0.333,0.666,0,0.333,0.333],[0.666,0,0,0.333,0.333],[0.666,0.333,0,0.333,0.333],[0.666,0.666,0,0.333,0.333]]",
//10分割 9
"[[0,0,0,0.5,0.5],[0.5,0,0,0.5,0.5],[0,0.5,0,0.25,0.25],[0.25,0.5,0,0.25,0.25],[0.5,0.5,0,0.25,0.25],[0.75,0.5,0,0.25,0.25],[0,0.75,0,0.25,0.25],[0.25,0.75,0,0.25,0.25],[0.5,0.75,0,0.25,0.25],[0.75,0.75,0,0.25,0.25]]",
//13分割 10
"[[0,0,0,0.5,0.5],[0.5,0,0,0.25,0.25],[0.75,0,0,0.25,0.25],[0.5,0.25,0,0.25,0.25],[0.75,0.25,0,0.25,0.25],[0,0.5,0,0.25,0.25],[0.25,0.5,0,0.25,0.25],[0.5,0.5,0,0.25,0.25],[0.75,0.5,0,0.25,0.25],[0,0.75,0,0.25,0.25],[0.25,0.75,0,0.25,0.25],[0.5,0.75,0,0.25,0.25],[0.75,0.75,0,0.25,0.25]]",
//16分割 11
"[[0,0,0,0.25,0.25],[0.25,0,0,0.25,0.25],[0,0.25,0,0.25,0.25],[0.25,0.25,0,0.25,0.25], [0.5,0,0,0.25,0.25],[0.75,0,0,0.25,0.25],[0.5,0.25,0,0.25,0.25],[0.75,0.25,0,0.25,0.25], [0,0.5,0,0.25,0.25],[0.25,0.5,0,0.25,0.25],[0.5,0.5,0,0.25,0.25],[0.75,0.5,0,0.25,0.25], [0,0.75,0,0.25,0.25],[0.25,0.75,0,0.25,0.25],[0.5,0.75,0,0.25,0.25],[0.75,0.75,0,0.25,0.25]]",
//17分割 12
"[[0,0,0,0.6,0.6],[0,0.6,0,0.2,0.2],[0,0.8,0,0.2,0.2],[0.6,0,0,0.2,0.2],[0.6,0.2,0,0.2,0.2],[0.6,0.4,0,0.2,0.2],[0.6,0.6,0,0.2,0.2],[0.6,0.8,0,0.2,0.2], [0.8,0,0,0.2,0.2],[0.8,0.2,0,0.2,0.2],[0.8,0.4,0,0.2,0.2],[0.8,0.6,0,0.2,0.2],[0.8,0.8,0,0.2,0.2],[0.2,0.6,0,0.2,0.2],[0.2,0.8,0,0.2,0.2],[0.4,0.6,0,0.2,0.2],[0.4,0.8,0,0.2,0.2]]",
//20分割 13
"[[0,0,0,0.5,0.5],[0,0.5,0,0.166,0.166],[0,0.666,0,0.166,0.166],[0,0.833,0,0.166,0.166],[0.166,0.5,0,0.166,0.166],[0.166,0.666,0,0.166,0.166],[0.166,0.833,0,0.166,0.166], [0.333,0.5,0,0.166,0.166],[0.333,0.666,0,0.166,0.166],[0.333,0.833,0,0.166,0.166],[0.5,0,0,0.5,0.5],[0.5,0.5,0,0.166,0.166],[0.5,0.666,0,0.166,0.166],[0.5,0.833,0,0.166,0.166], [0.666,0.5,0,0.166,0.166],[0.666,0.666,0,0.166,0.166],[0.666,0.833,0,0.166,0.166],[0.833,0.5,0,0.166,0.166],[0.833,0.666,0,0.166,0.166],[0.833,0.833,0,0.166,0.166]]",
//22分割 14
"[[0,0.0833,0,0.5,0.5],[0,0.5833,0,0.166,0.166],[0,0.7503,0,0.166,0.166],[0.166,0.5833,0,0.166,0.166],[0.166,0.7503,0,0.166,0.166], [0.333,0.5833,0,0.166,0.166],[0.333,0.7503,0,0.166,0.166],[0.5,0.0833,0,0.166,0.166],[0.5,0.25,0,0.166,0.166],[0.5,0.42,0,0.166,0.166],[0.5,0.5833,0,0.166,0.166],[0.5,0.7503,0,0.166,0.166], [0.666,0.0833,0,0.166,0.166],[0.666,0.25,0,0.166,0.166],[0.666,0.42,0,0.166,0.166],[0.666,0.5833,0,0.166,0.166],[0.666,0.7503,0,0.166,0.166],[0.832,0.0833,0,0.166,0.166],[0.832,0.25,0,0.166,0.166],[0.832,0.42,0,0.166,0.166],[0.832,0.5833,0,0.166,0.166],[0.832,0.7503,0,0.166,0.166]]",
//24分割 15
"[[0,0,0,0.333,0.333],[0.333,0,0,0.333,0.333],[0.666,0,0,0.167,0.167],[0.833,0,0,0.167,0.167],[0.666,0.166,0,0.167,0.167],[0.833,0.166,0,0.167,0.167], [0,0.333,0,0.333,0.333],[0.333,0.333,0,0.333,0.333],[0.666,0.333,0,0.167,0.167],[0.833,0.333,0,0.167,0.167],[0.666,0.499,0,0.167,0.167],[0.833,0.499,0,0.167,0.167], [0,0.666,0,0.166,0.167],[0.166,0.666,0,0.167,0.167],[0.333,0.666,0,0.166,0.167],[0.499,0.666,0,0.167,0.167],[0.666,0.666,0,0.167,0.167],[0.833,0.666,0,0.167,0.167], [0,0.833,0,0.166,0.167],[0.166,0.833,0,0.167,0.167],[0.333,0.833,0,0.166,0.167],[0.499,0.833,0,0.167,0.167],[0.666,0.833,0,0.167,0.167],[0.833,0.833,0,0.167,0.167]]",
//28分割 16
"[[0.002,0.002,0,0.498,0.498],[0.002,0.5,0,0.166,0.166],[0.002,0.666,0,0.166,0.166],[0.002,0.832,0,0.166,0.166],[0.168,0.5,0,0.166,0.166],[0.168,0.666,0,0.166,0.166],[0.168,0.832,0,0.166,0.166], [0.334,0.5,0,0.166,0.166],[0.334,0.666,0,0.166,0.166],[0.334,0.832,0,0.166,0.166],[0.5,0.002,0,0.166,0.166],[0.5,0.168,0,0.166,0.166],[0.5,0.334,0,0.166,0.166],[0.5,0.5,0,0.166,0.166],[0.5,0.666,0,0.166,0.166],[0.5,0.832,0,0.166,0.166], [0.666,0.002,0,0.166,0.166],[0.666,0.168,0,0.166,0.166],[0.666,0.334,0,0.166,0.166],[0.666,0.5,0,0.166,0.166],[0.666,0.666,0,0.166,0.166],[0.666,0.832,0,0.166,0.166], [0.832,0.002,0,0.166,0.166],[0.832,0.168,0,0.166,0.166],[0.832,0.334,0,0.166,0.166],[0.832,0.5,0,0.166,0.166],[0.832,0.666,0,0.166,0.166],[0.832,0.832,0,0.166,0.166]]"
};

private static String getLayout(int size) {
//10以内的用对应的布局
if (size>0&&size<=11){
return layouts[size-1];
//10到13用13的布局
}else if (size<=13){
return layouts[10];
}else if (size<=16){
return layouts[11];
}else if (size<=17){
return layouts[12];
}else if (size<=20){
return layouts[13];
}else if (size<=22){
return layouts[14];
}else if (size<=24){
return layouts[15];
}else {
return layouts[16];
}
}

/**
* 创建会议
* @param name 会议名称
* @param confid 会议 ID
* @return
* @throws IOException
*/
private static Result confCreate(String cookie, String name, String confid, List<DeviceT> deviceTList) throws IOException {
LocalDateTime rightNow = LocalDateTime.now();
String starttime = rightNow.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
String endtime = rightNow.plusMinutes(30).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));

StringBuilder attendee = new StringBuilder();
attendee.append("[");
for (DeviceT deviceT : deviceTList) {
attendee.append("{\"devid\":\""+ deviceT.getDeviceId() +"\",\"platformId\":\"0000\",\"name\":\""+ deviceT.getDeviceName() +"\",\"status\":1,\"orgid\":\"001\"}");
attendee.append(",");
}
attendee.deleteCharAt(attendee.length()-1);
attendee.append("]");
int confSsrc = Integer.parseInt(confid) * 10 + 2;

String devSsrc = getDevSsrc(deviceTList);
String layout = getLayout(deviceTList.size());
String interval = getInterval(deviceTList.size());
@Language("JSON") String json = "{\"name\":\""+ name +"\",\"conftype\":\"1\",\"starttime\":\""+ starttime +"\",\"endtime\":\""+ endtime +"\",\"confid\":\""+
confid +"\",\"creator\":\"admin\",\"subTitles\":\"\",\"description\":{\"isCentralizedControl\":false,\"sendMode\":1,\"toCloseMICDefault\":1,\"transferStreams\":[],\"noOwner\":0,\"seeOpposite\":0,\"templateId\":3},\"owner\":\"30000005\",\"attendee\":" +
attendee.toString() +
",\"olayout\":{\"id\":\"\",\"layout\":" + layout +
",\"ssrc\":" + devSsrc +
",\"interval\": "+ interval +"},\"alayout\":{\"id\":\"\",\"layout\":" + layout +
",\"ssrc\":" + devSsrc +
",\"interval\":"+ interval +",\"isInterval\":false,\"isFixedGrid\":false},\"layoutMode\":0,\"mode\":1,\"password\":\"\",\"remind\":\"0\",\"isAllowAnonymous\":1,\"toMulticast\":0,\"toLivecast\":0,\"toRecord\":0,\"isVoiceActivated\":0,\"fusionStreams\":[{\"videoBandwidth4mcu\":960,\"width4mcu\":1920,\"height4mcu\":1080,\"fps4mcu\":30,\"codec4mcu\":\"H264HP\",\"audioCodec4mcu\":\"OPUS\",\"audioBandwidth4mcu\":64,\"videoBandwidth\":960,\"audioBandwidth\":64,\"width\":1920,\"height\":1080,\"fps\":30,\"codec\":\"H264HP\",\"audioCodec\":\"OPUS\",\"bandwidth4p\":1024,\"codec4p\":\"H264HP\",\"fps4p\":25,\"width4p\":1280,\"height4p\":720,\"ssrc\":" +
confSsrc +"}],\"bandwidth\":2048}";

Result result = post(cookie, CONFCREATE, json);
result.setConfId(confid);
return result;
}

private static String getInterval(int size) {
// [0,0]
StringBuilder attendee = new StringBuilder();
attendee.append("[");
for (int i=0; i<size; i++) {
attendee.append(0);
attendee.append(",");
}
attendee.deleteCharAt(attendee.length()-1);
attendee.append("]");
return attendee.toString();
}

private static String getDevSsrc(List<DeviceT> deviceTList) {
//"[[300000072],[300000062]]"
StringBuilder attendee = new StringBuilder();
attendee.append("[");
for (DeviceT deviceT : deviceTList) {
attendee.append("["+ (Integer.parseInt(deviceT.getDeviceId()) * 10 + 2) +"]");
attendee.append(",");
}
attendee.deleteCharAt(attendee.length()-1);
attendee.append("]");
return attendee.toString();
}

/**
* 创建设备
* @param cookie
* @param id
* @param name
* @param password
* @return
* @throws IOException
*/
private static Result devCreate(String cookie, String id, String name, String password) throws IOException {
String json = "{\n" +
" \"channelID\": \"\",\n" +
" \"devid\": \""+ id +"\",\n" +
" \"email\": \"\",\n" +
" \"name\": \""+ name +"\",\n" +
" \"orgid\": \"001\",\n" +
" \"passwd\": \""+ password +"\",\n" +
" \"port\": \"\",\n" +
" \"protocol\": 0,\n" +
" \"tel\": \"\",\n" +
" \"type\": 30,\n" +
" \"username\": \"\",\n" +
" \"ip\": \"\",\n" +
" \"cameras\": \"1\"\n" +
"}\n";

return post(cookie, DEVICECREATE, json);
}

/**
* 修改设备
* @param cookie
* @param id
* @param name
* @param password
* @return
* @throws IOException
*/
private static Result devModify(String cookie, String id, String name, String password) throws IOException {
String json = "{\n" +
" \"channelID\": \"\",\n" +
" \"devid\": \""+ id +"\",\n" +
" \"email\": \"\",\n" +
" \"name\": \""+ name +"\",\n" +
" \"orgid\": \"001\",\n" +
" \"passwd\": \""+ password +"\",\n" +
" \"port\": \"\",\n" +
" \"protocol\": 0,\n" +
" \"tel\": \"\",\n" +
" \"type\": 30,\n" +
" \"username\": \"\",\n" +
" \"ip\": \"\",\n" +
" \"cameras\": \"1\"\n" +
"}\n";

return post(cookie, DEVICEMODIFY, json);
}

/**
* 删除设备
* @param cookie
* @param id
* @return
* @throws IOException
*/
private static Result devDelete(String cookie, String id) throws IOException {
String json = "{\n" +
" \"devid\": \""+ id +"\"\n" +
"}\n";

return post(cookie, DEVICEDELETE, json);
}

/**
* 分页获取设备
* @param cookie
* @param page
* @param size
* @return
* @throws IOException
*/
private static Result devList(String cookie, Integer page, Integer size) throws IOException {
String json = "{\"status\":[],\"name\":\"\",\"pageCur\":\""+ page +"\",\"pageNum\":\""+ size +"\",\"pageSort\":\"0\",\"orgid\":\"\"}";

Result res = post(cookie, DEVICELIST, json);
return res;
}

/**
* 分页获取会议
* @param page 当前页(从0开始, 0表示第一页)
* @param size 每页数量
* @return
* @throws IOException
*/
public static Set<Integer> confList(Integer page, Integer size) {
VideoCall login = null;
try {
login = login();
if(login.result.getResult() != 1) {
//登录失败
return null;
}

//登录成功-设备列表
return confList(login.cookie, page, size);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}

/**
* 分页获取会议
* @param cookie
* @param page
* @param size
* @return
* @throws IOException
*/
private static Set<Integer> confList(String cookie, Integer page, Integer size) throws IOException {
String json_1 = "{\"name\":\"\",\"pageCur\":\""+ page +"\",\"pageNum\":\""+ size +"\",\"pageSort\":\"0\",\"conftype\":\"1\"}";

Result res_1 = post(cookie, CONFGETBYPAGE, json_1);
List<Conf> c1 = JSON.parseArray(res_1.getData(), Conf.class);
Set<Integer> confIds = new HashSet<>();
for (Conf d : c1) {
confIds.add(Integer.parseInt(d.getConfid()));
}
return confIds;
}

/**
* 删除会议
*
* @param confId
* @return
* @throws IOException
*/
public static Result confDelete(String confId) throws IOException {
VideoCall login = login();
if (login.result.getResult() != 1) {
//登录失败
return login.result;
}

//登录成功-删除会议
return confDelete(login.cookie, confId);
}

/**
* 删除会议
* @param cookie
* @param confId
* @return
* @throws IOException
*/
private static Result confDelete(String cookie, String confId) throws IOException {
@Language("JSON") String json = "{\n" +
" " +
"\"confid\": [\""+ confId +"\"],\n" +
" " +
"\"conftype\": \"1\"\n" +
"}";

return post(cookie, CONFDEL, json);
}

/**
* post 同步请求,参数为 json 字符串、mediaType
*
* @param url
* @param json
* @return
* @throws IOException
*/
private static Result post(String cookie, String url, String json) throws IOException {
String data = "data=" + json;

RequestBody body = create(data, JSONTYPE_X_WWW_FORM_URLENCODED);
Request request = new Request.Builder()
.url(url)
.header("Cookie", cookie)
.post(body)
.build();
try (Response response = client.newCall(request).execute()) {
String res = response.body().string();
Result result = JSON.parseObject(res, Result.class);
if(result.getResult() == 1) {
result.setSuccess(true);
} else {
result.setSuccess(false);
}
return result;
}
}
}

前端

Android 集成

集成

  1. 将所有aar文件复制到app/libs目录;

  2. 添加依赖:
    在app/build.gradle的dependencies里,添加
    Implementation fileTree(dir: ‘libs’, include: [‘*.aar’])

  3. 添加 armeabi cpu 支持

    1
    2
    3
    ndk {
    abiFilters "armeabi"
    }

注:功能需要集成gson,请自行在app/build.gradle中进行集成

使用

主动入会
1
2
3
4
5
6
7
8
DHNavigator.INSTANCE.navigateWebContainer(Context context, String userName, String pwd, String ip, int port, String confId);
//参数说明:
//context:上下文(建议传入getApplicationContext());
//userName:用户ID;
//pwd:用户登录密码;
//ip:MCU ip;
//port:MCU端口;
//confId:会议ID(必须传入指定的会议ID,否则无法入会)。
进入手机端主界面
1
2
3
4
5
6
7
8
DHNavigator.INSTANCE.navigateWebContainer(Context context, String userName, String pwd, String ip, int port, String confId);
//参数说明:
//context:上下文(建议传入getApplicationContext());
//userName:用户ID;
//pwd:用户登录密码;
//ip:MCU ip;
//port:MCU端口;
//confId:会议ID(传入null或者空字符串)

播放页面

  1. 安装 webplugin.exe 插件
  2. 使用 360 极速浏览器或搜狗浏览器

demo.html

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
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="http://www.jq22.com/jquery/jquery-2.1.1.js"></script>
<style>
html, body, #video {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
#embed1 {
margin: 0 auto;
}
</style>
</head>
<body>
<div id="video">
<object id="embed1" type="application/MCU_RRS_webcore-9.1.0.4" width="1150" height="500"
style="background-color:#000000">
</object>
</div>
<script>
// let confid = '5538'; //会议id
var confid = '${confId}';
RequestMonitor();

//根据会议id获取会议信息
function getConferenceBasic(cb) {
$.ajax({
url: '/post/conf/GetConferenceBasic',
method: 'POST',
data: {
data: JSON.stringify({
"conferenceID": confid,
// toIP 为当前打开页面电脑能通的 mcu 的 ip,如果有内外网映射的环境,从内网打开页面则传内网 mcu ip,如果从外网打开页面则传外网 mcu ip
// 例如从 10.35.148.179 打开 mcu 界面,则传 10.35.148.179, 如果从外网访问 mcu 则需传外网的 ip
"toIP": "10.236.36.7"
})
},
success: function (result) {
var conferenceBasic = result.data;

cb(conferenceBasic);
}
})
}

function RequestMonitor() {
loginMcu(function () {
getConferenceBasic(function (conferenceBasic) {
var confid = conferenceBasic.conferenceID;
var rtpIP = conferenceBasic.rtpIP;
var rtpPort = conferenceBasic.rtpPort;

var plugin = document.getElementById("embed1");
plugin.ReleaseMonitor();

function getAddr() {
// 第三个参数可以填会议id也可以填设备id,如果填设备id那么设备如要在会议里
var taget = confid;
var natAddr = plugin.RequestMonitor(rtpIP, rtpPort, taget, 1);

if (!natAddr) {
setTimeout(getAddr, 3 * 1000);
return;
}

var arr = natAddr.split(":");
var clientRaknetIP = arr[0];
var clientRaknetPort = parseInt(arr[1]);
var ssrc = taget * 10 + 2;

var data = {
"method": "RequestMonitor",
"params": {
"conferenceID": confid,
"clientRaknetIP": clientRaknetIP, //raknet打洞后的外网IP及PORT。
"clientRaknetPort": clientRaknetPort,
"requestedStreams": [ssrc], //SSRC,可以是会议融合流或终端单路流,也可多选;
"toAcceptPresentation": false //是否接受演示流
}
};

$.ajax({
url: '/post/jsonrpc/callService',
method: 'POST',
data: {
data: JSON.stringify(data)
},
})
};

getAddr();
})
})
}

function loginMcu(cb) {
$.ajax({
url: '/login',
method: 'POST',
data: {
data: JSON.stringify({
"username": "admin",
"password": "xxxx"
})
},
success: function () {
cb();
}
})
}
</script>
</body>

</html>

Nginx

nginx.conf 配置请求转发

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 location /demo.html {
root html;
}

# 项目
location ^~ /gms-web {
proxy_pass http://127.0.0.1:8000/gms-web;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# websocket support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}

# 播放页面请求转发
location / {
proxy_pass http://ip; # mcu IP 地址
}