|
@@ -4,14 +4,16 @@ function Peer(options) {
|
|
|
|
|
|
options = util.extend({
|
|
|
debug: false,
|
|
|
- peer: 'ws://localhost'
|
|
|
+ server: 'localhost'
|
|
|
}, options);
|
|
|
this.options = options;
|
|
|
util.debug = options.debug;
|
|
|
|
|
|
- this._id = null;
|
|
|
+ this._id = options.id;
|
|
|
+ // Not used unless using cloud server.
|
|
|
+ this._api_key = options.api_key;
|
|
|
|
|
|
- this._socket = new WebSocket(options.ws);
|
|
|
+ this._socket = new WebSocket('ws://' + options.server);
|
|
|
this._socketInit();
|
|
|
|
|
|
// Connections for this peer.
|
|
@@ -20,6 +22,9 @@ function Peer(options) {
|
|
|
// Queued connections to make.
|
|
|
this._queued = [];
|
|
|
|
|
|
+ // If no ID provided, get a unique ID from server.
|
|
|
+
|
|
|
+
|
|
|
// Make sure connections are cleaned up.
|
|
|
window.onbeforeunload = this._cleanup;
|
|
|
};
|
|
@@ -71,10 +76,7 @@ Peer.prototype._socketInit = function() {
|
|
|
}
|
|
|
};
|
|
|
this._socket.onopen = function() {
|
|
|
- // Announce as a PEER to receive an ID.
|
|
|
- self._socket.send(JSON.stringify({
|
|
|
- type: 'PEER'
|
|
|
- }));
|
|
|
+ self._use_socket = true;
|
|
|
};
|
|
|
};
|
|
|
|