Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of github.com:peers/peerjs

  • Loading branch information...
commit 4371d39ed539472ee63b007b30370f5279531a1d 2 parents 28a7d4b + 8323942
@michelle michelle authored
Showing with 12 additions and 10 deletions.
  1. +12 −10 lib/peer.js
View
22 lib/peer.js
@@ -65,13 +65,13 @@ function Peer(id, options) {
this._init();
} else {
this.id = null;
- this._getId();
+ this._retrieveId();
}
};
util.inherits(Peer, EventEmitter);
-Peer.prototype._getId = function(cb) {
+Peer.prototype._retrieveId = function(cb) {
var self = this;
try {
var http = new XMLHttpRequest();
@@ -82,6 +82,10 @@ Peer.prototype._getId = function(cb) {
http.open('get', url, true);
http.onreadystatechange = function() {
if (http.readyState === 4) {
+ if (http.status !== 200) {
+ throw 'Retrieve id response not 200';
+ return;
+ }
self.id = http.responseText;
self._init();
}
@@ -217,15 +221,13 @@ Peer.prototype._abort = function(type, message) {
Peer.prototype._cleanup = function() {
var self = this;
- if (!!this.managers) {
- var peers = Object.keys(this.managers);
- for (var i = 0, ii = peers.length; i < ii; i++) {
- this.managers[peers[i]].close();
- }
- util.setZeroTimeout(function(){
- self.disconnect();
- });
+ var peers = Object.keys(this.managers);
+ for (var i = 0, ii = peers.length; i < ii; i++) {
+ this.managers[peers[i]].close();
}
+ util.setZeroTimeout(function(){
+ self.disconnect();
+ });
this.emit('close');
};
Please sign in to comment.
Something went wrong with that request. Please try again.