Permalink
Browse files

cleanup connections hash

  • Loading branch information...
1 parent b294951 commit a6c5fd96b8dac80eaa0648fb43a21107e70e0b02 @michelle michelle committed Apr 5, 2013
Showing with 6 additions and 9 deletions.
  1. +1 −1 lib/connectionmanager.js
  2. +5 −8 lib/peer.js
View
@@ -298,7 +298,7 @@ ConnectionManager.prototype.connect = function(options) {
}
this._lock = true
- return [options.label, connection];
+ return connection;
};
/** Updates label:[serialization, reliable, metadata] pairs from offer. */
View
@@ -140,7 +140,7 @@ Peer.prototype._handleServerJSONMessage = function(message) {
manager = new ConnectionManager(this.id, peer, this._socket, options);
this._attachManagerListeners(manager);
this.managers[peer] = manager;
- this.connections[peer] = {};
+ this.connections[peer] = manager.connections;
}
manager.update(options.labels);
manager.handleSDP(payload.sdp, message.type);
@@ -193,13 +193,13 @@ Peer.prototype._attachManagerListeners = function(manager) {
var self = this;
// Handle receiving a connection.
manager.on('connection', function(connection) {
- self.connections[connection.peer][connection.label] = connection;
self.emit('connection', connection);
});
// Handle a connection closing.
manager.on('close', function() {
if (!!self.managers[manager.peer]) {
- delete self.managers[manager.peer]
+ delete self.managers[manager.peer];
+ delete self.connections[manager.peer];
}
});
manager.on('error', function(err) {
@@ -253,15 +253,12 @@ Peer.prototype.connect = function(peer, options) {
this.connections[peer] = {};
}
- var connectionInfo = manager.connect(options);
- if (!!connectionInfo) {
- this.connections[peer][connectionInfo[0]] = connectionInfo[1];
- }
+ var connection = manager.connect(options);
if (!this.id) {
this._queued.push(manager);
}
- return connectionInfo[1];
+ return connection;
};
/**

0 comments on commit a6c5fd9

Please sign in to comment.