diff --git a/lib/server.js b/lib/server.js index 1437acc..a67e41e 100644 --- a/lib/server.js +++ b/lib/server.js @@ -110,7 +110,8 @@ PeerServer.prototype._initializeHTTP = function() { clientId = util.randomId(); } self._startStreaming(res, clientId, function() { - res.write(clientId); + // Chrome hacks. + res.write('{"id":"' + clientId + '"}\n'); }); }); @@ -138,11 +139,18 @@ PeerServer.prototype._initializeHTTP = function() { /** Saves a streaming response and takes care of timeouts and headers. */ PeerServer.prototype._startStreaming = function(res, id, write) { - res.writeHead(200, {'Content-Type': 'text/plain'}); + res.writeHead(200, {'Content-Type': 'application/octet-stream'}); if (!!write) { write(); } + var pad = '00'; + var iterations = 10; + for (var i = 0; i < iterations; i++) { + pad += pad; + } + res.write(pad + '\n'); + // Save res so we can write to it. this._clients[id] = res; @@ -157,6 +165,9 @@ PeerServer.prototype._handleTransmission = function(type, src, dst, data) { if (!!destination) { try { + if (this._timeouts[dst]) + data += '\n'; + destination.send(data); } catch (e) { util.prettyError(e);