/
datachannel.js
63 lines (48 loc) · 1.25 KB
/
datachannel.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
var assert = require('assert');
var uuid = require('uuid');
var RTC = require('../');
var connections = [];
var roomId = uuid.v4();
var dcs = [];
suite('datachannels connectivity');
test('create connection:0', function() {
var conn = RTC({ room: roomId, constraints: null });
// create the datachannel
conn.createDataChannel('test');
assert(conn);
assert(conn.id);
connections.push(conn);
});
test('create connection:1', function() {
var conn = RTC({ room: roomId, constraints: null });
// create the datachannel
conn.createDataChannel('test');
assert(conn);
assert(conn.id);
connections.push(conn);
});
test('receive channel:opened:test events for both connections', function(done) {
var expected = 2;
function checkExpected() {
expected--;
if (expected <= 0) {
done();
}
}
this.timeout(10e3);
connections[0].once('channel:opened:test', function(id, dc) {
assert.equal(id, connections[1].id);
dcs[0] = dc;
checkExpected();
});
connections[1].once('channel:opened:test', function(id, dc) {
assert.equal(id, connections[0].id);
dcs[1] = dc;
checkExpected();
});
});
test('close connections', function() {
connections.splice(0).forEach(function(conn) {
conn.close();
});
});