-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtestWebsocket.js
68 lines (55 loc) · 2 KB
/
testWebsocket.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env node
var WebSocketClient = require('websocket').client;
var client = new WebSocketClient();
client.on('connectFailed', (error) => {
console.log('Connect Error: ' + error.toString());
});
client.on('connect', (connection) => {
console.log('> Connected');
connection.on('error', (error) => {
console.log("> Connection Error: " + error.toString());
});
connection.on('close', () => {
console.log('> Connection Closed');
});
connection.on('message', (message) => {
if (message.type === 'utf8')
console.log("Received: '" + message.utf8Data + "'");
});
//////////////////////////////////////////////////////////////////////////////
///
//////////////////////////////////////////////////////////////////////////////
function ping(connection) {
if (connection.connected) {
connection.sendUTF(JSON.stringify({event: "ping"}));
}
}
function channel_subscribe_attestation(connection) {
if (connection.connected) {
connection.sendUTF(JSON.stringify({event: "subscribe", channel: "attestation"}));
}
}
function channel_subscribe_attestationinfo(connection) {
if (connection.connected) {
connection.sendUTF(JSON.stringify({event: "subscribe", channel: "attestationinfo"}));
}
}
function channel_subscribe_merklecommitment(connection) {
if (connection.connected) {
connection.sendUTF(JSON.stringify({event: "subscribe", channel: "merklecommitment"}));
}
}
function channel_subscribe_merkleproof(connection) {
if (connection.connected) {
connection.sendUTF(JSON.stringify({event: "subscribe", channel: "merkleproof"}));
}
}
ping(connection);
channel_subscribe_attestation(connection);
channel_subscribe_attestation(connection);
channel_subscribe_attestationinfo(connection);
channel_subscribe_merklecommitment(connection);
channel_subscribe_merkleproof(connection);
//////////////////////////////////////////////////////////////////////////////
});
client.connect('ws://localhost:8080');