|
@@ -14,11 +14,11 @@ function DataConnection(id, peer, socket, cb, options) {
|
|
// Connection is not open yet
|
|
// Connection is not open yet
|
|
this.open = false;
|
|
this.open = false;
|
|
|
|
|
|
- this._id = id;
|
|
|
|
- this._peer = peer;
|
|
|
|
|
|
+ this.id = id;
|
|
|
|
+ this.peer = peer;
|
|
this._originator = (options.sdp === undefined);
|
|
this._originator = (options.sdp === undefined);
|
|
this._cb = cb;
|
|
this._cb = cb;
|
|
- this._metadata = options.metadata;
|
|
|
|
|
|
+ this.metadata = options.metadata;
|
|
|
|
|
|
this._socket = socket;
|
|
this._socket = socket;
|
|
|
|
|
|
@@ -68,7 +68,7 @@ DataConnection.prototype._setupDataChannel = function() {
|
|
var self = this;
|
|
var self = this;
|
|
if (this._originator) {
|
|
if (this._originator) {
|
|
util.log('Creating data channel');
|
|
util.log('Creating data channel');
|
|
- this._dc = this._pc.createDataChannel(this._peer, { reliable: this._options.reliable });
|
|
|
|
|
|
+ this._dc = this._pc.createDataChannel(this.peer, { reliable: this._options.reliable });
|
|
this._configureDataChannel();
|
|
this._configureDataChannel();
|
|
} else {
|
|
} else {
|
|
util.log('Listening for data channel');
|
|
util.log('Listening for data channel');
|
|
@@ -98,8 +98,8 @@ DataConnection.prototype._setupIce = function() {
|
|
self._socket.send({
|
|
self._socket.send({
|
|
type: 'CANDIDATE',
|
|
type: 'CANDIDATE',
|
|
candidate: evt.candidate,
|
|
candidate: evt.candidate,
|
|
- dst: self._peer,
|
|
|
|
- src: self._id
|
|
|
|
|
|
+ dst: self.peer,
|
|
|
|
+ src: self.id
|
|
});
|
|
});
|
|
}
|
|
}
|
|
};
|
|
};
|
|
@@ -132,6 +132,7 @@ DataConnection.prototype._configureDataChannel = function() {
|
|
this._dc.onopen = function() {
|
|
this._dc.onopen = function() {
|
|
util.log('Data channel connection success');
|
|
util.log('Data channel connection success');
|
|
self.open = true;
|
|
self.open = true;
|
|
|
|
+ self.emit('open');
|
|
self._callback(null, self);
|
|
self._callback(null, self);
|
|
};
|
|
};
|
|
this._dc.onmessage = function(e) {
|
|
this._dc.onmessage = function(e) {
|
|
@@ -157,12 +158,11 @@ DataConnection.prototype._makeOffer = function() {
|
|
util.log('Created offer');
|
|
util.log('Created offer');
|
|
self._pc.setLocalDescription(offer, function() {
|
|
self._pc.setLocalDescription(offer, function() {
|
|
util.log('Set localDescription to offer');
|
|
util.log('Set localDescription to offer');
|
|
- //self._peerReady = false;
|
|
|
|
self._socket.send({
|
|
self._socket.send({
|
|
type: 'OFFER',
|
|
type: 'OFFER',
|
|
sdp: offer,
|
|
sdp: offer,
|
|
- dst: self._peer,
|
|
|
|
- src: self._id,
|
|
|
|
|
|
+ dst: self.peer,
|
|
|
|
+ src: self.id,
|
|
metadata: self.metadata
|
|
metadata: self.metadata
|
|
});
|
|
});
|
|
}, function(err) {
|
|
}, function(err) {
|
|
@@ -181,9 +181,9 @@ DataConnection.prototype._makeAnswer = function() {
|
|
util.log('Set localDescription to answer');
|
|
util.log('Set localDescription to answer');
|
|
self._socket.send({
|
|
self._socket.send({
|
|
type: 'ANSWER',
|
|
type: 'ANSWER',
|
|
- src: self._id,
|
|
|
|
|
|
+ src: self.id,
|
|
sdp: answer,
|
|
sdp: answer,
|
|
- dst: self._peer
|
|
|
|
|
|
+ dst: self.peer
|
|
});
|
|
});
|
|
}, function(err) {
|
|
}, function(err) {
|
|
self._callback('Failed to setLocalDescription');
|
|
self._callback('Failed to setLocalDescription');
|
|
@@ -205,7 +205,7 @@ DataConnection.prototype._cleanup = function() {
|
|
this._pc.close();
|
|
this._pc.close();
|
|
this._pc = null;
|
|
this._pc = null;
|
|
}
|
|
}
|
|
- this.emit('close', this._peer);
|
|
|
|
|
|
+ this.emit('close', this.peer);
|
|
};
|
|
};
|
|
|
|
|
|
// Make sure _cb only gets called once
|
|
// Make sure _cb only gets called once
|
|
@@ -247,8 +247,8 @@ DataConnection.prototype.close = function(reason) {
|
|
if (this.open) {
|
|
if (this.open) {
|
|
this._socket.send({
|
|
this._socket.send({
|
|
type: 'LEAVE',
|
|
type: 'LEAVE',
|
|
- dst: self._peer,
|
|
|
|
- src: self._id,
|
|
|
|
|
|
+ dst: self.peer,
|
|
|
|
+ src: self.id,
|
|
});
|
|
});
|
|
} else {
|
|
} else {
|
|
this._callback(reason);
|
|
this._callback(reason);
|
|
@@ -270,11 +270,6 @@ DataConnection.prototype.send = function(data) {
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
-DataConnection.prototype.getMetadata = function() {
|
|
|
|
- return this._metadata;
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
-
|
|
|
|
DataConnection.prototype.handleSDP = function(message) {
|
|
DataConnection.prototype.handleSDP = function(message) {
|
|
var sdp = message.sdp;
|
|
var sdp = message.sdp;
|
|
if (util.browserisms != 'Firefox') {
|
|
if (util.browserisms != 'Firefox') {
|
|
@@ -288,8 +283,8 @@ DataConnection.prototype.handleSDP = function(message) {
|
|
self._pc.connectDataConnection(self.localPort, self.remotePort);
|
|
self._pc.connectDataConnection(self.localPort, self.remotePort);
|
|
self._socket.send({
|
|
self._socket.send({
|
|
type: 'PORT',
|
|
type: 'PORT',
|
|
- dst: self._peer,
|
|
|
|
- src: self._id,
|
|
|
|
|
|
+ dst: self.peer,
|
|
|
|
+ src: self.id,
|
|
remote: self.localPort,
|
|
remote: self.localPort,
|
|
local: self.remotePort
|
|
local: self.remotePort
|
|
});
|
|
});
|
|
@@ -311,7 +306,7 @@ DataConnection.prototype.handleCandidate = function(message) {
|
|
|
|
|
|
|
|
|
|
DataConnection.prototype.handleLeave = function() {
|
|
DataConnection.prototype.handleLeave = function() {
|
|
- util.log('Peer ' + this._peer + ' disconnected');
|
|
|
|
|
|
+ util.log('Peer ' + this.peer + ' disconnected');
|
|
this._cleanup();
|
|
this._cleanup();
|
|
};
|
|
};
|
|
|
|
|