-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
25 lines (18 loc) · 826 Bytes
/
main.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
import PubSubClient from './pubsubClient.js';
const subscribeUrl = 'wss://pubsub.warths.fr/';
const publishUrl = 'https://pubsub.warths.fr/publish';
const client = new PubSubClient(subscribeUrl, publishUrl);
client.addEventListener('socket:open', () => {
client.subscribe('commands')
.then(() => {
console.log('subscribed!');
client.sendCommand('vip', ['a', 'b'], import.meta.env.VITE_AUTH_TOKEN);
});
});
client.addEventListener('client:message', event => {
if (event.topic === 'commands') {
const parameters = event.message.parameters.reduce((list, param) => list = `${ list }, ${ param }`);
console.log(`${ event.message.user.display_name } issued the command ${ event.message.command } with the parameters ${ parameters }`);
}
});
client.addEventListener('socket:message', msg => console.log(msg));