Skip to content

Commit

Permalink
work out glitches
Browse files Browse the repository at this point in the history
  • Loading branch information
oberstet committed Mar 16, 2018
1 parent 7269d73 commit 0430d19
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 95 deletions.
69 changes: 45 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,49 @@ default:
@echo " - publish_browser Publish the browser version of the library"
@echo " - publish_npm Publish the npm version of the library"


#
# Cleanup targets
#
clean:
rm -rf build
sudo rm -rf build

dist_clean: clean
rm -rf ./node_modules
rm -f .sconsign.dblite
sudo rm -rf ./node_modules
sudo rm -f .sconsign.dblite


#
# Docker based build targets (normally, use these!)
#

# build Docker toolchain image
docker_build_toolchain:
docker build \
-t autobahnjs-toolchain \
-f Dockerfile \
.

docker_toolchain_shell:
docker run -it --rm \
--net=host \
-v ${PWD}:/work \
autobahnjs-toolchain \
bash

# use the Docker toolchain image to build AutobahnJS
# for browsers
docker_build_browser:
docker run -it --rm \
--net=host \
-v ${PWD}:/work \
autobahnjs-toolchain \
make browser_deps build_browser


#
# host native build targets
#
requirements:
pip install -U scons boto taschenmesser
sudo apt update
Expand All @@ -27,7 +63,6 @@ browser_deps:
npm install
npm update


build_browser:
scons
java -jar /usr/local/lib/node_modules/google-closure-compiler/compiler.jar --version
Expand All @@ -36,26 +71,9 @@ build_npm:
@echo "Ok, npm doesn't need a build step"


# build Docker toolchain image
build_toolchain:
docker build -t autobahnjs-toolchain -f Dockerfile .

# use the Docker toolchain image to build AutobahnJS
build:
docker run -it --rm \
--net=host \
-v ${PWD}:/work \
autobahnjs-toolchain \
make browser_deps build_browser

build_shell:
docker run -it --rm \
--net=host \
-v ${PWD}:/work \
autobahnjs-toolchain \
bash


#
# Package publication targets
#
publish: publish_browser publish_npm

publish_browser:
Expand All @@ -69,6 +87,9 @@ publish_npm: build_npm
npm publish


#
# Test targets
#
crossbar:
crossbar start

Expand Down
3 changes: 2 additions & 1 deletion SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ Depends(ab, sources)
ab_min = env.JavaScript("build/autobahn.min.js",
ab,
#JS_COMPILATION_LEVEL = "ADVANCED_OPTIMIZATIONS")
JS_COMPILATION_LEVEL = "SIMPLE_OPTIMIZATIONS")
JS_COMPILATION_LEVEL = "SIMPLE_OPTIMIZATIONS",
JS_OUTPUT_LANG = "ES5")

# minimized & compressed
ab_min_gz = env.GZip("build/autobahn.min.jgz",
Expand Down
120 changes: 64 additions & 56 deletions lib/serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,69 +56,77 @@ JSONSerializer.prototype.unserialize = function (payload) {
exports.JSONSerializer = JSONSerializer;


// https://github.com/mcollina/msgpack5
var msgpack = require('msgpack5')({forceFloat64: true});
try {
// https://github.com/mcollina/msgpack5
var msgpack = require('msgpack5')({forceFloat64: true});

function MsgpackSerializer() {
this.SERIALIZER_ID = 'msgpack';
this.BINARY = true;
function MsgpackSerializer() {
this.SERIALIZER_ID = 'msgpack';
this.BINARY = true;

this.newid = newid;
}

MsgpackSerializer.prototype.serialize = function (obj) {
try {
var payload = msgpack.encode(obj);
return payload;
} catch (e) {
log.warn('MessagePack encoding error', e);
throw e;
}
};

MsgpackSerializer.prototype.unserialize = function (payload) {
try {
var obj = msgpack.decode(payload);
return obj;
} catch (e) {
log.warn('MessagePack decoding error', e);
throw e;
this.newid = newid;
}
};

exports.MsgpackSerializer = MsgpackSerializer;

MsgpackSerializer.prototype.serialize = function (obj) {
try {
var payload = msgpack.encode(obj);
return payload;
} catch (e) {
log.warn('MessagePack encoding error', e);
throw e;
}
};

MsgpackSerializer.prototype.unserialize = function (payload) {
try {
var obj = msgpack.decode(payload);
return obj;
} catch (e) {
log.warn('MessagePack decoding error', e);
throw e;
}
};

exports.MsgpackSerializer = MsgpackSerializer;
} catch (e) {
log.warn('msgpack serializer not available', e);
}

// http://hildjj.github.io/node-cbor/
var cbor = require('cbor');

function CBORSerializer() {
this.SERIALIZER_ID = 'cbor';
this.BINARY = true;

// CBOR encoder does not need anything special here
this.newid = newid;
}
try {
// http://hildjj.github.io/node-cbor/
var cbor = require('cbor');

CBORSerializer.prototype.serialize = function (obj) {
try {
var payload = cbor.encode(obj);
return payload;
} catch (e) {
log.warn('CBOR encoding error', e);
throw e;
}
};
function CBORSerializer() {
this.SERIALIZER_ID = 'cbor';
this.BINARY = true;

CBORSerializer.prototype.unserialize = function (payload) {
try {
//var obj = cbor.decodeAllSync(payload)[0];
var obj = cbor.decodeFirstSync(payload);
return obj;
} catch (e) {
log.warn('CBOR decoding error', e);
throw e;
// CBOR encoder does not need anything special here
this.newid = newid;
}
};

exports.CBORSerializer = CBORSerializer;
CBORSerializer.prototype.serialize = function (obj) {
try {
var payload = cbor.encode(obj);
return payload;
} catch (e) {
log.warn('CBOR encoding error', e);
throw e;
}
};

CBORSerializer.prototype.unserialize = function (payload) {
try {
//var obj = cbor.decodeAllSync(payload)[0];
var obj = cbor.decodeFirstSync(payload);
return obj;
} catch (e) {
log.warn('CBOR decoding error', e);
throw e;
}
};

exports.CBORSerializer = CBORSerializer;
} catch (e) {
log.warn('cbor serializer not available', e);
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "autobahn",
"version": "17.5.2",
"version": "18.3.1",
"description": "An implementation of The Web Application Messaging Protocol (WAMP).",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -29,7 +29,8 @@
},
"browser": {
"ws": false,
"lib/transport/rawsocket.js": false
"lib/transport/rawsocket.js": false,
"cbor": false
},
"repository": {
"type": "git",
Expand Down
10 changes: 5 additions & 5 deletions test/test_pubsub_multiple_matching_subs.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,19 @@ exports.testPubsubMultipleMatchingSubs = function (testcase) {
var dl3 = [];

// these are received in sessions b-e
dl3.push(publish_later(session_a, 100, 'com.myapp.topic1', [msg, counter++], null, options));
dl3.push(publish_later(session_a, 500, 'com.myapp.topic1', [msg, counter++], null, options));

// these are received in sessions c and d
dl3.push(publish_later(session_a, 200, 'com.myapp.topic123', [msg, counter++], null, options));
dl3.push(publish_later(session_a, 1000, 'com.myapp.topic123', [msg, counter++], null, options));

// these are received in sessions c and d
dl3.push(publish_later(session_a, 300, 'com.myapp.topic1.foobar', [msg, counter++], null, options));
dl3.push(publish_later(session_a, 1500, 'com.myapp.topic1.foobar', [msg, counter++], null, options));

// these are received in no session at all
dl3.push(publish_later(session_a, 400, 'de.myapp.topic1', [msg, counter++], null, options));
dl3.push(publish_later(session_a, 2000, 'de.myapp.topic1', [msg, counter++], null, options));

// these are received in session d only
dl3.push(publish_later(session_a, 500, 'com.foobar', [msg, counter++], null, options));
dl3.push(publish_later(session_a, 2500, 'com.foobar', [msg, counter++], null, options));

autobahn.when.all(dl3).then(
function (res) {
Expand Down
8 changes: 4 additions & 4 deletions test/test_pubsub_multiple_matching_subs.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
0 "all sessions connected"
1 "event: args=" ["hello subscriber!",1] ", kwargs=" {}
2 "subscription: sub_topic=" "com.myapp.topic1" ", sub_match=" "exact" ", session_ident=" "E"
2 "subscription: sub_topic=" "com..topic1" ", sub_match=" "wildcard" ", session_ident=" "B"
3 "event: args=" ["hello subscriber!",1] ", kwargs=" {}
4 "subscription: sub_topic=" "com" ", sub_match=" "prefix" ", session_ident=" "D"
4 "subscription: sub_topic=" "com.myapp.topic1" ", sub_match=" "exact" ", session_ident=" "E"
5 "event: args=" ["hello subscriber!",1] ", kwargs=" {}
6 "subscription: sub_topic=" "com.myapp" ", sub_match=" "prefix" ", session_ident=" "C"
6 "subscription: sub_topic=" "com" ", sub_match=" "prefix" ", session_ident=" "D"
7 "event: args=" ["hello subscriber!",1] ", kwargs=" {}
8 "subscription: sub_topic=" "com..topic1" ", sub_match=" "wildcard" ", session_ident=" "B"
8 "subscription: sub_topic=" "com.myapp" ", sub_match=" "prefix" ", session_ident=" "C"
9 "event: args=" ["hello subscriber!",2] ", kwargs=" {}
10 "subscription: sub_topic=" "com" ", sub_match=" "prefix" ", session_ident=" "D"
11 "event: args=" ["hello subscriber!",2] ", kwargs=" {}
Expand Down
1 change: 0 additions & 1 deletion test/test_serialization_cbor.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
var autobahn = require('./../index.js');
var testutil = require('./testutil.js');


exports.testCBORSerialization = function (testcase) {

testcase.expect(1);
Expand Down
5 changes: 3 additions & 2 deletions test/testutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ var create_timeout_handler = function(testcase) {
// shortcut config
var default_config = {
url: 'ws://127.0.0.1:8080/ws',
realm: 'realm1'
//realm: 'realm1'
realm: 'crossbardemo'
}

function connect_n(n, config) {
Expand Down Expand Up @@ -166,4 +167,4 @@ Testlog.prototype.check = function () {
exports.Testlog = Testlog;
exports.config = default_config;
exports.connect_n = connect_n;
exports.create_timeout_handler = create_timeout_handler;
exports.create_timeout_handler = create_timeout_handler;

0 comments on commit 0430d19

Please sign in to comment.