getting id works over xhr

This commit is contained in:
Michelle Bu 2013-01-31 11:27:34 -08:00
parent afd9ae0bb5
commit f66efcff91

View File

@ -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);