-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest-tick-websocket.js
46 lines (41 loc) · 1.14 KB
/
test-tick-websocket.js
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
/*
* Simple script to test if the websocket is working, including through
* any reverse proxy with SSL.
*
* Usage: <this script> <URL of web socket>
*
* node test-tick-websocket.js wss://tick.edcd.io
*
*
* It bares noting that despite using the WebSocket protocol the actual
* socket in this case has the socket.io protocol on top of that. Thus
* a bare WebSocket connection **will not work**.
*
* When it works output should be like:
*
* [message]: 2022-12-18T13:20:50+00:00
*
* the datetimestamp is that of the last detected tick. If you keep it
* running then you should get an additional message when the next tick
* is detected.
*
*/
/*
* You will need to have done:
*
* npm install socket.io-client
*/
const { io } = require("socket.io-client")
// Check we were passed a URL
if (process.argv.length != 3) {
console.log(`Usage: ${process.argv[1]} <URL of socket.io websocket>`)
console.log('')
console.log(' NB: "bare" URL not including ANY path.')
return
}
url = process.argv[2]
console.log(`Attempting to connect to: ${url}`)
socket = io(url)
socket.on('message', (data) => {
console.log(`[message]: ${data}`);
})