-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdebug-connection.js
42 lines (33 loc) · 1.15 KB
/
debug-connection.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
const Connection = require('../lib/connection');
global.debugConnection = async () => {
var connA = new Connection();
var connB = new Connection();
connA.on('sdp', sdp => {
console.log('A', sdp);
connB.processMessageFromServer({sdp:JSON.parse(JSON.stringify(sdp))});
});
connA.on('ice', ice => {
console.log('A', ice);
connB.processMessageFromServer({ice:JSON.parse(JSON.stringify(ice))});
});
connB.on('sdp', sdp => {
console.log('B', sdp);
connA.processMessageFromServer({sdp:JSON.parse(JSON.stringify(sdp))});
});
connB.on('ice', ice => {
console.log('B', ice);
connA.processMessageFromServer({ice:JSON.parse(JSON.stringify(ice))});
});
connA.createDataChannel('control', {
ordered: true
});
connA.once('connected', () => {
console.log('connected');
connA.sendMessage('control', 'Hello, World!');
});
connA.on('disconnected', () => console.log('disconnected'));
connA.on('failed', () => console.log('failed'));
connB.on('message-control', msg => console.log(msg));
connB.start();
connA.start(true);
};