forked from rtc-io/demo-helloworld
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
69 lines (56 loc) · 1.6 KB
/
app.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
(function() {
var room = location.hash.slice(1);
var roomData = document.querySelector('.roomdata');
var roomInput = roomData && roomData.querySelector('input[type="text"]');
var conference;
function connectToRoom() {
if (roomData) {
roomData.classList.remove('active');
}
conference = RTC({
// use the rtc.io development and testing switchboard
signaller: 'https://switchboard.rtc.io',
// use the public google stun servers :)
ice: [
{ url: 'stun:stun1.l.google.com:19302' },
{ url: 'stun:stun2.l.google.com:19302' },
{ url: 'stun:stun3.l.google.com:19302' },
{ url: 'stun:stun4.l.google.com:19302' }
],
room: 'helloworld:' + room,
// we want this to work on iOS as well so we will use
// the rtc-plugin-nicta-ios plugin so we can use the
// build.rtc.io to create a native iOS app
plugins: [ RTC.IOS ]
});
}
function handleKey(evt) {
if (evt && evt.keyCode === 13) {
updateRoom();
}
}
function initEvents() {
if (! roomData) {
return;
}
roomData.querySelector('button').addEventListener('click', updateRoom);
roomInput.addEventListener('keydown', handleKey);
roomData.classList.add('ready');
}
function promptForRoom() {
setTimeout(function() {
roomData.classList.add('active');
}, 50);
}
function updateRoom() {
room = location.hash = roomInput.value;
if (room) {
connectToRoom();
}
}
window.addEventListener('load', initEvents);
if (! room) {
return promptForRoom();
}
connectToRoom();
})();