-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.js
89 lines (64 loc) · 2.47 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
77
78
79
80
81
82
83
84
85
86
87
88
89
/* jshint node: true */
'use strict';
/**
# rtc-tools
The `rtc-tools` module does most of the heavy lifting within the
[rtc.io](http://rtc.io) suite. Primarily it handles the logic of coupling
a local `RTCPeerConnection` with it's remote counterpart via an
[rtc-signaller](https://github.com/rtc-io/rtc-signaller) signalling
channel.
## Getting Started
If you decide that the `rtc-tools` module is a better fit for you than either
[rtc-quickconnect](https://github.com/rtc-io/rtc-quickconnect) or
[rtc](https://github.com/rtc-io/rtc) then the code snippet below
will provide you a guide on how to get started using it in conjunction with
the [rtc-signaller](https://github.com/rtc-io/rtc-signaller) (version 5.0 and above)
and [rtc-media](https://github.com/rtc-io/rtc-media) modules:
<<< examples/getting-started.js
This code definitely doesn't cover all the cases that you need to consider
(i.e. peers leaving, etc) but it should demonstrate how to:
1. Capture video and add it to a peer connection
2. Couple a local peer connection with a remote peer connection
3. Deal with the remote steam being discovered and how to render
that to the local interface.
## Reference
**/
var gen = require('./generators');
// export detect
var detect = exports.detect = require('./detect');
var findPlugin = require('rtc-core/plugin');
// export cog logger for convenience
exports.logger = require('cog/logger');
// export peer connection
var RTCPeerConnection =
exports.RTCPeerConnection = detect('RTCPeerConnection');
// add the couple utility
exports.couple = require('./couple');
/**
### createConnection
```
createConnection(opts?, constraints?) => RTCPeerConnection
```
Create a new `RTCPeerConnection` auto generating default opts as required.
```js
var conn;
// this is ok
conn = rtc.createConnection();
// and so is this
conn = rtc.createConnection({
iceServers: []
});
```
**/
exports.createConnection = function(opts, constraints) {
var plugin = findPlugin((opts || {}).plugins);
var PeerConnection = (opts || {}).RTCPeerConnection || RTCPeerConnection;
// generate the config based on options provided
var config = gen.config(opts);
// generate appropriate connection constraints
constraints = gen.connectionConstraints(opts, constraints);
if (plugin && typeof plugin.createConnection == 'function') {
return plugin.createConnection(config, constraints);
}
return new PeerConnection(config, constraints);
};