-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
45 lines (37 loc) · 1.27 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
44
45
const voiceChat = new P2PVoiceChat({
channelId: 'testvchat',
signalSend: send,
audioMeter: true,
onaudiometer: showAudio,
onreceiveinvite: function() {
btnCall.innerHTML = 'Accept';
btnCall.onclick = voiceChat.accept.bind(voiceChat);
btnHangUp.innerHTML = 'Reject';
btnHangUp.onclick = voiceChat.reject.bind(voiceChat);
},
onvoicechatready: function(){
meter.showPopover();
resetButtons();
},
onreceivereject: resetButtons,
onend: resetButtons,
});
/////////////////////////////////////////
const btnCall = document.getElementById('call');
const btnHangUp = document.getElementById('hangup');
const meter = document.getElementById('audioVisualizer');
function showAudio(v) {
meter.style.scale = 1 + v / 100;
}
function resetButtons() {
btnCall.innerHTML = 'Call';
btnCall.onclick = voiceChat.call.bind(voiceChat);
btnHangUp.innerHTML = 'Hang Up';
btnHangUp.onclick = voiceChat.end.bind(voiceChat);
}
/////////////////////////////////////////
const signaling = new BroadcastChannel('testvchat');
signaling.onmessage = e => voiceChat.processSignal(e.data.type, e.data.data, e.data.src);
function send(_, type, data, src) {
signaling.postMessage({data: data, type: type, src: src});
}