|
@@ -12,8 +12,11 @@ function Peer(id, options) {
|
|
// First check if browser can use PeerConnection/DataChannels.
|
|
// First check if browser can use PeerConnection/DataChannels.
|
|
// TODO: when media is supported, lower browser version limit and move DC
|
|
// TODO: when media is supported, lower browser version limit and move DC
|
|
// check to where`connect` is called.
|
|
// check to where`connect` is called.
|
|
|
|
+ var self = this;
|
|
if (!util.isBrowserCompatible()) {
|
|
if (!util.isBrowserCompatible()) {
|
|
- this._abort('browser-incompatible', 'The current browser does not support WebRTC DataChannels');
|
|
|
|
|
|
+ util.setZeroTimeout(function() {
|
|
|
|
+ self._abort('browser-incompatible', 'The current browser does not support WebRTC DataChannels');
|
|
|
|
+ });
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -33,18 +36,17 @@ function Peer(id, options) {
|
|
util.debug = options.debug;
|
|
util.debug = options.debug;
|
|
|
|
|
|
// Ensure alphanumeric_-
|
|
// Ensure alphanumeric_-
|
|
- var self = this;
|
|
|
|
if (id && !/^[A-Za-z0-9]+(?:[ _-][A-Za-z0-9]+)*$/.exec(id)) {
|
|
if (id && !/^[A-Za-z0-9]+(?:[ _-][A-Za-z0-9]+)*$/.exec(id)) {
|
|
util.setZeroTimeout(function() {
|
|
util.setZeroTimeout(function() {
|
|
self._abort('invalid-id', 'ID "' + id + '" is invalid');
|
|
self._abort('invalid-id', 'ID "' + id + '" is invalid');
|
|
});
|
|
});
|
|
- return
|
|
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
if (options.key && !/^[A-Za-z0-9]+(?:[ _-][A-Za-z0-9]+)*$/.exec(options.key)) {
|
|
if (options.key && !/^[A-Za-z0-9]+(?:[ _-][A-Za-z0-9]+)*$/.exec(options.key)) {
|
|
util.setZeroTimeout(function() {
|
|
util.setZeroTimeout(function() {
|
|
self._abort('invalid-key', 'API KEY "' + options.key + '" is invalid');
|
|
self._abort('invalid-key', 'API KEY "' + options.key + '" is invalid');
|
|
});
|
|
});
|
|
- return
|
|
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
|
|
|
|
// States.
|
|
// States.
|
|
@@ -172,11 +174,6 @@ Peer.prototype._handleServerJSONMessage = function(message) {
|
|
case 'INVALID-KEY':
|
|
case 'INVALID-KEY':
|
|
this._abort('invalid-key', 'API KEY "' + this._key + '" is invalid');
|
|
this._abort('invalid-key', 'API KEY "' + this._key + '" is invalid');
|
|
break;
|
|
break;
|
|
- case 'PORT':
|
|
|
|
- //if (util.browserisms === 'Firefox') {
|
|
|
|
- // connection.handlePort(payload);
|
|
|
|
- // break;
|
|
|
|
- //}
|
|
|
|
default:
|
|
default:
|
|
util.log('Unrecognized message type:', message.type);
|
|
util.log('Unrecognized message type:', message.type);
|
|
break;
|
|
break;
|
|
@@ -221,9 +218,11 @@ Peer.prototype._abort = function(type, message) {
|
|
|
|
|
|
Peer.prototype._cleanup = function() {
|
|
Peer.prototype._cleanup = function() {
|
|
var self = this;
|
|
var self = this;
|
|
- var peers = Object.keys(this.managers);
|
|
|
|
- for (var i = 0, ii = peers.length; i < ii; i++) {
|
|
|
|
- this.managers[peers[i]].close();
|
|
|
|
|
|
+ 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(){
|
|
util.setZeroTimeout(function(){
|
|
self.disconnect();
|
|
self.disconnect();
|
|
@@ -232,7 +231,6 @@ Peer.prototype._cleanup = function() {
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
/** Exposed connect function for users. Will try to connect later if user
|
|
/** Exposed connect function for users. Will try to connect later if user
|
|
* is waiting for an ID. */
|
|
* is waiting for an ID. */
|
|
Peer.prototype.connect = function(peer, options) {
|
|
Peer.prototype.connect = function(peer, options) {
|