Permalink
Browse files

fix msgpack imports for browsers; forward transport info to onjoin

  • Loading branch information...
1 parent 1e7f22e commit 2b9af4a71151fbe0d6e7e3f4745176fefb7ca90c @oberstet oberstet committed Nov 16, 2016
Showing with 43 additions and 44 deletions.
  1. +3 −0 lib/autobahn.js
  2. +3 −1 lib/connection.js
  3. +35 −40 lib/serializer.js
  4. +2 −3 package.json
View
@@ -19,6 +19,8 @@ var pjson = require('../package.json');
var when = require('when');
//var fn = require("when/function");
+var msgpack = require('msgpack-lite');
+
if ('AUTOBAHN_DEBUG' in global && AUTOBAHN_DEBUG) {
// https://github.com/cujojs/when/blob/master/docs/api.md#whenmonitor
require('when/monitor/console');
@@ -58,6 +60,7 @@ exports.auth_persona = persona.auth;
exports.auth_cra = cra;
exports.when = when;
+exports.msgpack = msgpack;
exports.util = util;
exports.log = log;
View
@@ -314,6 +314,8 @@ Connection.prototype.open = function () {
self._session.onjoin = function (details) {
if (self.onopen) {
try {
+ // forward transport info ..
+ details.transport = self._transport.info;
self.onopen(self._session, details);
} catch (e) {
log.debug("Exception raised from app code while firing Connection.onopen()", e);
@@ -352,7 +354,7 @@ Connection.prototype.open = function () {
} else {
reason = "closed";
}
-
+
var next_retry = self._autoreconnect_advance();
// fire app code handler
View
@@ -12,6 +12,7 @@
///////////////////////////////////////////////////////////////////////////////
var log = require('./log.js');
+var msgpack = require('msgpack-lite');
function JSONSerializer(replacer, reviver) {
this.replacer = replacer;
@@ -31,48 +32,42 @@ JSONSerializer.prototype.unserialize = function (payload) {
exports.JSONSerializer = JSONSerializer;
-try {
- var msgpack = require('msgpack-lite');
+var msgpack = require('msgpack-lite');
- function MsgpackSerializer() {
- this.SERIALIZER_ID = 'msgpack';
- this.BINARY = true;
- this.codec = msgpack.createCodec();
- }
-
- MsgpackSerializer.prototype.serialize = function (obj) {
- return msgpack.encode(obj, {codec: this.codec});
- };
+function MsgpackSerializer() {
+ this.SERIALIZER_ID = 'msgpack';
+ this.BINARY = true;
+ this.codec = msgpack.createCodec();
+}
- MsgpackSerializer.prototype.unserialize = function (payload) {
- // need to encapsulate ArrayBuffer into Uint8Array for msgpack decoding
- // https://github.com/kawanet/msgpack-lite/issues/44
- return msgpack.decode(new Uint8Array(payload), {codec: this.codec});
- };
+MsgpackSerializer.prototype.serialize = function (obj) {
+ return msgpack.encode(obj, {codec: this.codec});
+};
- /**
- * Register a packer and/or unpacker functions for a given type.
- *
- * The msgpack specification allows applications to register up to 128 extension
- * types.
- *
- * @param code numeric extension code (between 0-127)
- * @param type constructor for the given type (only required when packer is defined)
- * @param packer a function that takes an object and returns a Buffer
- * @param unpacker a function that takes a Buffer and returns an instance of the given type
- */
- MsgpackSerializer.prototype.registerExtType = function (code, type, packer, unpacker) {
- if (packer && type) {
- this.codec.addExtPacker(code, type, packer);
- }
- if (unpacker) {
- this.codec.addExtUnpacker(code, unpacker);
- }
- };
+MsgpackSerializer.prototype.unserialize = function (payload) {
+ // need to encapsulate ArrayBuffer into Uint8Array for msgpack decoding
+ // https://github.com/kawanet/msgpack-lite/issues/44
+ return msgpack.decode(new Uint8Array(payload), {codec: this.codec});
+};
- exports.MsgpackSerializer = MsgpackSerializer;
-} catch (err) {
+/**
+ * Register a packer and/or unpacker functions for a given type.
+ *
+ * The msgpack specification allows applications to register up to 128 extension
+ * types.
+ *
+ * @param code numeric extension code (between 0-127)
+ * @param type constructor for the given type (only required when packer is defined)
+ * @param packer a function that takes an object and returns a Buffer
+ * @param unpacker a function that takes a Buffer and returns an instance of the given type
+ */
+MsgpackSerializer.prototype.registerExtType = function (code, type, packer, unpacker) {
+ if (packer && type) {
+ this.codec.addExtPacker(code, type, packer);
+ }
+ if (unpacker) {
+ this.codec.addExtUnpacker(code, unpacker);
+ }
+};
- log.debug('WARNING: could not setup msgpack serializer: ' + err);
- exports.MsgpackSerializer = null;
-}
+exports.MsgpackSerializer = MsgpackSerializer;
View
@@ -1,6 +1,6 @@
{
"name": "autobahn",
- "version": "0.11.0",
+ "version": "0.11.1",
"description": "An implementation of The Web Application Messaging Protocol (WAMP).",
"main": "index.js",
"scripts": {
@@ -24,8 +24,7 @@
},
"browser": {
"ws": false,
- "lib/transport/rawsocket.js": false,
- "msgpack-lite": "msgpack-lite/global"
+ "lib/transport/rawsocket.js": false
},
"repository": {
"type": "git",

0 comments on commit 2b9af4a

Please sign in to comment.