瀏覽代碼

open in right place

Michelle Bu 12 年之前
父節點
當前提交
887c2a851e
共有 1 個文件被更改,包括 3 次插入9 次删除
  1. 3 9
      lib/peer.js

+ 3 - 9
lib/peer.js

@@ -49,12 +49,6 @@ Peer.prototype._startSocket = function() {
   this._socket.on('message', function(data) {
   this._socket.on('message', function(data) {
     self._handleServerJSONMessage(data);
     self._handleServerJSONMessage(data);
   });
   });
-  this._socket.on('open', function() {
-    if (self.id) {
-      self.emit('open', self.id);
-      self._processQueue();
-    }
-  });
   this._socket.on('error', function(error) {
   this._socket.on('error', function(error) {
     util.log(error);
     util.log(error);
     self.emit('error', error);
     self.emit('error', error);
@@ -74,13 +68,13 @@ Peer.prototype._handleServerJSONMessage = function(message) {
   var peer = message.src;
   var peer = message.src;
   var connection = this.connections[peer];
   var connection = this.connections[peer];
   switch (message.type) {
   switch (message.type) {
-    case 'ID':
+    case 'OPEN':
       if (!this.id) {
       if (!this.id) {
         // If we're just now getting an ID then we may have a queue.
         // If we're just now getting an ID then we may have a queue.
         this.id = message.id;
         this.id = message.id;
-        this.emit('open', this.id);
-        this._processQueue();
       }
       }
+      this.emit('open', this.id);
+      this._processQueue();
       break;
       break;
     case 'ERROR':
     case 'ERROR':
       this.emit('error', message.msg);
       this.emit('error', message.msg);