-
Notifications
You must be signed in to change notification settings - Fork 2
/
ws.html
43 lines (35 loc) · 1.01 KB
/
ws.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
<h1>
Web Socket Example
</h1>
<p>
open console to see connection.
</p>
<p>
request:
<input type="text" name="req" id="req">
<button id="submit">submit</button>
</p>
<script src="https://cdn.jsdelivr.net/npm/socket.io-client@2/dist/socket.io.js"></script>
<script>
// const url = 'wss://red-gold-socket.herokuapp.com'
const url = 'ws://localhost:3001'
var socket = io(url, { query: "accessKey=bar&uid=ef54ada2-3e8f-4c88-8406-7eeaf4d9fc40" });
socket.on('connect', function(data){
console.log('connected')
var submitBtn = document.getElementById('submit');
var textField = document.getElementById('req')
submitBtn.onclick = function(event){
event.preventDefault()
var value = textField.value;
console.log('value: ', value)
socket.emit('di', socket.id, {value: value})
}
socket.on('dispatch', function(data){
console.log(data)
});
// socket.emit('login', socket.id, {statue: 'login'})
});
socket.on('disconnect', function(){
console.log('disconnected')
});
</script>