-
Notifications
You must be signed in to change notification settings - Fork 0
/
socktest.html
34 lines (32 loc) · 1.2 KB
/
socktest.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
<script src="https://code.jquery.com/jquery-3.3.1.min.js" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/socket.io-client@2/dist/socket.io.js" crossorigin="anonymous"></script>
<script>
const socket = io.connect('http://' + document.domain + ':' + location.port + '/');
function dlog(etype, msg) {
if(typeof msg != typeof "")
msg = JSON.stringify(msg);
$('#received').append(etype + ":" + msg + "<br />");
}
{% autoescape false %}
const eventList = {{ eventList|default(["connect", "disconnect", "debug", "update"], true) }};
{% endautoescape %}
eventList.forEach(eventName =>
socket.on(eventName, function(msg) {
dlog(eventName, msg);
})
);
/*
socket.on('connection', (socket) => {
socket.use((packet, next) => {
alert(packet);
next();
});
});
*/
</script>
<input type="text" id="eventType"></input>
<input type="text" id="msg"></input>
<button type="button" id="send" onclick="socket.emit($('#eventType').val(), $('#msg').val());">Send</button>
<button type="button" id="sendJSON" onclick="socket.emit($('#eventType').val(), JSON.parse($('#msg').val()));">Send as JSON</button>
<br />
<div id="received"></div>