Skip to content

Commit

Permalink
Built after linter pr
Browse files Browse the repository at this point in the history
  • Loading branch information
ericz committed Oct 8, 2014
1 parent 4afee64 commit 9ed9aa8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 40 deletions.
78 changes: 39 additions & 39 deletions dist/peer.js
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ function Peer(id, options) {
this._retrieveId();
}
//
};
}

util.inherits(Peer, EventEmitter);

Expand All @@ -806,7 +806,7 @@ Peer.prototype._initializeServerConnection = function() {
this.socket.on('disconnected', function() {
// If we haven't explicitly disconnected, emit error and disconnect.
if (!self.disconnected) {
self.emitError('network', 'Lost connection to server.')
self.emitError('network', 'Lost connection to server.');
self.disconnect();
}
});
Expand All @@ -823,8 +823,8 @@ Peer.prototype._retrieveId = function(cb) {
var self = this;
var http = new XMLHttpRequest();
var protocol = this.options.secure ? 'https://' : 'http://';
var url = protocol + this.options.host + ':' + this.options.port
+ this.options.path + this.options.key + '/id';
var url = protocol + this.options.host + ':' + this.options.port +
this.options.path + this.options.key + '/id';
var queryString = '?ts=' + new Date().getTime() + '' + Math.random();
url += queryString;

Expand All @@ -834,12 +834,12 @@ Peer.prototype._retrieveId = function(cb) {
util.error('Error retrieving ID', e);
var pathError = '';
if (self.options.path === '/' && self.options.host !== util.CLOUD_HOST) {
pathError = ' If you passed in a `path` to your self-hosted PeerServer, '
+ 'you\'ll also need to pass in that same path when creating a new'
+ ' Peer.';
pathError = ' If you passed in a `path` to your self-hosted PeerServer, ' +
'you\'ll also need to pass in that same path when creating a new ' +
'Peer.';
}
self._abort('server-error', 'Could not get an ID from the server.' + pathError);
}
};
http.onreadystatechange = function() {
if (http.readyState !== 4) {
return;
Expand All @@ -857,7 +857,7 @@ Peer.prototype._retrieveId = function(cb) {
Peer.prototype._initialize = function(id) {
this.id = id;
this.socket.start(this.id, this.options.token);
}
};

/** Handles messages from the server. */
Peer.prototype._handleMessage = function(message) {
Expand Down Expand Up @@ -899,7 +899,7 @@ Peer.prototype._handleMessage = function(message) {
} else {
// Create a new connection.
if (payload.type === 'media') {
var connection = new MediaConnection(peer, this, {
connection = new MediaConnection(peer, this, {
connectionId: connectionId,
_payload: payload,
metadata: payload.metadata
Expand Down Expand Up @@ -935,7 +935,7 @@ Peer.prototype._handleMessage = function(message) {
}

var id = payload.connectionId;
var connection = this.getConnection(peer, id);
connection = this.getConnection(peer, id);

if (connection && connection.pc) {
// Pass it on.
Expand All @@ -948,15 +948,15 @@ Peer.prototype._handleMessage = function(message) {
}
break;
}
}
};

/** Stores messages without a set up connection, to be claimed later. */
Peer.prototype._storeMessage = function(connectionId, message) {
if (!this._lostMessages[connectionId]) {
this._lostMessages[connectionId] = [];
}
this._lostMessages[connectionId].push(message);
}
};

/** Retrieve messages from lost message store */
Peer.prototype._getMessages = function(connectionId) {
Expand All @@ -967,35 +967,35 @@ Peer.prototype._getMessages = function(connectionId) {
} else {
return [];
}
}
};

/**
* Returns a DataConnection to the specified peer. See documentation for a
* complete list of options.
*/
Peer.prototype.connect = function(peer, options) {
if (this.disconnected) {
util.warn('You cannot connect to a new Peer because you called '
+ '.disconnect() on this Peer and ended your connection with the'
+ ' server. You can create a new Peer to reconnect, or call reconnect'
+ ' on this peer if you believe its ID to still be available.');
util.warn('You cannot connect to a new Peer because you called ' +
'.disconnect() on this Peer and ended your connection with the ' +
'server. You can create a new Peer to reconnect, or call reconnect ' +
'on this peer if you believe its ID to still be available.');
this.emitError('disconnected', 'Cannot connect to new Peer after disconnecting from server.');
return;
}
var connection = new DataConnection(peer, this, options);
this._addConnection(peer, connection);
return connection;
}
};

/**
* Returns a MediaConnection to the specified peer. See documentation for a
* complete list of options.
*/
Peer.prototype.call = function(peer, stream, options) {
if (this.disconnected) {
util.warn('You cannot connect to a new Peer because you called '
+ '.disconnect() on this Peer and ended your connection with the'
+ ' server. You can create a new Peer to reconnect.');
util.warn('You cannot connect to a new Peer because you called ' +
'.disconnect() on this Peer and ended your connection with the ' +
'server. You can create a new Peer to reconnect.');
this.emitError('disconnected', 'Cannot connect to new Peer after disconnecting from server.');
return;
}
Expand All @@ -1008,15 +1008,15 @@ Peer.prototype.call = function(peer, stream, options) {
var call = new MediaConnection(peer, this, options);
this._addConnection(peer, call);
return call;
}
};

/** Add a data/media connection to this peer. */
Peer.prototype._addConnection = function(peer, connection) {
if (!this.connections[peer]) {
this.connections[peer] = [];
}
this.connections[peer].push(connection);
}
};

/** Retrieve a data/media connection for this peer. */
Peer.prototype.getConnection = function(peer, id) {
Expand All @@ -1030,14 +1030,14 @@ Peer.prototype.getConnection = function(peer, id) {
}
}
return null;
}
};

Peer.prototype._delayedAbort = function(type, message) {
var self = this;
util.setZeroTimeout(function(){
self._abort(type, message);
});
}
};

/**
* Destroys the Peer and emits an error message.
Expand Down Expand Up @@ -1076,7 +1076,7 @@ Peer.prototype.destroy = function() {
this.disconnect();
this.destroyed = true;
}
}
};


/** Disconnects every connection on this peer. */
Expand All @@ -1088,15 +1088,15 @@ Peer.prototype._cleanup = function() {
}
}
this.emit('close');
}
};

/** Closes all connections to this peer. */
Peer.prototype._cleanupPeer = function(peer) {
var connections = this.connections[peer];
for (var j = 0, jj = connections.length; j < jj; j += 1) {
connections[j].close();
}
}
};

/**
* Disconnects the Peer's connection to the PeerServer. Does not close any
Expand All @@ -1118,7 +1118,7 @@ Peer.prototype.disconnect = function() {
self.id = null;
}
});
}
};

/** Attempts to reconnect with the same ID. */
Peer.prototype.reconnect = function() {
Expand Down Expand Up @@ -1148,8 +1148,8 @@ Peer.prototype.listAllPeers = function(cb) {
var self = this;
var http = new XMLHttpRequest();
var protocol = this.options.secure ? 'https://' : 'http://';
var url = protocol + this.options.host + ':' + this.options.port
+ this.options.path + this.options.key + '/peers';
var url = protocol + this.options.host + ':' + this.options.port +
this.options.path + this.options.key + '/peers';
var queryString = '?ts=' + new Date().getTime() + '' + Math.random();
url += queryString;

Expand All @@ -1158,30 +1158,30 @@ Peer.prototype.listAllPeers = function(cb) {
http.onerror = function(e) {
self._abort('server-error', 'Could not get peers from the server.');
cb([]);
}
};
http.onreadystatechange = function() {
if (http.readyState !== 4) {
return;
}
if (http.status === 401) {
var helpfulError = '';
if (self.options.host !== util.CLOUD_HOST) {
helpfulError = 'It looks like you\'re using the cloud server. You can email '
+ 'team@peerjs.com to enable peer listing for your API key.';
helpfulError = 'It looks like you\'re using the cloud server. You can email ' +
'team@peerjs.com to enable peer listing for your API key.';
} else {
helpfulError = 'You need to enable `allow_discovery` on your self-hosted'
+ ' PeerServer to use this feature.';
helpfulError = 'You need to enable `allow_discovery` on your self-hosted ' +
'PeerServer to use this feature.';
}
throw new Error('It doesn\'t look like you have permission to list peers IDs. ' + helpfulError);
cb([]);
throw new Error('It doesn\'t look like you have permission to list peers IDs. ' + helpfulError);
} else if (http.status !== 200) {
cb([]);
} else {
cb(JSON.parse(http.responseText));
}
};
http.send(null);
}
};

module.exports = Peer;

Expand Down
Loading

0 comments on commit 9ed9aa8

Please sign in to comment.