Explorar o código

fixed data handler bugs and binarypack migration

Michelle Bu %!s(int64=12) %!d(string=hai) anos
pai
achega
cfbe862c25
Modificáronse 4 ficheiros con 17 adicións e 14 borrados
  1. 1 1
      public/js/binarypack
  2. 8 7
      public/js/sink.js
  3. 7 5
      public/js/source.js
  4. 1 1
      public/sinkoriginator.html

+ 1 - 1
public/js/binarypack

@@ -1 +1 @@
-Subproject commit 69e5a2a2c07f00e3b259171c0b02c3b6a33074c4
+Subproject commit 6509cf76ef8ce490f0882f51452718790835fff3

+ 8 - 7
public/js/sink.js

@@ -145,7 +145,7 @@ SinkPeer.prototype.setupDataChannel = function(originator, target, cb) {
         console.log('ORIGINATOR: onconnection triggered');
 
         self._dc = self._pc.createDataChannel('StreamAPI', {}, target);
-        self._dc.binaryType = 'arraybuffer';
+        self._dc.binaryType = 'blob';
 
         if (!!self._connectionHandler) {
           self._connectionHandler(target);
@@ -160,7 +160,7 @@ SinkPeer.prototype.setupDataChannel = function(originator, target, cb) {
       this._pc.ondatachannel = function(dc) {
         console.log('SINK: ondatachannel triggered');
         self._dc = dc;
-        self._dc.binaryType = 'arraybuffer';
+        self._dc.binaryType = 'blob';
 
         if (!!self._connectionHandler) {
           self._connectionHandler(target);
@@ -192,11 +192,11 @@ SinkPeer.prototype.send = function(data) {
 // Handles a DataChannel message.
 // TODO: have these extend Peer, which will impl these generic handlers.
 SinkPeer.prototype.handleDataMessage = function(e) {
-  data = BinaryPack.unpack(e.data);
-
-  if (!!this._dataHandler) {
-    this._dataHandler(data);
-  }
+  BinaryPack.unpack(e.data, function(msg) {
+    if (!!this._dataHandler) {
+      this._dataHandler(msg);
+    }
+  });
 }
 
 
@@ -210,6 +210,7 @@ SinkPeer.prototype.on = function(code, cb) {
   } else if (code === 'ready') {
     this._readyHandler = cb;
   } else if (code === 'connection') {
+    console.log('poop');
     this._connectionHandler = cb;
   }
 }

+ 7 - 5
public/js/source.js

@@ -106,7 +106,7 @@ SourcePeer.prototype.setupDataChannel = function(pc, target, cb) {
     console.log('SOURCE: onconnection triggered.');
     var dc = pc.createDataChannel(self._name, {}, target);
     self._dcs[target] = dc;
-    dc.binaryType = 'arraybuffer';
+    dc.binaryType = 'blob';
 
     // User handler
     if (!!self._sinkHandler) {
@@ -148,16 +148,18 @@ SourcePeer.prototype.send = function(data, sink) {
 
 // Handles a DataChannel message.
 SourcePeer.prototype.handleDataMessage = function(e) {
-  var data = BinaryPack.unpack(e.data);
+  BinaryPack.unpack(e.data, function(msg) {
+    if (!!this._dataHandler) {
+      this._dataHandler(msg);
+    }
+  });
 
-  if (!!this._dataHandler) {
-    this._dataHandler(data);
-  }
 }
 
 
 SourcePeer.prototype.on = function(code, cb) {
   // For enduser.
+  // MAKE A HASH
   if (code === 'data') {
     this._dataHandler = cb;
   } else if (code === 'sink') {

+ 1 - 1
public/sinkoriginator.html

@@ -9,7 +9,6 @@
 
 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> 
 <script src="/socket.io/socket.io.js"></script>
-<script type="text/javascript" src="/js/msgpack/msgpack.js"></script>
 <script type="text/javascript" src="/js/binarypack/dist/binarypack.js"></script>
 <script type="text/javascript" src="/js/adapter.js"></script>
 <script type="text/javascript" src="/js/sink.js"></script>
@@ -20,6 +19,7 @@ $(document).ready(function() {
     console.log(id);
   });
   originator.on('connection', function(recipient) {
+    console.log('connection');
     originator.send('Hi there!');
   });
   originator.on('data', function(data) {