Forráskód Böngészése

making some vars public

ericz 12 éve
szülő
commit
796303c97c
1 módosított fájl, 17 hozzáadás és 22 törlés
  1. 17 22
      lib/connection.js

+ 17 - 22
lib/connection.js

@@ -14,11 +14,11 @@ function DataConnection(id, peer, socket, cb, options) {
   // Connection is not open yet
   this.open = false;
   
-  this._id = id;
-  this._peer = peer;
+  this.id = id;
+  this.peer = peer;
   this._originator = (options.sdp === undefined);
   this._cb = cb;
-  this._metadata = options.metadata;
+  this.metadata = options.metadata;
 
   this._socket = socket;
 
@@ -68,7 +68,7 @@ DataConnection.prototype._setupDataChannel = function() {
   var self = this;
   if (this._originator) {
     util.log('Creating data channel');
-    this._dc = this._pc.createDataChannel(this._peer, { reliable: this._options.reliable });
+    this._dc = this._pc.createDataChannel(this.peer, { reliable: this._options.reliable });
     this._configureDataChannel();
   } else {
     util.log('Listening for data channel');
@@ -98,8 +98,8 @@ DataConnection.prototype._setupIce = function() {
       self._socket.send({
         type: 'CANDIDATE',
         candidate: evt.candidate,
-        dst: self._peer,
-        src: self._id
+        dst: self.peer,
+        src: self.id
       });
     }
   };
@@ -132,6 +132,7 @@ DataConnection.prototype._configureDataChannel = function() {
   this._dc.onopen = function() {
     util.log('Data channel connection success');
     self.open = true;
+    self.emit('open');
     self._callback(null, self);
   };
   this._dc.onmessage = function(e) {
@@ -157,12 +158,11 @@ DataConnection.prototype._makeOffer = function() {
     util.log('Created offer');
     self._pc.setLocalDescription(offer, function() {
       util.log('Set localDescription to offer');
-      //self._peerReady = false;
       self._socket.send({
         type: 'OFFER',
         sdp: offer,
-        dst: self._peer,
-        src: self._id,
+        dst: self.peer,
+        src: self.id,
         metadata: self.metadata
       });
     }, function(err) {
@@ -181,9 +181,9 @@ DataConnection.prototype._makeAnswer = function() {
       util.log('Set localDescription to answer');
       self._socket.send({
         type: 'ANSWER',
-        src: self._id,
+        src: self.id,
         sdp: answer,
-        dst: self._peer
+        dst: self.peer
       });
     }, function(err) {
       self._callback('Failed to setLocalDescription');
@@ -205,7 +205,7 @@ DataConnection.prototype._cleanup = function() {
     this._pc.close();
     this._pc = null;
   }
-  this.emit('close', this._peer);
+  this.emit('close', this.peer);
 };
 
 // Make sure _cb only gets called once
@@ -247,8 +247,8 @@ DataConnection.prototype.close = function(reason) {
   if (this.open) {
     this._socket.send({
       type: 'LEAVE',
-      dst: self._peer,
-      src: self._id,
+      dst: self.peer,
+      src: self.id,
     });
   } else {
     this._callback(reason);
@@ -270,11 +270,6 @@ DataConnection.prototype.send = function(data) {
   }
 };
 
-DataConnection.prototype.getMetadata = function() {
-  return this._metadata;
-};
-
-
 DataConnection.prototype.handleSDP = function(message) {
   var sdp = message.sdp;
   if (util.browserisms != 'Firefox') {
@@ -288,8 +283,8 @@ DataConnection.prototype.handleSDP = function(message) {
       self._pc.connectDataConnection(self.localPort, self.remotePort);
       self._socket.send({
         type: 'PORT',
-        dst: self._peer,
-        src: self._id,
+        dst: self.peer,
+        src: self.id,
         remote: self.localPort,
         local: self.remotePort
       });
@@ -311,7 +306,7 @@ DataConnection.prototype.handleCandidate = function(message) {
 
 
 DataConnection.prototype.handleLeave = function() {
-  util.log('Peer ' + this._peer + ' disconnected');
+  util.log('Peer ' + this.peer + ' disconnected');
   this._cleanup();
 };