-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathConnection.js
63 lines (48 loc) · 1.68 KB
/
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"use strict";
var fs = require('fs');
var mumble = require('mumble');
var PeerConnection = require('../peerconnection').PeerConnection;
var Connection = function( socket ) {
console.log( 'New connection' );
this.socket = socket;
socket.emit('start');
var self = this;
socket.on( 'setname', function( name ) { self.setName(name); } );
socket.on( 'call', function( sdp ) { self.onCall( sdp ); } );
};
Connection.prototype.setName = function( name ) {
this.name = name;
};
Connection.prototype.onCall = function( sdp ) {
var self = this;
console.log( "New call:" );
console.log( sdp.sdp );
var c = new PeerConnection();
this.peerConnection = c;
var options = {};
mumble.connect( process.env.MUMBLE_ADDR, 64738, options, function( err, mumbleConn ) {
mumbleConn.authenticate( self.name );
mumbleConn.on( 'initialized', function () {
self.mumble = mumbleConn;
c.on( 'iceCandidate', function( evt ) {
self.socket.emit( 'icecandidate', evt );
});
c.on( 'answer', function( evt ) {
self.socket.emit( 'answer', evt );
});
c.on( 'audio', function( evt ) {
self.mumble.sendVoice( evt.data );
});
mumbleConn.on( 'voice', function( evt ) {
c.transmit( evt.data );
});
c.setRemoteDescription( sdp );
self.socket.on( 'icecandidate', function( evt ) {
console.log( "Adding ice candidate!" );
console.dir( evt );
c.addIceCandidate( evt );
});
});
});
};
module.exports = Connection;