-
Notifications
You must be signed in to change notification settings - Fork 27
/
index.js
43 lines (33 loc) · 1.25 KB
/
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
var message = document.querySelector('#message');
var button = document.querySelector('#btn-record');
var info = document.querySelector("#info-subscribe");
var subscribe = document.querySelector("#btn-subscribe");
var channelInput = document.querySelector("#input-channel");
var channel = "test";
showMessage("Connecting to server..");
ptt.connect().then((connection)=>{
showMessage("Connection established!");
connection.bind(button);
function handleSubscribeSuccess(response){
info.textContent = `Subscribed to channel '${channel}'`;
}
function handleError(){
showMessage("Could not subscribe!");
showMessage(JSON.stringify(err));
}
// automatically connects to channel 'test'
connection.subscribe(channel).then(handleSubscribeSuccess).catch(handleError);
subscribe.onclick = (e)=>{
if(channelInput.value.trim().length > 0){
channel = channelInput.value.trim();
connection.subscribe(channel).then(handleSubscribeSuccess).catch(handleError);
channelInput.value = "";
}
};
}).catch(err=>{
showMessage("Connection failed!");
showMessage(JSON.stringify(err));
});
function showMessage(msg){
message.textContent += `\n${msg}`;
}