Michelle Bu il y a 12 ans
Parent
commit
ee3bb9e9ee
5 fichiers modifiés avec 21 ajouts et 12 suppressions
  1. 7 4
      demo/static/peer.js
  2. 4 2
      demo/static/sink.html
  3. 3 2
      demo/static/sinkoriginator.html
  4. 7 4
      dist/peer.js
  5. 0 0
      dist/peer.min.js

+ 7 - 4
demo/static/peer.js

@@ -974,6 +974,7 @@ function DataConnection(options, socket, cb) {
       self._maybeBrowserisms();
 
     }, function(err) {
+      this._cb('failed to setRemoteDescription');
       util.log('failed to setRemoteDescription with offer, ', err);
     });
   }
@@ -1004,6 +1005,7 @@ DataConnection.prototype.handleAnswer = function(message) {
     }
     util.log('ORIGINATOR: PeerConnection success');
   }, function(err) {
+    this._cb('failed to setRemoteDescription');
     util.log('failed to setRemoteDescription, ', err);
   });
 };
@@ -1113,12 +1115,11 @@ DataConnection.prototype._startDataChannel = function() {
   var self = this;
   this._dc = this._pc.createDataChannel(this._peer, { reliable: false });
   this._dc.binaryType = 'blob';
-
-  this._cb(null, self);
-
   this._dc.onmessage = function(e) {
     self._handleDataMessage(e);
   };
+
+  this._cb(null, self);
 };
 
 
@@ -1160,9 +1161,11 @@ DataConnection.prototype._makeAnswer = function() {
         dst: self._peer
       }));
     }, function(err) {
+      self._cb('failed to setLocalDescription');
       util.log('failed to setLocalDescription, ', err)
     });
   }, function(err) {
+    self._cb('failed to create answer');
     util.log('failed to create answer, ', err)
   });
 };
@@ -1183,6 +1186,7 @@ DataConnection.prototype._makeOffer = function() {
         metadata: self._metadata
       }));
     }, function(err) {
+      self._cb('failed to setLocalDescription');
       util.log('failed to setLocalDescription, ', err);
     });
   });
@@ -1203,7 +1207,6 @@ DataConnection.prototype._handleDataMessage = function(e) {
   fr.onload = function(evt) {
     var ab = evt.target.result;
     var data = BinaryPack.unpack(ab);
-    console.log(data);
 
     self.emit('data', data);
   };

+ 4 - 2
demo/static/sink.html

@@ -19,11 +19,13 @@ $(document).ready(function() {
     sink.on('ready', function() {
       sink.connect(source, { username: 'michelle' }, function(err, connection) {
         console.log(connection);
+
         connection.on('data', function(data) {
           console.log(data);
         });
-        connection.send('I am so scared.');
-        connections['hi'] = connection;
+
+        connection.send('Hi there!');
+        connections[source] = connection;
       });
     });
   });

+ 3 - 2
demo/static/sinkoriginator.html

@@ -11,6 +11,7 @@
 <script type="text/javascript" src="/peer.js"></script>
 <script>
 $(document).ready(function() {
+  connections = {};
   originator = new Peer({ ws: 'ws://localhost:9000', debug: true });
   originator.on('ready', function(id) {
     console.log(id);
@@ -20,8 +21,8 @@ $(document).ready(function() {
     connection.on('data', function(data) {
       console.log(data);
     });
-    connection.send('Hi there!');
-    c = connection;
+    connection.send('What is going on?');
+    connections[connection.metadata.username] = connection;
   });
 });
 

+ 7 - 4
dist/peer.js

@@ -974,6 +974,7 @@ function DataConnection(options, socket, cb) {
       self._maybeBrowserisms();
 
     }, function(err) {
+      this._cb('failed to setRemoteDescription');
       util.log('failed to setRemoteDescription with offer, ', err);
     });
   }
@@ -1004,6 +1005,7 @@ DataConnection.prototype.handleAnswer = function(message) {
     }
     util.log('ORIGINATOR: PeerConnection success');
   }, function(err) {
+    this._cb('failed to setRemoteDescription');
     util.log('failed to setRemoteDescription, ', err);
   });
 };
@@ -1113,12 +1115,11 @@ DataConnection.prototype._startDataChannel = function() {
   var self = this;
   this._dc = this._pc.createDataChannel(this._peer, { reliable: false });
   this._dc.binaryType = 'blob';
-
-  this._cb(null, self);
-
   this._dc.onmessage = function(e) {
     self._handleDataMessage(e);
   };
+
+  this._cb(null, self);
 };
 
 
@@ -1160,9 +1161,11 @@ DataConnection.prototype._makeAnswer = function() {
         dst: self._peer
       }));
     }, function(err) {
+      self._cb('failed to setLocalDescription');
       util.log('failed to setLocalDescription, ', err)
     });
   }, function(err) {
+    self._cb('failed to create answer');
     util.log('failed to create answer, ', err)
   });
 };
@@ -1183,6 +1186,7 @@ DataConnection.prototype._makeOffer = function() {
         metadata: self._metadata
       }));
     }, function(err) {
+      self._cb('failed to setLocalDescription');
       util.log('failed to setLocalDescription, ', err);
     });
   });
@@ -1203,7 +1207,6 @@ DataConnection.prototype._handleDataMessage = function(e) {
   fr.onload = function(evt) {
     var ab = evt.target.result;
     var data = BinaryPack.unpack(ab);
-    console.log(data);
 
     self.emit('data', data);
   };

Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
dist/peer.min.js


Certains fichiers n'ont pas été affichés car il y a eu trop de fichiers modifiés dans ce diff