-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex1.html
176 lines (171 loc) · 5.38 KB
/
index1.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
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
<head>
<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
<link
rel="stylesheet"
href="C:/Users/tmp53/Desktop/test/bootcamp.css"
crossorigin="anonymous"
/>
<style>
@import url("C:/Users/tmp53/Desktop/test/button.css");
#danmuarea {
position: relative;
background: #222;
width: 800px;
height: 445px;
margin-left: auto;
margin-right: auto;
}
.center {
text-align: center;
}
.ctr {
font-size: 1em;
}
.container {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.options {
width: 100%;
height: fit-content;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}
.my-button {
margin: 5px 80px;
}
</style>
</head>
<div class="container">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">弹幕</h3>
</div>
<div class="panel-body">
<div id="danmuarea">
<div
id="my-container"
style="width: 640px; height: 360px"
></div>
</div>
</div>
<div class="panel-footer">
<div class="row">
<div class="col-lg-3">
<button id="open" type="button" class="btn btn-primary">
Open
</button>
</div>
<div class="col-lg-9">
<div class="input-group">
<input
type="text"
id="input-area"
class="form-control"
placeholder="输入弹幕"
/>
<span class="input-group-btn">
<button
id="send-button"
class="btn btn-primary"
type="button"
>
send
</button>
</span>
</div>
</div>
</div>
</div>
</div>
<!-- <script src="path/to/socket.io.js"></script> -->
<script src="file:C:/Users/tmp53/Desktop/test/danmuku.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://10.108.21.48: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;
});
document.getElementById("close").onclick = function(evt) {
if (!ws) {
return false;
}
ws.close();
return false;
};
function unpack(package) {
const reader = new FileReader();
reader.onload = function (event) {
var content = reader.result;
var results = content.split("\n");
console.log(results);
results.forEach(function (cur, idx, arr) {
if (idx == 0) {
} else {
var comment = {
text: cur,
style: {
fontSize: "20px",
color: "#fff00f",
},
};
danmaku.emit(comment);
}
});
};
reader.readAsText(package);
};
function httpPost(URL, PARAMS) {
var temp = document.createElement("form");
temp.action = URL;
temp.method = "post";
temp.style.display = "none";
for (var x in PARAMS) {
var opt = document.createElement("textarea");
opt.name = x;
opt.value = PARAMS[x];
temp.appendChild(opt);
}
document.body.appendChild(temp);
temp.submit();
return temp;
}
</script>
</div>