index.js
1.82 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
import RTCClient from './rtc-client';
import axios from "axios";
import stomp from "./stomp";
import './assets/style.css'
if (!AgoraRTS.checkSystemRequirements()) {
alert('Your web browser not support AgoraRTS!')
} else {
console.log('check success')
}
$(() => {
let rtc = new RTCClient()
let subscribes = [];
let sessionId = '';
let loading = false;
let token = '';
let noticeInfo = {};
function createWatch() {
subscribes = [];
subscribes.push({
topic: '/broadcast/live',
callback: (data) => {
if (data.body) {
let msg = JSON.parse(data.body)
if (msg.type === 'changeSid') {
sessionId = msg.content;
console.log(msg.content);
rtc.join(sessionId).then(() => {
console.log('加入')
})
}
if (msg.type === 'overLive') {
sessionId = '';
rtc.leave();
getNotice();
}
}
},
});
init();
}
function init() {
if (subscribes.length > 0) {
stomp.disconnect();
stomp.connect(subscribes);
}
}
createWatch();
axios.post('https://openday.console.etoneiot.tech/openday-boot/sys/mLogin', {
username: 'admin',
password: 'admin123'
}).then(r => {
if (r.data.code === 200) {
token = r.data.result.token;
getNotice();
}
})
function getNotice() {
axios.get('https://openday.console.etoneiot.tech/openday-boot/openday/notice', {
headers: {
'X-Access-Token': token
}
}).then(r => {
if (r.data.code === 200) {
noticeInfo = r.data.result;
sessionId = r.data.result.sessionId;
rtc.join(sessionId).then(() => {
console.log('加入')
})
} else {
noticeInfo = {};
sessionId = '';
}
})
}
})