-
Notifications
You must be signed in to change notification settings - Fork 367
/
remote.js
54 lines (46 loc) · 1.53 KB
/
remote.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
var createPeerConnection = require('./peer.js')
var peerConnection = createPeerConnection()
var ui = require('./ui.js')
var connect = require('./connect.js')
ui.inputs.paste.value = 'Loading...'
connect.verifyUserRoom(peerConnection, ui, function (err, room, config) {
if (err) {
ui.inputs.paste.value = 'Error! ' + err.message
return
}
ui.inputs.paste.value = 'Waiting on other side...'
connect.remote(peerConnection, ui, config, room)
})
peerConnection.on('connected', function connected (peer) {
ui.inputs.paste.value = ''
ui.show(ui.containers.multimedia)
ui.hide(ui.containers.content)
peer.on('error', function error (err) {
console.error('peer error')
console.error(err)
ui.hide(ui.containers.multimedia)
ui.show(ui.containers.content)
ui.containers.join.innerHTML = 'Error connecting! Please Quit. ' + err.message
})
peer.on('close', function close () {
ui.hide(ui.containers.multimedia)
ui.show(ui.containers.content)
ui.containers.join.innerHTML = 'The remote user ended the sharing session.'
ui.containers.multimedia.innerHTML = ''
})
})
ui.buttons.back.addEventListener('click', function (e) {
showChoose()
})
peerConnection.on('getting-audio', function () {
ui.inputs.paste.value = 'Please allow or deny voice chat...'
})
peerConnection.on('waiting-for-peer', function () {
ui.inputs.paste.value = 'Waiting for other side...'
})
function showChoose () {
ui.show(ui.containers.choose)
ui.hide(ui.containers.share)
ui.hide(ui.containers.join)
ui.hide(ui.buttons.back)
}