-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
86 lines (84 loc) · 2.36 KB
/
index.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
<head>
<style>
#danmuarea {
position: relative;
background: #222;
width: 800px;
height: 445px;
margin-left: auto;
margin-right: auto;
}
.center {
text-align: center;
}
.ctr {
font-size: 1em;
}
</style>
</head>
<div id="danmuarea">
<div id="my-container" style="width:640px;height:360px;"></div>
</div>
<button id="open">Open</button>
<button id="close">Close</button>
<button id="send-button">Send</button>
<!-- <script src="path/to/socket.io.js"></script> -->
<script src="https://cdn.jsdelivr.net/npm/danmaku/dist/danmaku.js"></script>
<script>
var danmaku = new Danmaku({
container: document.getElementById('my-container')
});
var btn = document.getElementById('send-button');
btn.addEventListener('click', function () {
var comment = {
text: 'bla bla',
style: {
fontSize: '20px',
color: '#fff00f'
},
};
console.log("233")
});
var ws
var btn2 = document.getElementById('open');
btn2.addEventListener('click', function () {
if (ws) {
return false;
}
ws = new WebSocket("ws://localhost:3101/push?roomid=1");
ws.onopen = function (evt) {
console.log("ws opened!")
}
ws.onclose = function (evt) {
console.log("ws closed!")
ws = null;
}
ws.onmessage = function (evt) {
unpack(evt.data)
}
ws.onerror = function (evt) {
print("ERROR: " + evt.data);
}
return false;
});
function unpack(package) {
const reader = new FileReader();
reader.onload = function (event) {
var content = reader.result;
var results = content.split('\n')
console.log(typeof(results))
console.log(results)
results.forEach(function (cur, idx, arr) {
var comment = {
text: cur,
style: {
fontSize: '20px',
color: '#fff00f'
},
};
danmaku.emit(comment)
})
}
reader.readAsText(package)
}
</script>