|
@@ -5,12 +5,12 @@
|
|
|
function Socket(host, port, key, id) {
|
|
|
if (!(this instanceof Socket)) return new Socket(host, port, key, id);
|
|
|
EventEmitter.call(this);
|
|
|
-
|
|
|
+
|
|
|
this._id = id;
|
|
|
var token = util.randomToken();
|
|
|
|
|
|
this.disconnected = false;
|
|
|
-
|
|
|
+
|
|
|
this._httpUrl = 'http://' + host + ':' + port + '/' + key + '/' + id + '/' + token;
|
|
|
this._wsUrl = 'ws://' + host + ':' + port + '/peerjs?key='+key+'&id='+id+'&token='+token;
|
|
|
};
|
|
@@ -34,7 +34,7 @@ Socket.prototype._startWebSocket = function() {
|
|
|
}
|
|
|
|
|
|
this._socket = new WebSocket(this._wsUrl);
|
|
|
-
|
|
|
+
|
|
|
this._socket.onmessage = function(event) {
|
|
|
var data;
|
|
|
try {
|
|
@@ -156,7 +156,7 @@ Socket.prototype.send = function(data) {
|
|
|
this.emit('error', 'Invalid message');
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
var message = JSON.stringify(data);
|
|
|
if (this._wsOpen()) {
|
|
|
this._socket.send(message);
|