Эх сурвалжийг харах

getting id works over xhr

Michelle Bu 12 жил өмнө
parent
commit
f66efcff91
1 өөрчлөгдсөн 13 нэмэгдсэн , 2 устгасан
  1. 13 2
      lib/server.js

+ 13 - 2
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);