-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (38 loc) · 937 Bytes
/
index.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
import WebSocketAsPromised from 'websocket-as-promised';
import { w3cwebsocket } from 'websocket';
import config from './config';
const wsp = new WebSocketAsPromised(
config.server,
{
createWebSocket: url => new w3cwebsocket(url)
}
);
let AuthenticateUserFrame = {
'm': 0,
'i': 2,
'n': 'AuthenticateUser',
'o': JSON.stringify({
'UserName': config.UserName,
'Password': config.Password,
})
}
let AddUserAPIKeyFrame = {
'm': 0,
'i': 2,
'n': 'AddUserAPIKey',
'o': JSON.stringify({
'UserId': config.UserId,
'Permissions': config.Permissions,
})
}
wsp.open().then((res) => {
wsp.onMessage.addListener(message => {
console.log(message);
});
wsp.send(JSON.stringify(AuthenticateUserFrame));
setTimeout(() => {
wsp.send(JSON.stringify(AddUserAPIKeyFrame));
}, 1000);
}).catch((err) => {
console.log(err);
});