|
@@ -156,6 +156,7 @@ Peer.prototype._handleMessage = function(message) {
|
|
this._abort('invalid-key', 'API KEY "' + this._key + '" is invalid');
|
|
this._abort('invalid-key', 'API KEY "' + this._key + '" is invalid');
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
+ //
|
|
case 'LEAVE': // Another peer has closed its connection to this peer.
|
|
case 'LEAVE': // Another peer has closed its connection to this peer.
|
|
this._cleanupPeer(peer);
|
|
this._cleanupPeer(peer);
|
|
break;
|
|
break;
|
|
@@ -165,29 +166,25 @@ Peer.prototype._handleMessage = function(message) {
|
|
this.emit('error', new Error('Could not connect to peer ' + peer));
|
|
this.emit('error', new Error('Could not connect to peer ' + peer));
|
|
break;
|
|
break;
|
|
case 'OFFER': // we should consider switching this to CALL/CONNECT, but this is the least breaking option.
|
|
case 'OFFER': // we should consider switching this to CALL/CONNECT, but this is the least breaking option.
|
|
- var id = message.id;
|
|
|
|
- var connection = this._getConnection(peer, id);
|
|
|
|
|
|
+ var connectionId = payload.connectionId;
|
|
|
|
+ var connection = this._getConnection(peer, connectionId);
|
|
|
|
|
|
if (connection) {
|
|
if (connection) {
|
|
- // Pass it on
|
|
|
|
- // TODO: is this just a no-op for DataConnection then? I am under the
|
|
|
|
- // impression that only MediaConnection need to renegotiate. I'm not
|
|
|
|
- // even sure how a DataConnection would handle renegotiation.
|
|
|
|
- connection.handleMessage(message);
|
|
|
|
|
|
+ util.warn('Offer received for existing Connection ID:', connectionId);
|
|
|
|
+ //connection.handleMessage(message);
|
|
} else {
|
|
} else {
|
|
// Create a new connection.
|
|
// Create a new connection.
|
|
if (payload.type === 'call') {
|
|
if (payload.type === 'call') {
|
|
- var call = new MediaConnection(peer, {
|
|
|
|
- id: id,
|
|
|
|
- offer: payload.sdp
|
|
|
|
|
|
+ var call = new MediaConnection(peer, this, {
|
|
|
|
+ _id: connectionId,
|
|
|
|
+ _payload: payload // A regular *Connection would have no payload.
|
|
});
|
|
});
|
|
this._addConnection(peer, call);
|
|
this._addConnection(peer, call);
|
|
this.emit('call', call);
|
|
this.emit('call', call);
|
|
} else if (payload.type === 'connect') {
|
|
} else if (payload.type === 'connect') {
|
|
- var connection = new DataConnection(peer, {
|
|
|
|
- id: id,
|
|
|
|
- offer: payload.sdp,
|
|
|
|
- config: this.options.config
|
|
|
|
|
|
+ var connection = new DataConnection(peer, this, {
|
|
|
|
+ _id: connectionId,
|
|
|
|
+ _payload: payload
|
|
});
|
|
});
|
|
this._addConnection(peer, connection);
|
|
this._addConnection(peer, connection);
|
|
this.emit('connection', connection);
|
|
this.emit('connection', connection);
|
|
@@ -201,6 +198,7 @@ Peer.prototype._handleMessage = function(message) {
|
|
var connection = this._getConnection(peer, id);
|
|
var connection = this._getConnection(peer, id);
|
|
|
|
|
|
if (connection) {
|
|
if (connection) {
|
|
|
|
+ // Pass it on.
|
|
connection.handleMessage(message);
|
|
connection.handleMessage(message);
|
|
} else {
|
|
} else {
|
|
util.warn('You aborted your connection to ' + peer + ' before it opened.');
|
|
util.warn('You aborted your connection to ' + peer + ' before it opened.');
|
|
@@ -214,7 +212,7 @@ Peer.prototype._handleMessage = function(message) {
|
|
* complete list of options.
|
|
* complete list of options.
|
|
*/
|
|
*/
|
|
Peer.prototype.connect = function(peer, options) {
|
|
Peer.prototype.connect = function(peer, options) {
|
|
- var connection = new DataConnection(peer, options);
|
|
|
|
|
|
+ var connection = new DataConnection(peer, this, options);
|
|
this._addConnection(peer, connection);
|
|
this._addConnection(peer, connection);
|
|
return connection;
|
|
return connection;
|
|
}
|
|
}
|
|
@@ -229,7 +227,7 @@ Peer.prototype.call = function(peer, stream, options) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
options.stream = stream;
|
|
options.stream = stream;
|
|
- var call = new MediaConnection(peer, options);
|
|
|
|
|
|
+ var call = new MediaConnection(peer, this, options);
|
|
this._addConnection(peer, call);
|
|
this._addConnection(peer, call);
|
|
return call;
|
|
return call;
|
|
}
|
|
}
|