-
Notifications
You must be signed in to change notification settings - Fork 19
/
index.js
76 lines (62 loc) · 2.03 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
var attach = require('rtc-attach');
var capture = require('rtc-capture');
var quickconnect = require('rtc-quickconnect');
var classtweak = require('classtweak');
var append = require('fdom/append');
var qsa = require('fdom/qsa');
var kgo = require('kgo');
var config = require('./config.js');
/**
# demo-quickconnect
This is a demonstration of how
[`rtc-quickconnect`](https://github.com/rtc-io/rtc-quickconnect) can be used
to create a simple video conferencing application.
**/
function createConference() {
var conference = quickconnect(config.switchboard, {
// we are going to let quickconnect autogenerate #room names if not
// supplied, but we will announce in the "qcdemo" namespace
ns: 'qcdemo',
// only start the conference when we have received 1 local stream
expectedLocalStreams: 1,
// flag reactive, which allow us to be more flexible in chrome browsers
// reactive: true,
// use some standard free ice servers
iceServers: require('freeice')()
});
conference
.createDataChannel('chat')
.on('call:ended', removeRemoteVideos)
.on('stream:added', renderRemote);
localVideo(conference, config);
}
function localVideo(qc, cfg) {
// use kgo to help with flow control
kgo(cfg)
('capture', [ 'constraints', 'options' ], capture)
('attach', [ 'capture', 'options' ], attach.local)
('render-local', [ 'attach' ], function(el) {
['+rtc', '+localvideo'].forEach(classtweak(el));
append.to((cfg || {}).localContainer || '#l-video', el);
})
('start-conference', [ 'capture' ], qc.addStream)
.on('error', reportError);
}
function removeRemoteVideos(id) {
qsa('[data-peer="' + id + '"]').forEach(function(el) {
el.parentNode.removeChild(el);
});
}
function renderRemote(id, stream) {
kgo({ stream: stream })
('attach', [ 'stream' ], attach)
('render-remote', [ 'attach' ], function(el) {
el.dataset.peer = id;
append.to('#r-video', el);
})
.on('error', reportError);
}
function reportError(err) {
console.error('Encountered error: ', err);
}
createConference();