Michelle Bu 12 years ago
parent
commit
94e9386b08
3 changed files with 8 additions and 4 deletions
  1. 2 1
      lib/dataconnection.js
  2. 1 1
      lib/mediaconnection.js
  3. 5 2
      lib/peer.js

+ 2 - 1
lib/dataconnection.js

@@ -27,7 +27,7 @@ function DataConnection(peer, provider, options) {
     this.peer,
     this.id,
     this.provider,
-    this.options._payload
+    this.options._payload || {originator: true}
   );
 }
 
@@ -165,6 +165,7 @@ DataConnection.prototype.handleMessage = function(message) {
       Negotiator.handleSDP(this.peer, this.id, payload.sdp, message.type);
       break;
     case 'CANDIDATE':
+      // TODO
       Negotiator.handleCandidate(this.peer, this.id, payload.candidate);
       break;
     default:

+ 1 - 1
lib/mediaconnection.js

@@ -21,7 +21,7 @@ function MediaConnection(peer, provider, options) {
       this.peer,
       this.id,
       this.provider,
-      { _stream: this.localStream }
+      {_stream: this.localStream, originator: true  }
     )
   }
 };

+ 5 - 2
lib/peer.js

@@ -66,7 +66,8 @@ function Peer(id, options) {
 
   // States.
   this.destroyed = false; // Connections have been killed
-  this.disconnected = false; // Connection to PeerServer killed but P2P connections still active
+  this.disconnected = false; // Connection to PeerServer killed manually but P2P connections still active
+  this.open = false; // Sockets and such are not yet open.
   //
 
   // References
@@ -130,7 +131,7 @@ Peer.prototype._initialize = function(id) {
   });
   this.socket.on('close', function() {
     if (!self.disconnected) { // If we haven't explicitly disconnected, emit error.
-      self._abort('socket-closed', 'Underlying socket has closed');
+      self._abort('socket-closed', 'Underlying socket is already closed.');
     }
   });
   this.socket.start();
@@ -145,6 +146,7 @@ Peer.prototype._handleMessage = function(message) {
   switch (type) {
     case 'OPEN': // The connection to the server is open.
       this.emit('open', this.id);
+      this.open = true;
       break;
     case 'ERROR': // Server error.
       this._abort('server-error', payload.msg);
@@ -318,6 +320,7 @@ Peer.prototype.disconnect = function() {
   util.setZeroTimeout(function(){
     if (!self.disconnected) {
       self.disconnected = true;
+      self.open = false;
       if (self.socket) {
         self.socket.close();
       }