forked from rtc-io/rtc-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
81 lines (59 loc) · 2.16 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
/* jshint node: true */
'use strict';
/**
# rtc
The `rtc` 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` module is a better fit for you than either
[rtc-quickconnect](https://github.com/rtc-io/rtc-quickconnect) or
[rtc-glue](https://github.com/rtc-io/rtc-glue) 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) 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');
// 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');
/**
### rtc.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) {
return new ((opts || {}).RTCPeerConnection || RTCPeerConnection)(
// generate the config based on options provided
gen.config(opts),
// generate appropriate connection constraints
gen.connectionConstraints(opts, constraints)
);
};