|
@@ -67,7 +67,8 @@ PeerServer.prototype._initializeWSS = function() {
|
|
delete self._timeouts[id];
|
|
delete self._timeouts[id];
|
|
self._clients[id].end(JSON.stringify({ type: 'HTTP-SOCKET' }));
|
|
self._clients[id].end(JSON.stringify({ type: 'HTTP-SOCKET' }));
|
|
} else {
|
|
} else {
|
|
- socket.send(JSON.stringify({ type: 'ERROR', msg: 'ID is taken' }));
|
|
|
|
|
|
+ socket.send(JSON.stringify({ type: 'ID-TAKEN', msg: 'ID is taken' }));
|
|
|
|
+ socket.close();
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
} else if (id === undefined) {
|
|
} else if (id === undefined) {
|
|
@@ -108,10 +109,10 @@ PeerServer.prototype._initializeWSS = function() {
|
|
self._handleTransmission(message);
|
|
self._handleTransmission(message);
|
|
break;
|
|
break;
|
|
default:
|
|
default:
|
|
- util.prettyError('message unrecognized');
|
|
|
|
|
|
+ util.prettyError('Message unrecognized');
|
|
}
|
|
}
|
|
} catch(e) {
|
|
} catch(e) {
|
|
- util.log('invalid message');
|
|
|
|
|
|
+ util.log('Invalid message', data);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
});
|
|
});
|
|
@@ -214,7 +215,6 @@ PeerServer.prototype._startStreaming = function(res, id, write) {
|
|
}, 30000);
|
|
}, 30000);
|
|
this._processOutstandingOffers(id);
|
|
this._processOutstandingOffers(id);
|
|
} else {
|
|
} else {
|
|
- res.write(JSON.stringify({ type: 'ERROR', msg: 'ID is taken' }) + '\n');
|
|
|
|
res.end(JSON.stringify({ type: 'HTTP-ERROR' }));
|
|
res.end(JSON.stringify({ type: 'HTTP-ERROR' }));
|
|
}
|
|
}
|
|
|
|
|
|
@@ -266,7 +266,7 @@ PeerServer.prototype._handleTransmission = function(message, res) {
|
|
setTimeout(function() {
|
|
setTimeout(function() {
|
|
if(!!self._outstandingOffers[dst][src]) {
|
|
if(!!self._outstandingOffers[dst][src]) {
|
|
delete self._outstandingOffers[dst][src];
|
|
delete self._outstandingOffers[dst][src];
|
|
- this._handleTransmission({
|
|
|
|
|
|
+ self._handleTransmission({
|
|
type: 'EXPIRE',
|
|
type: 'EXPIRE',
|
|
src: dst,
|
|
src: dst,
|
|
dst: src
|
|
dst: src
|
|
@@ -275,10 +275,10 @@ PeerServer.prototype._handleTransmission = function(message, res) {
|
|
}, this._options.timeout);
|
|
}, this._options.timeout);
|
|
}
|
|
}
|
|
this._outstandingOffers[dst][src].push(Array.prototype.slice.apply(arguments));
|
|
this._outstandingOffers[dst][src].push(Array.prototype.slice.apply(arguments));
|
|
- res.send(200);
|
|
|
|
|
|
+ if (!!res) res.send(200);
|
|
} else if (type === 'LEAVE' && !dst) {
|
|
} else if (type === 'LEAVE' && !dst) {
|
|
this._removePeer(src);
|
|
this._removePeer(src);
|
|
- res.send(200);
|
|
|
|
|
|
+ if (!!res) res.send(200);
|
|
} else {
|
|
} else {
|
|
// Assume a disconnect if the client no longer exists.
|
|
// Assume a disconnect if the client no longer exists.
|
|
this._handleTransmission({
|
|
this._handleTransmission({
|