-
Notifications
You must be signed in to change notification settings - Fork 2
/
example.js
29 lines (23 loc) · 913 Bytes
/
example.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
const WebsocketCollabClient = require("./lib/wcc");
const WS_URL = "<url>";
const USER = "<user>";
const PASS = "<pass>";
const CHANNEL_ID = "<channel id>";
async function main() {
let client = new WebsocketCollabClient();
await client.connect(WS_URL, CHANNEL_ID, { user: USER, pass: PASS });
// Called when a message destined to you, and that you did not send is received by the client.
client.onTextMessage = (sender, content, json) => {
console.log("RAW:", json);
console.log(`From: '${sender}' Message: '${content}'`);
};
// Called with every message, even those you sent or those that are not destined to you. Additional checks may be required.
client.onAllMessages = (json) => {
console.log("Received:", json);
};
while (true) {
await new Promise((resolve) => setTimeout(resolve, 2000));
client.sendText("Hilda", "This is a test message", ["all"]);
}
}
main();