├── .crossbar ├── backend.py ├── config.json ├── key.priv └── key.pub ├── .github └── workflows │ └── main.yml ├── .gitignore ├── .npmignore ├── .travis.yml ├── Dockerfile ├── LICENSE ├── Makefile ├── README.md ├── doc ├── .gitignore ├── README.md ├── building.md ├── changelog.md ├── examples.md ├── getting-started.md ├── programming.md ├── reference.md ├── release-process.md └── utils.md ├── docker ├── Makefile ├── aarch64 │ ├── Dockerfile.alpine │ ├── Dockerfile.full │ ├── Makefile │ ├── README.md │ ├── app │ │ ├── README.txt │ │ ├── client.js │ │ ├── package.json │ │ └── run │ └── removeall.sh ├── armhf │ ├── Dockerfile.alpine │ ├── Dockerfile.full │ ├── Makefile │ ├── README.md │ ├── app │ │ ├── README.txt │ │ ├── client.js │ │ ├── package.json │ │ └── run │ └── removeall.sh ├── removeall.sh ├── versions.sh └── x86_64 │ ├── Dockerfile.alpine │ ├── Dockerfile.full │ ├── Makefile │ ├── README.md │ ├── app │ ├── README.txt │ ├── client.js │ ├── package.json │ └── run │ └── removeall.sh ├── package.json └── packages ├── autobahn-xbr ├── LICENSE ├── SConstruct ├── index.js ├── lib │ ├── autobahn-xbr.js │ ├── blockchain.js │ ├── buyer.js │ ├── eip712.js │ ├── ethereum.js │ ├── keyseries.js │ ├── log.js │ ├── seller.js │ └── util.js ├── package.json └── test │ ├── Makefile │ ├── README.md │ ├── client │ ├── Makefile │ ├── README.md │ ├── browser │ │ ├── Makefile │ │ ├── README.md │ │ ├── buyer.html │ │ ├── buyer.js │ │ ├── index.html │ │ ├── seller.html │ │ └── seller.js │ └── nodejs │ │ ├── .dockerignore │ │ ├── Dockerfile │ │ ├── Makefile │ │ ├── buyer.js │ │ ├── package.json │ │ └── seller.js │ ├── eip712 │ ├── package.json │ ├── sign-browser.html │ ├── sign-browser.js │ ├── sign-cli.js │ └── test_uint256.js │ ├── onchain │ ├── Makefile │ ├── autobahn-xbr.js │ ├── index.html │ └── main.js │ ├── test_typed.js │ └── web3.min.js └── autobahn ├── LICENSE ├── SConstruct ├── index.js ├── lib ├── auth │ ├── cra.js │ ├── cryptosign.js │ └── persona.js ├── autobahn.js ├── configure.js ├── connection.js ├── log.js ├── polyfill.js ├── polyfill │ ├── array.js │ ├── console.js │ ├── function.js │ ├── json.js │ ├── object.js │ ├── string.js │ └── typedarray.js ├── serializer.js ├── session.js ├── transport │ ├── longpoll.js │ ├── rawsocket.js │ └── websocket.js └── util.js ├── package.json └── test ├── README.md ├── test.js ├── test_basic_async.js ├── test_basic_async.txt ├── test_basic_sync.js ├── test_basic_sync.txt ├── test_binary.js ├── test_binary_cbor.txt ├── test_connect.js ├── test_connect.trace ├── test_connect.txt ├── test_cryptosign.html ├── test_error_handling.js ├── test_error_handling.trace ├── test_error_handling_on_colse.txt ├── test_error_handling_on_event.txt ├── test_error_handling_on_invocation.txt ├── test_error_handling_on_open.txt ├── test_pubsub_basic.js ├── test_pubsub_basic.trace ├── test_pubsub_basic.txt ├── test_pubsub_complex.js ├── test_pubsub_complex.trace ├── test_pubsub_complex.txt ├── test_pubsub_eligible.js ├── test_pubsub_eligible.trace ├── test_pubsub_eligible.txt ├── test_pubsub_exclude.js ├── test_pubsub_exclude.trace ├── test_pubsub_exclude.txt ├── test_pubsub_excludeme.js ├── test_pubsub_excludeme.trace ├── test_pubsub_excludeme.txt ├── test_pubsub_multiple_matching_subs.js ├── test_pubsub_multiple_matching_subs.trace ├── test_pubsub_multiple_matching_subs.txt ├── test_pubsub_options.js ├── test_pubsub_options.trace ├── test_pubsub_options.txt ├── test_pubsub_prefix_sub.js ├── test_pubsub_prefix_sub.trace ├── test_pubsub_prefix_sub.txt ├── test_pubsub_wildcard_sub.js ├── test_pubsub_wildcard_sub.trace ├── test_pubsub_wildcard_sub.txt ├── test_rawsocket_protocol.js ├── test_rawsocket_transport.js ├── test_rawsocket_transport.trace ├── test_rawsocket_transport.txt ├── test_rpc_arguments.js ├── test_rpc_arguments.trace ├── test_rpc_arguments.txt ├── test_rpc_complex.js ├── test_rpc_complex.trace ├── test_rpc_complex.txt ├── test_rpc_error.js ├── test_rpc_error.trace ├── test_rpc_error.txt ├── test_rpc_options.js ├── test_rpc_options.trace ├── test_rpc_options.txt ├── test_rpc_progress.js ├── test_rpc_progress.trace ├── test_rpc_progress.txt ├── test_rpc_request_id_sequence.js ├── test_rpc_request_id_sequence.trace ├── test_rpc_request_id_sequence.txt ├── test_rpc_routing.js ├── test_rpc_routing.trace ├── test_rpc_routing.txt ├── test_rpc_slowsquare.js ├── test_rpc_slowsquare.trace ├── test_rpc_slowsquare.txt ├── test_sealedbox.js ├── test_serialization_cbor.js ├── test_serialization_cbor.trace ├── test_serialization_cbor.txt ├── test_serialization_json.js ├── test_serialization_json.trace ├── test_serialization_json.txt ├── test_serialization_msgpack.js ├── test_serialization_msgpack.txt ├── test_util_is_object.js ├── test_util_is_object_fail.txt ├── test_util_is_object_success.txt ├── test_util_is_object_vm.txt └── testutil.js /.crossbar/backend.py: -------------------------------------------------------------------------------- 1 | import os 2 | import hashlib 3 | 4 | from twisted.internet.defer import inlineCallbacks 5 | 6 | from txaio import make_logger 7 | from autobahn import wamp 8 | from autobahn.twisted.wamp import ApplicationSession 9 | 10 | 11 | class Backend(ApplicationSession): 12 | 13 | log = make_logger() 14 | 15 | def __init__(self, config): 16 | self.log.info('Backend.__init__(config={config})', config=config) 17 | ApplicationSession.__init__(self, config) 18 | 19 | @inlineCallbacks 20 | def onJoin(self, details): 21 | self.log.info('Backend.onJoin(details={details})', details=details) 22 | regs = yield self.register(self) 23 | self.log.info('Registered procedures {regs}', regs=[r.procedure for r in regs if r]) 24 | 25 | @wamp.register('any.echo') 26 | def echo(self, whatever): 27 | return whatever 28 | 29 | @wamp.register('binary.random') 30 | def random(self, len=32): 31 | assert type(len) == int 32 | return os.urandom(len) 33 | 34 | @wamp.register('binary.concat') 35 | def concat(self, xbytes, ybytes): 36 | assert type(xbytes) == bytes 37 | assert type(ybytes) == bytes 38 | return xbytes + ybytes 39 | 40 | @wamp.register('binary.hash') 41 | def hash(self, xbytes): 42 | assert type(xbytes) == bytes 43 | return hashlib.sha256(xbytes).digest() 44 | 45 | @wamp.register('binary.reversed') 46 | def reversed(self, xbytes): 47 | assert type(xbytes) == bytes 48 | return bytes(reversed(xbytes)) 49 | -------------------------------------------------------------------------------- /.crossbar/key.priv: -------------------------------------------------------------------------------- 1 | Crossbar.io node private key - KEEP THIS SAFE! 2 | 3 | creator: oberstet@intel-nuci7 4 | created-at: 2023-01-16T10:13:47.153Z 5 | machine-id: 816b4b901e774fc1ad59cbf2719806b7 6 | node-authid: intel-nuci7 7 | node-cluster-ip: 127.0.0.1 8 | public-key-ed25519: 04ffa62e526aa0ff648cd61be4cc9d92f80e973485473647f76e96bef0d84dfe 9 | public-adr-eth: 0x62E7Af2CF452e820051210D237723E5914fB53F4 10 | private-key-ed25519: 39e3c34e472b6b5e6b93f73690584471f5c717b7320ea393d90d4f15a9747338 11 | private-key-eth: 3dcf36bafeb82d1b3927389847c68f1920c33c5f3607fffb4b2561da24351849 12 | -------------------------------------------------------------------------------- /.crossbar/key.pub: -------------------------------------------------------------------------------- 1 | Crossbar.io node public key 2 | 3 | creator: oberstet@intel-nuci7 4 | created-at: 2023-01-16T10:13:47.153Z 5 | machine-id: 816b4b901e774fc1ad59cbf2719806b7 6 | node-authid: intel-nuci7 7 | node-cluster-ip: 127.0.0.1 8 | public-key-ed25519: 04ffa62e526aa0ff648cd61be4cc9d92f80e973485473647f76e96bef0d84dfe 9 | public-adr-eth: 0x62E7Af2CF452e820051210D237723E5914fB53F4 10 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: Autobahn JS CI 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | branches: 9 | - master 10 | 11 | jobs: 12 | unittest: 13 | env: 14 | CB_IMAGE: crossbario/crossbar:cpy-slim-amd64-22.7.1.dev1 15 | 16 | runs-on: ubuntu-latest 17 | strategy: 18 | matrix: 19 | # https://de.wikipedia.org/wiki/Node.js#Versionen 20 | node: ['14', '18', '19'] 21 | 22 | name: Node ${{ matrix.node }} run 23 | steps: 24 | - uses: actions/checkout@v3 25 | - uses: actions/setup-node@v3 26 | with: 27 | node-version: ${{ matrix.node }} 28 | 29 | # Run this a bit early in the CI, so we don't have to "sleep". 30 | - name: Run crossbar 31 | run: | 32 | docker run --rm --entrypoint=/usr/local/bin/crossbar $CB_IMAGE version 33 | docker run -d -v $PWD/.crossbar:/node -p 8080:8080 -p 8090:8090 -u $UID --entrypoint=/usr/local/bin/crossbar $CB_IMAGE start --cbdir /node 34 | 35 | - name: Install dependencies 36 | run: | 37 | sudo apt update 38 | sudo npm install -g nodeunit 39 | sudo pip3 install --no-cache-dir -U scons boto taschenmesser 40 | 41 | - name: Run tests 42 | run: | 43 | cd packages/autobahn && npm install 44 | make test 45 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .build 2 | .qemu 3 | node-v*-linux-x64/ 4 | .sconsign.dblite 5 | *.sublime-workspace 6 | build 7 | node_modules 8 | *.log 9 | *.pyc 10 | *.pid 11 | .idea/ 12 | .*.swp 13 | .lock-* 14 | package/.crossbar/ 15 | package-lock.json 16 | packages/autobahn-xbr/lib/contracts/ 17 | packages/autobahn-xbr/contracts/ 18 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | npm-debug.log 2 | node_modules 3 | .*.swp 4 | .lock-* 5 | build 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "10" 4 | dist: xenial 5 | sudo: true 6 | services: 7 | - docker 8 | 9 | addons: 10 | apt: 11 | update: true 12 | packages: 13 | - python3-pip 14 | 15 | before_install: 16 | - sudo pip3 install --no-cache-dir -U scons boto taschenmesser 17 | - rm -rf node_modules/websocket 18 | 19 | before_script: 20 | - docker run -d -v $PWD/.crossbar:/node -p 8080:8080 -p 8090:8090 -u $UID crossbario/crossbar --cbdir /node 21 | - sleep 5 22 | 23 | script: 24 | - npm install -g nodeunit 25 | - cd packages/autobahn && npm install && npm test 26 | 27 | # CI notifications 28 | notifications: 29 | # IRC: chat messages on #crossbar-ci @ freenode 30 | irc: 31 | on_success: always # options: [always|never|change] default: always 32 | on_failure: always # options: [always|never|change] default: always 33 | on_start: always # options: [always|never|change] default: always 34 | channels: 35 | - "irc.freenode.org#crossbar-ci" 36 | use_notice: false 37 | skip_join: false 38 | slack: 39 | on_success: always # options: [always|never|change] default: always 40 | on_failure: always # options: [always|never|change] default: always 41 | on_start: always # options: [always|never|change] default: always 42 | rooms: 43 | # travis encrypt --org --repo crossbario/autobahn-js "crossbario:FYg..." 44 | - secure: "J5IKtd+BlVHWVDrtoCGpesVE7nASw1yg/DcKDtd/dVoj6dJimXoYXFPdJTjBvsDg54Zd41KMshe5fSRlEOkg9r0333OxtXySK/v66ncI6ipnSo2eM5kuOJ6E2Kg3A8AdhcV3IxG3awbHYxgtQVcCpOGIZ2bkaHNqxj2smiNAKK0=" 45 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:bionic 2 | 3 | RUN apt-get update \ 4 | && apt-get install -y npm \ 5 | nodejs \ 6 | nodejs-dev \ 7 | default-jre \ 8 | python \ 9 | python-pip \ 10 | wget \ 11 | curl \ 12 | unzip \ 13 | git-core \ 14 | build-essential \ 15 | autotools-dev \ 16 | autoconf \ 17 | libtool \ 18 | cmake \ 19 | scons \ 20 | zlib1g-dev \ 21 | libbz2-dev \ 22 | libssl1.0-dev \ 23 | && rm -rf /var/lib/apt/lists/* \ 24 | && apt-get clean 25 | 26 | # https://nodejs.org/dist/v6.10.3/node-v6.10.3-linux-x64.tar.xz 27 | # tar xvf node-v*.tar.?z --strip-components=1 -C ./node 28 | # sudo ln -s /opt/node/bin/node /usr/local/bin/node 29 | # sudo ln -s /opt/node/bin/npm /usr/local/bin/npm 30 | 31 | 32 | RUN pip install -U scons boto taschenmesser 33 | 34 | VOLUME /work 35 | WORKDIR /work 36 | 37 | ENV JAVA_HOME /usr/lib/jvm/default-java 38 | ENV JS_COMPILER /work/node_modules/google-closure-compiler-java/compiler.jar 39 | 40 | CMD ["make", "build_browser_docker"] 41 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) typedef int GmbH and contributors. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | the Software, and to permit persons to whom the Software is furnished to do so, 8 | subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | -------------------------------------------------------------------------------- /doc/.gitignore: -------------------------------------------------------------------------------- 1 | _build 2 | _upload 3 | _test 4 | _spelling 5 | _static/img/gen 6 | .sconsign.dblite 7 | -------------------------------------------------------------------------------- /doc/README.md: -------------------------------------------------------------------------------- 1 | # Autobahn|JS Documentation 2 | 3 | ## First Contact 4 | 5 | If you're new to Autobahn|JS, then please take a look at [Getting Started](getting-started.md) first. 6 | 7 | You may also want to read up a bit on the [Web Application Messaging Protocol (WAMP)](http://wamp-proto.org/why/) which it implements. 8 | 9 | And finally, we suggest visiting the [Crossbar.io site](http://crossbar.io). Crossbar.io is a WAMP router maintained by the people behind Autobahn|JS, and the documentation there includes examples for some aspects of building WAMP applications - all of which use Autobahn|JS. 10 | 11 | ## Table of Contents 12 | 13 | * [Getting Started](getting-started.md) 14 | * [Programming](programming.md) - A quick introduction to using Autobahn|JS in your applications 15 | * [Reference](reference.md) - A full reference to the Autobahn|JS API 16 | * [Examples Overview](examples.md) - An overview of the available code examples 17 | * [Building](building.md) - Instructions for how to build Autobahn|JS from source 18 | * [Release Process](release-process.md) - Instructions on how to do a new release (only relevant for project members) 19 | * [Utilities](utils.md) - Autobahn utilities. 20 | -------------------------------------------------------------------------------- /doc/building.md: -------------------------------------------------------------------------------- 1 | # Building Autobahn|JS 2 | 3 | The following describes how to build and publish **Autobahn|JS** for browser and Node. 4 | 5 | 6 | ## Build environment (browser build) 7 | 8 | Install [Node.js](http://nodejs.org/) 9 | 10 | sudo apt-get install -y nodejs nodejs-legacy npm 11 | 12 | Install [browserify](http://browserify.org/) 13 | 14 | sudo npm install -g browserify nodeunit 15 | 16 | Install Python tools (preferrably into a dedicated virtualenv) 17 | 18 | pip install -U scons boto scour taschenmesser 19 | 20 | Install Java JDK 21 | 22 | sudo apt install -y openjdk-8-jdk 23 | 24 | Install [Google Closure Compiler](https://developers.google.com/closure/compiler/) 25 | 26 | cd ~ 27 | rm -f compiler-latest.zip 28 | wget https://dl.google.com/closure-compiler/compiler-latest.zip 29 | unzip -o compiler-latest.zip 30 | 31 | This will produce a file like `closure-compiler-v20161024.jar` in your `$HOME`. 32 | 33 | Install library dependencies 34 | 35 | sudo npm install -g ws when crypto-js \ 36 | tweetnacl msgpack-lite int64-buffer bufferutil utf-8-validate 37 | 38 | Set environment variables (add that to `$HOME/.profile`): 39 | 40 | export JS_COMPILER=$HOME/closure-compiler-v20161024.jar 41 | export JAVA_HOME=/usr/lib/jvm/default-java 42 | export NODE_PATH=/usr/local/lib/node_modules/ 43 | 44 | 45 | ## Building for browsers 46 | 47 | To start the build: 48 | 49 | scons 50 | 51 | To clean up your build: 52 | 53 | scons -uc 54 | 55 | Here is a typical build output (*some* warnings are "ok" - they come from dependencies we don't control): 56 | 57 | 58 | ```console 59 | (cpy2712_1) oberstet@office-corei7:~/scm/crossbario/autobahn-js$ scons 60 | scons: Reading SConscript files ... 61 | Building AutobahnJS 0.11.0 62 | scons: done reading SConscript files. 63 | scons: Building targets ... 64 | browserify lib/autobahn.js --standalone autobahn -o build/autobahn.js 65 | js_builder(["build/autobahn.min.js"], ["build/autobahn.js"]) 66 | java -jar /home/oberstet/closure-compiler-v20161024.jar --compilation_level SIMPLE_OPTIMIZATIONS --js build/autobahn.js --js_output_file build/autobahn.min.js 67 | build/autobahn.js:772: WARNING - Suspicious negated left operand of in operator. 68 | while ( k < len && ! k in t ) k++; 69 | ^ 70 | 71 | build/autobahn.js:866: WARNING - Suspicious negated left operand of in operator. 72 | while ( k >= 0 && ! k in t ) k--; 73 | ^ 74 | 75 | build/autobahn.js:6098: WARNING - Suspicious code. The result of the 'getprop' operator is not being used. 76 | array.byteLength // this throws if `array` is not a valid ArrayBuffer 77 | ^ 78 | 79 | build/autobahn.js:15857: WARNING - Suspicious code. The result of the 'not' operator is not being used. 80 | !function(exports) { 81 | ^ 82 | 83 | 0 error(s), 4 warning(s) 84 | gzipper(["build/autobahn.min.jgz"], ["build/autobahn.min.js"]) 85 | checksumsMD5(["build/CHECKSUM.MD5"], ["build/autobahn.js", "build/autobahn.min.js", "build/autobahn.min.jgz"]) 86 | checksumsSHA1(["build/CHECKSUM.SHA1"], ["build/autobahn.js", "build/autobahn.min.js", "build/autobahn.min.jgz"]) 87 | checksumsSHA256(["build/CHECKSUM.SHA256"], ["build/autobahn.js", "build/autobahn.min.js", "build/autobahn.min.jgz"]) 88 | Copy("build/LICENSE", "LICENSE") 89 | scons: done building targets. 90 | ``` 91 | 92 | This should produce the following build artifacts: 93 | 94 | ```console 95 | (cpy2712_1) oberstet@office-corei7:~/scm/crossbario/autobahn-js$ ls -la build/ 96 | insgesamt 896 97 | drwxrwxr-x 2 oberstet oberstet 4096 Nov 15 10:51 . 98 | drwxrwxr-x 7 oberstet oberstet 4096 Nov 15 10:51 .. 99 | -rw-rw-r-- 1 oberstet oberstet 573208 Nov 15 10:51 autobahn.js 100 | -rw-rw-r-- 1 oberstet oberstet 58009 Nov 15 10:51 autobahn.min.jgz 101 | -rw-rw-r-- 1 oberstet oberstet 198906 Nov 15 10:51 autobahn.min.js 102 | -rw-rw-r-- 1 oberstet oberstet 168 Nov 15 10:51 CHECKSUM.MD5 103 | -rw-rw-r-- 1 oberstet oberstet 195 Nov 15 10:51 CHECKSUM.SHA1 104 | -rw-rw-r-- 1 oberstet oberstet 273 Nov 15 10:51 CHECKSUM.SHA256 105 | -rw-rw-r-- 1 oberstet oberstet 1086 Nov 15 10:46 LICENSE 106 | ``` 107 | -------------------------------------------------------------------------------- /doc/changelog.md: -------------------------------------------------------------------------------- 1 | # AutobahnJS - Change Log 2 | 3 | ## 20.2.2 4 | 5 | * new: update XBR contract ABI files to v20.2.2 6 | * fix: assert issue when running under different nodejs vm contexts (#490) 7 | 8 | ## 20.2.1 9 | 10 | * new: update XBR contract ABI files to v20.2.1 11 | 12 | ## 20.1.1 13 | 14 | * fix: upstream truffle dependency renaming - must use `@truffle/contract` 15 | * new: update XBR contract ABI files 16 | 17 | ## v19.12.1 18 | 19 | * fix: docker image build scripts 20 | * new: streamline websocket selection (#479) 21 | 22 | ## v19.10.1 23 | 24 | released 2019/10/02: 25 | 26 | * new: XBR data service encryption and transaction support 27 | 28 | ## v17.5.2 29 | 30 | * new: WAMP-cryptosign authentication support 31 | 32 | ## v0.9.1 33 | * compatibility with latest WAMP v2 spec ("RC-2, 2014/02/22") 34 | 35 | ## v0.9.0 36 | * complete new implementation with WAMP v2 only support 37 | 38 | ## v0.8.2 39 | * compatibility with Web workers 40 | * fix problem with Require.js 41 | * fix RPC error callback 42 | * update bundled to [whenjs](https://github.com/cujojs/when) v2.7.1 43 | 44 | ## v0.8.1 45 | * update bundled to [whenjs](https://github.com/cujojs/when) v2.7.0 46 | * fix IE8/9 connection timeout handling (relevant when running WebSocket Flash polyfill) 47 | 48 | ## v0.8.0 49 | * support for AMD/CommonJS module loading 50 | * update bundled to [whenjs](https://github.com/cujojs/when) v2.5.1 51 | * build with [Taschenmesser](https://pypi.python.org/pypi/taschenmesser) 52 | 53 | ## v0.7.9 54 | * simple `launch` function (also handles WAMP-CRA auth) 55 | * improve WAMP session logging 56 | * JSlint cosmetics 57 | 58 | ## v0.7.8 59 | Not released. 60 | 61 | ## v0.7.7 62 | * build system improvements (gzipped version etc) 63 | * `getServerUrl` helper 64 | * `Session.log` and `Session.wsuri` 65 | * allow silencing of logging 66 | * update bundled [whenjs](https://github.com/cujojs/when) 67 | * started on NPM module (unfinished) 68 | * `console.log` polyfill 69 | 70 | ## v0.7.6 71 | * default 'onhangup' handler now logs all arguments (issue #19) 72 | 73 | ## v0.7.5 74 | * add option to skip announcing of WebSocket subprotocol (WAMP) 75 | * implement `deriveKey` function for salted WAMP-CRA 76 | 77 | ## v0.7.4 78 | * update bundled [whenjs](https://github.com/cujojs/when) to v1.8.1 79 | * update bundled [CryptoJS](http://code.google.com/p/crypto-js/) to v3.1.2 80 | * faster ID generation for tracking RPCs 81 | -------------------------------------------------------------------------------- /doc/examples.md: -------------------------------------------------------------------------------- 1 | # Examples Overview 2 | 3 | The examples give an overview of the features of WAMP by providing working code. 4 | 5 | Read, run, and modify as you like! 6 | 7 | There are two main sources of examples: 8 | 9 | - the [Autobahn|Python repository](https://github.com/crossbario/autobahn-python/tree/master/examples) - for an overview see the [Autobahn|Python documentation](http://autobahn.ws/python/wamp/examples.html) 10 | - the [Crossbar.io examples repository](https://github.com/crossbario/crossbarexamples) - for an overview see [the Crossbar.io documentation](http://crossbar.io/docs/Examples/) 11 | 12 | > **note** 13 | > 14 | > The JavaScript code provided generally runs both in the browser and in Node.js. When using the browser, load the JavaScript via the provided HTML page. Each example also contains Python versions. Python and JavaScript versions are interoperable: You may run e.g. a JavaScript subscriber and a Python publisher. 15 | 16 | Running examples 17 | ================ 18 | 19 | All examples require a WAMP router. 20 | 21 | We suggest using [Crossbar.io](http://crossbar.io), an open source WAMP application router. 22 | 23 | For the installation of Crossbar.io, see the [project documentation](http://crossbar.io/docs/Quick-Start/). 24 | 25 | Examples from the Autobahn|Python repo 26 | -------------------------------------- 27 | 28 | Once you've installed Crossbar.io, open a command shell, create a test directory, initialize Crossbar.io and start it. 29 | 30 | mkdir test1 31 | cd test 1 32 | crossbar init 33 | crossbar start 34 | 35 | Code runs both in the browser and in Node.js. 36 | 37 | For the latter, you need to have **Autobahn|JS** installed. To do so, in a shell do 38 | 39 | npm install autobahn 40 | npm install when 41 | 42 | Examples from the crossbarexamples repo 43 | --------------------------------------- 44 | 45 | The examples here all include a Crossbar.io configuration for the example. 46 | 47 | So do 48 | 49 | crossbar start 50 | 51 | in the example directory and then open a Web browser to 'localhost:8080'. 52 | -------------------------------------------------------------------------------- /doc/release-process.md: -------------------------------------------------------------------------------- 1 | # Releasing Autobahn|JS 2 | 3 | Autobahn is released to the following locations: 4 | 5 | 1. On NPM, here https://www.npmjs.com/package/autobahn 6 | 2. On GitHub, here https://github.com/crossbario/autobahn-js-built 7 | 8 | ## Release Steps 9 | 10 | ### Test 11 | 12 | Start a local Crossbar.io node with a default configuration (`crossbar init && crossbar start`). Then do 13 | 14 | ``` 15 | make test 16 | ``` 17 | 18 | ### Bump version 19 | 20 | Update `package.json` with the new release number. 21 | 22 | 23 | ### Build 24 | 25 | In the root directory, do 26 | 27 | ``` 28 | make build_browser 29 | ``` 30 | 31 | which will package the library for browser use into the `build` directory. For npm, there is nothing to build. 32 | 33 | 34 | ### Tag the release 35 | 36 | E.g. by doing 37 | 38 | ``` 39 | git tag -a v18.6.1 -m "tagged release" 40 | ``` 41 | 42 | before you commit. (Add the hash of a commit at the end of the above to tag at a later time.) 43 | 44 | 45 | ### Publish 46 | 47 | To publish: 48 | 49 | ``` 50 | make publish 51 | ``` 52 | 53 | Don't forget to tag and push from the AutobahnJSbuilt repo (which has been updated by above command). 54 | -------------------------------------------------------------------------------- /doc/utils.md: -------------------------------------------------------------------------------- 1 | # Utilities 2 | 3 | ## HTTP requests 4 | 5 | Autobahn includes helpers to do HTTP requests returning JS promises, allowing 6 | a modern style of asynchronous programming without callback hell. 7 | 8 | To do a HTTP/GET requesting JSON data: 9 | 10 | ```javascript 11 | autobahn.util.http_get_json("/config").then( 12 | function (config) { 13 | console.log(config); 14 | }, 15 | function (err) { 16 | console.log(err); 17 | } 18 | ); 19 | ``` 20 | 21 | JSON data can be served directly from Crossbar.io using a webservice of type `json`. 22 | 23 | Here is a node configuration that will serve the `value` configured on the HTTP 24 | URL `/config`: 25 | 26 | 27 | ```json 28 | { 29 | "workers": [ 30 | { 31 | "type": "router", 32 | "transports": [ 33 | { 34 | "type": "web", 35 | "endpoint": { 36 | "type": "tcp", 37 | "port": 8080 38 | }, 39 | "paths": { 40 | "/": { 41 | "type": "static", 42 | "directory": "../web", 43 | "options": { 44 | "enable_directory_listing": true 45 | } 46 | }, 47 | "config": { 48 | "type": "json", 49 | "value": { 50 | "nodes": [ 51 | "ws://localhost:8081/ws", 52 | "ws://localhost:8082/ws", 53 | "ws://localhost:8083/ws", 54 | "ws://localhost:8084/ws" 55 | ] 56 | } 57 | }, 58 | } 59 | } 60 | ] 61 | } 62 | ] 63 | } 64 | ``` 65 | -------------------------------------------------------------------------------- /docker/Makefile: -------------------------------------------------------------------------------- 1 | SUBDIRS = x86_64 armhf aarch64 2 | 3 | subdirs: $(SUBDIRS) 4 | 5 | BUILDDIRS = $(SUBDIRS:%=build-%) 6 | VERSIONDIRS = $(SUBDIRS:%=version-%) 7 | TESTDIRS = $(SUBDIRS:%=test-%) 8 | PUBLISHDIRS = $(SUBDIRS:%=publish-%) 9 | 10 | build: $(BUILDDIRS) 11 | version: $(VERSIONDIRS) 12 | test: $(TESTDIRS) 13 | publish: $(PUBLISHDIRS) 14 | 15 | .PHONY: subdirs $(BUILDDIRS) $(VERSIONDIRS) $(TESTDIRS) $(PUBLISHDIRS) 16 | .PHONY: build version test publish 17 | 18 | $(BUILDDIRS): 19 | $(MAKE) -C $(@:build-%=%) build 20 | 21 | $(VERSIONDIRS): 22 | $(MAKE) -C $(@:version-%=%) version 23 | 24 | $(TESTDIRS): 25 | $(MAKE) -C $(@:test-%=%) test 26 | 27 | $(PUBLISHDIRS): 28 | $(MAKE) -C $(@:publish-%=%) publish 29 | 30 | list: 31 | docker images crossbario/autobahn-js*:* 32 | 33 | clean: 34 | -./removeall.sh 35 | -------------------------------------------------------------------------------- /docker/aarch64/Dockerfile.alpine: -------------------------------------------------------------------------------- 1 | FROM aarch64/alpine:edge 2 | 3 | COPY .qemu/qemu-aarch64-static /usr/bin/qemu-aarch64-static 4 | 5 | MAINTAINER The Crossbar.io Project 6 | 7 | # Metadata 8 | ARG AUTOBAHN_JS_VERSION 9 | ARG AUTOBAHN_JS_XBR_VERSION 10 | ARG BUILD_DATE 11 | ARG AUTOBAHN_JS_VCS_REF 12 | 13 | # Metadata labeling 14 | LABEL org.label-schema.build-date=$BUILD_DATE \ 15 | org.label-schema.name="AutobahnJS Starter Template" \ 16 | org.label-schema.description="Quickstart template for application development with AutobahnJS" \ 17 | org.label-schema.url="http://crossbar.io" \ 18 | org.label-schema.vcs-ref=$AUTOBAHN_JS_VCS_REF \ 19 | org.label-schema.vcs-url="https://github.com/crossbario/autobahn-js" \ 20 | org.label-schema.vendor="The Crossbar.io Project" \ 21 | org.label-schema.version=$AUTOBAHN_JS_VERSION \ 22 | org.label-schema.schema-version="1.0" 23 | 24 | # Application home 25 | ENV HOME /app 26 | ENV DEBIAN_FRONTEND noninteractive 27 | ENV NODE_PATH /usr/lib/node_modules 28 | 29 | # we need a toolchain for the (optional) binary extensions used by Autobahn 30 | RUN apk add --update git build-base libffi-dev openssl-dev \ 31 | && rm -rf /var/cache/apk/* 32 | 33 | # Crossbar.io connection defaults 34 | ENV CBURL ws://crossbar:8080/ws 35 | ENV CBREALM realm1 36 | 37 | # make sure HOME exists! 38 | RUN mkdir /app 39 | 40 | # set the app component directory as working directory 41 | WORKDIR /app 42 | 43 | # install node 44 | RUN apk add --update nodejs nodejs-npm nodejs-dev build-base python \ 45 | && rm -rf /var/cache/apk/* 46 | 47 | # see: 48 | # - https://github.com/npm/uid-number/issues/3#issuecomment-287413039 49 | # - https://github.com/tootsuite/mastodon/issues/802 50 | RUN npm config set unsafe-perm true 51 | 52 | # install Autobahn|JS 53 | #https://github.com/npm/npm/issues/17431#issuecomment-325892798 54 | RUN npm install -g --unsafe-perm node-gyp 55 | RUN npm install -g --unsafe-perm autobahn@${AUTOBAHN_JS_VERSION} 56 | RUN npm install -g --unsafe-perm autobahn-xbr@${AUTOBAHN_JS_XBR_VERSION} 57 | 58 | # add example service 59 | COPY ./app/* /app/ 60 | 61 | # make /app a volume to allow external configuration 62 | VOLUME /app 63 | 64 | # run service entry script by default 65 | CMD ["sh", "/app/run"] 66 | -------------------------------------------------------------------------------- /docker/aarch64/Dockerfile.full: -------------------------------------------------------------------------------- 1 | #FROM aarch64/node 2 | FROM arm64v8/node 3 | 4 | COPY .qemu/qemu-aarch64-static /usr/bin/qemu-aarch64-static 5 | 6 | MAINTAINER The Crossbar.io Project 7 | 8 | # Metadata 9 | ARG AUTOBAHN_JS_VERSION 10 | ARG AUTOBAHN_JS_XBR_VERSION 11 | ARG BUILD_DATE 12 | ARG AUTOBAHN_JS_VCS_REF 13 | 14 | # Metadata labeling 15 | LABEL org.label-schema.build-date=$BUILD_DATE \ 16 | org.label-schema.name="AutobahnJS Starter Template" \ 17 | org.label-schema.description="Quickstart template for application development with AutobahnJS" \ 18 | org.label-schema.url="http://crossbar.io" \ 19 | org.label-schema.vcs-ref=$AUTOBAHN_JS_VCS_REF \ 20 | org.label-schema.vcs-url="https://github.com/crossbario/autobahn-js" \ 21 | org.label-schema.vendor="The Crossbar.io Project" \ 22 | org.label-schema.version=$AUTOBAHN_JS_VERSION \ 23 | org.label-schema.schema-version="1.0" 24 | 25 | # Application home 26 | ENV HOME /app 27 | ENV DEBIAN_FRONTEND noninteractive 28 | ENV NODE_PATH /usr/local/lib/node_modules 29 | 30 | RUN apt-get update \ 31 | && apt-get install -y --no-install-recommends \ 32 | ca-certificates \ 33 | git \ 34 | build-essential \ 35 | libssl-dev \ 36 | libffi-dev \ 37 | libunwind-dev \ 38 | libsnappy-dev \ 39 | libbz2-dev \ 40 | && rm -rf ~/.cache \ 41 | && rm -rf /var/lib/apt/lists/* 42 | 43 | # Crossbar.io connection defaults 44 | ENV CBURL ws://crossbar:8080/ws 45 | ENV CBREALM realm1 46 | 47 | # make sure HOME exists! 48 | RUN mkdir /app 49 | 50 | # set the app component directory as working directory 51 | WORKDIR /app 52 | 53 | # see: 54 | # - https://github.com/npm/uid-number/issues/3#issuecomment-287413039 55 | # - https://github.com/tootsuite/mastodon/issues/802 56 | RUN npm config set unsafe-perm true 57 | 58 | # install Autobahn|JS 59 | #https://github.com/npm/npm/issues/17431#issuecomment-325892798 60 | RUN npm install -g --unsafe-perm node-gyp 61 | RUN npm install -g --unsafe-perm autobahn@${AUTOBAHN_JS_VERSION} 62 | RUN npm install -g --unsafe-perm autobahn-xbr@${AUTOBAHN_JS_XBR_VERSION} 63 | 64 | # add example service 65 | COPY ./app/* /app/ 66 | 67 | # make /app a volume to allow external configuration 68 | VOLUME /app 69 | 70 | # run service entry script by default 71 | CMD ["sh", "/app/run"] 72 | -------------------------------------------------------------------------------- /docker/aarch64/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: build 2 | 3 | HOSTIP=$(shell ip route get 1 | awk '{print $$NF;exit}') 4 | 5 | default: 6 | @echo "Targets: build, test, publish, .." 7 | 8 | 9 | qemu_deps: 10 | mkdir -p ./.qemu 11 | cp /usr/bin/qemu-aarch64-static ./.qemu/ 12 | 13 | 14 | #build: build_full build_alpine 15 | build: build_full 16 | 17 | build_full: 18 | time docker build \ 19 | --build-arg BUILD_DATE=${BUILD_DATE} \ 20 | --build-arg AUTOBAHN_JS_VCS_REF=${AUTOBAHN_JS_VCS_REF} \ 21 | --build-arg AUTOBAHN_JS_VERSION=${AUTOBAHN_JS_VERSION} \ 22 | --build-arg AUTOBAHN_JS_XBR_VERSION=${AUTOBAHN_JS_XBR_VERSION} \ 23 | -t crossbario/autobahn-js-aarch64 \ 24 | -t crossbario/autobahn-js-aarch64:latest \ 25 | -t crossbario/autobahn-js-aarch64:full \ 26 | -t crossbario/autobahn-js-aarch64:full-${AUTOBAHN_JS_VERSION} \ 27 | -f Dockerfile.full . 28 | 29 | build_alpine: 30 | @echo "FIXME: crossbario/autobahn-js-aarch64:alpine is broken" 31 | time docker build \ 32 | --build-arg BUILD_DATE=${BUILD_DATE} \ 33 | --build-arg AUTOBAHN_JS_VCS_REF=${AUTOBAHN_JS_VCS_REF} \ 34 | --build-arg AUTOBAHN_JS_VERSION=${AUTOBAHN_JS_VERSION} \ 35 | --build-arg AUTOBAHN_JS_XBR_VERSION=${AUTOBAHN_JS_XBR_VERSION} \ 36 | -t crossbario/autobahn-js-aarch64:alpine \ 37 | -t crossbario/autobahn-js-aarch64:alpine-${AUTOBAHN_JS_VERSION} \ 38 | -f Dockerfile.alpine . 39 | 40 | 41 | version: os_version node_version autobahn_version 42 | 43 | os_version: 44 | docker run -it --rm crossbario/autobahn-js-aarch64:full uname -a 45 | docker run -it --rm crossbario/autobahn-js-aarch64:alpine uname -a 46 | 47 | node_version: 48 | docker run -it --rm crossbario/autobahn-js-aarch64:full node -v 49 | docker run -it --rm crossbario/autobahn-js-aarch64:alpine node -v 50 | 51 | autobahn_version: 52 | docker run -it --rm crossbario/autobahn-js-aarch64:full sh -c "echo \"console.log('autobahn-' + require('autobahn').version + ' is installed');\" | node" 53 | docker run -it --rm crossbario/autobahn-js-aarch64:alpine sh -c "echo \"console.log('autobahn-' + require('autobahn').version + ' is installed');\" | node" 54 | 55 | 56 | ping: ping_full ping_alpine 57 | 58 | ping_full: 59 | docker run --add-host=crossbar:$(HOSTIP) -it --rm crossbario/autobahn-js-aarch64:full ping crossbar 60 | 61 | ping_alpine: 62 | docker run --add-host=crossbar:$(HOSTIP) -it --rm crossbario/autobahn-js-aarch64:alpine ping crossbar 63 | 64 | 65 | test: test_full test_alpine 66 | 67 | test_full: 68 | docker run -it --rm --link crossbar crossbario/autobahn-js-aarch64:full 69 | 70 | test_alpine: 71 | docker run -it --rm --link crossbar crossbario/autobahn-js-aarch64:alpine 72 | 73 | 74 | #publish: publish_full publish_alpine 75 | publish: publish_full 76 | 77 | publish_alpine: build_alpine 78 | docker push crossbario/autobahn-js-aarch64:alpine 79 | docker push crossbario/autobahn-js-aarch64:alpine-${AUTOBAHN_JS_VERSION} 80 | 81 | publish_full: build_full 82 | docker push crossbario/autobahn-js-aarch64 83 | docker push crossbario/autobahn-js-aarch64:latest 84 | docker push crossbario/autobahn-js-aarch64:full 85 | docker push crossbario/autobahn-js-aarch64:full-${AUTOBAHN_JS_VERSION} 86 | 87 | 88 | list: 89 | -docker images crossbario/autobahn-js-aarch64:* 90 | 91 | clean: 92 | ./removeall.sh 93 | -------------------------------------------------------------------------------- /docker/aarch64/README.md: -------------------------------------------------------------------------------- 1 | # AutobahnJS for Docker 2 | 3 | [![](https://images.microbadger.com/badges/version/crossbario/autobahn-js-aarch64.svg)](https://microbadger.com/images/crossbario/autobahn-js-aarch64 "Get your own version badge on microbadger.com") 4 | 5 | 6 | Here you find the Dockerfiles for creating the [AutobahnJS for Docker images](https://hub.docker.com/r/crossbario/autobahn-js/) maintained by the Crossbar.io Project. 7 | 8 | These images come with NodeJS and AutobahnJS preinstalled and are intended to base application service containers on. 9 | 10 | 11 | https://hub.docker.com/r/armhf/node/ 12 | 13 | 14 | ## Images 15 | 16 | 1. **`crossbario/autobahn-js:latest` == `crossbario/autobahnjs:alpine`: Alpine Linux based variant, the default (<27MB container size)** RECOMMENDED FOR GENERAL USE 17 | 2. `crossbario/autobahn-js:full`: Variant based on full Node image (650MB container size) 18 | 19 | ## Build, test and deploy 20 | 21 | To build, test and deploy the AutobahnJS images to DockerHub, do: 22 | 23 | ```console 24 | make build 25 | make test 26 | make publish 27 | ``` 28 | 29 | > You will need a Crossbar.io container running. Run `make crossbar` in the `crossbar` folder of this repo. 30 | -------------------------------------------------------------------------------- /docker/aarch64/app/README.txt: -------------------------------------------------------------------------------- 1 | Put your microservice code and assets in here. 2 | 3 | The container will automatically start the script client.js in this folder. 4 | 5 | The environment of the script will have these variables set: 6 | 7 | * CBURL = ws://crossbar:8080/ws 8 | * CBREALM = realm1 9 | 10 | where the host crossbar resolves to a linked Docker container running Crossbar.io. 11 | -------------------------------------------------------------------------------- /docker/aarch64/app/client.js: -------------------------------------------------------------------------------- 1 | // Example WAMP client for AutobahnJS connecting to a Crossbar.io WAMP router. 2 | 3 | // AutobahnJS, the WAMP client library to connect and talk to Crossbar.io: 4 | var autobahn = require('autobahn'); 5 | 6 | console.log("Running AutobahnJS " + autobahn.version); 7 | 8 | // We read the connection parameters from the command line in this example: 9 | const url = process.env.CBURL; 10 | const realm = process.env.CBREALM; 11 | 12 | // Make us a new connection .. 13 | var connection = new autobahn.Connection({url: url, realm: realm}); 14 | 15 | // .. and fire this code when we got a session 16 | connection.onopen = function (session, details) { 17 | console.log("session open!", details); 18 | 19 | // Your code goes here: use WAMP via the session you got to 20 | // call, register, subscribe and publish .. 21 | 22 | connection.close(); 23 | }; 24 | 25 | // .. and fire this code when our session has gone 26 | connection.onclose = function (reason, details) { 27 | console.log("session closed: " + reason, details); 28 | } 29 | 30 | // Don't forget to actually trigger the opening of the connection! 31 | connection.open(); 32 | -------------------------------------------------------------------------------- /docker/aarch64/app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "crossbarclient", 3 | "version": "0.0.0", 4 | "description": "AutobahnJS demo client connecting to Crossbar.io", 5 | "dependencies": { 6 | }, 7 | "main": "client.js", 8 | "scripts": { 9 | "test": "echo \"Error: no test specified\" && exit 1" 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "git://github.com/crossbario/crossbar-docker.git" 14 | }, 15 | "author": "The Crossbar.io Project", 16 | "license": "MIT" 17 | } 18 | -------------------------------------------------------------------------------- /docker/aarch64/app/run: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | npm install 4 | node client.js 5 | -------------------------------------------------------------------------------- /docker/aarch64/removeall.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | docker rmi -f $(docker images -q crossbario/autobahn-js-aarch64:* | uniq) 4 | -------------------------------------------------------------------------------- /docker/armhf/Dockerfile.alpine: -------------------------------------------------------------------------------- 1 | FROM armhf/alpine:edge 2 | 3 | COPY .qemu/qemu-arm-static /usr/bin/qemu-arm-static 4 | 5 | MAINTAINER The Crossbar.io Project 6 | 7 | # Metadata 8 | ARG AUTOBAHN_JS_VERSION 9 | ARG AUTOBAHN_JS_XBR_VERSION 10 | ARG BUILD_DATE 11 | ARG AUTOBAHN_JS_VCS_REF 12 | 13 | # Metadata labeling 14 | LABEL org.label-schema.build-date=$BUILD_DATE \ 15 | org.label-schema.name="AutobahnJS Starter Template" \ 16 | org.label-schema.description="Quickstart template for application development with AutobahnJS" \ 17 | org.label-schema.url="http://crossbar.io" \ 18 | org.label-schema.vcs-ref=$AUTOBAHN_JS_VCS_REF \ 19 | org.label-schema.vcs-url="https://github.com/crossbario/autobahn-js" \ 20 | org.label-schema.vendor="The Crossbar.io Project" \ 21 | org.label-schema.version=$AUTOBAHN_JS_VERSION \ 22 | org.label-schema.schema-version="1.0" 23 | 24 | # Application home 25 | ENV HOME /app 26 | ENV DEBIAN_FRONTEND noninteractive 27 | ENV NODE_PATH /usr/lib/node_modules 28 | 29 | # we need a toolchain for the (optional) binary extensions used by Autobahn 30 | RUN apk add --update git build-base libffi-dev openssl-dev \ 31 | && rm -rf /var/cache/apk/* 32 | 33 | # Crossbar.io connection defaults 34 | ENV CBURL ws://crossbar:8080/ws 35 | ENV CBREALM realm1 36 | 37 | # make sure HOME exists! 38 | RUN mkdir /app 39 | 40 | # set the app component directory as working directory 41 | WORKDIR /app 42 | 43 | # install node 44 | RUN apk add --update nodejs nodejs-npm nodejs-dev build-base python \ 45 | && rm -rf /var/cache/apk/* 46 | 47 | # see: 48 | # - https://github.com/npm/uid-number/issues/3#issuecomment-287413039 49 | # - https://github.com/tootsuite/mastodon/issues/802 50 | RUN npm config set unsafe-perm true 51 | 52 | # install Autobahn|JS 53 | #https://github.com/npm/npm/issues/17431#issuecomment-325892798 54 | RUN npm install -g --unsafe-perm node-gyp 55 | RUN npm install -g --unsafe-perm autobahn@${AUTOBAHN_JS_VERSION} 56 | RUN npm install -g --unsafe-perm autobahn-xbr@${AUTOBAHN_JS_XBR_VERSION} 57 | 58 | # add example service 59 | COPY ./app/* /app/ 60 | 61 | # make /app a volume to allow external configuration 62 | VOLUME /app 63 | 64 | # run service entry script by default 65 | CMD ["sh", "/app/run"] 66 | -------------------------------------------------------------------------------- /docker/armhf/Dockerfile.full: -------------------------------------------------------------------------------- 1 | FROM arm32v7/node 2 | 3 | COPY .qemu/qemu-arm-static /usr/bin/qemu-arm-static 4 | 5 | MAINTAINER The Crossbar.io Project 6 | 7 | # Metadata 8 | ARG AUTOBAHN_JS_VERSION 9 | ARG AUTOBAHN_JS_XBR_VERSION 10 | ARG BUILD_DATE 11 | ARG AUTOBAHN_JS_VCS_REF 12 | 13 | # Metadata labeling 14 | LABEL org.label-schema.build-date=$BUILD_DATE \ 15 | org.label-schema.name="AutobahnJS Starter Template" \ 16 | org.label-schema.description="Quickstart template for application development with AutobahnJS" \ 17 | org.label-schema.url="http://crossbar.io" \ 18 | org.label-schema.vcs-ref=$AUTOBAHN_JS_VCS_REF \ 19 | org.label-schema.vcs-url="https://github.com/crossbario/autobahn-js" \ 20 | org.label-schema.vendor="The Crossbar.io Project" \ 21 | org.label-schema.version=$AUTOBAHN_JS_VERSION \ 22 | org.label-schema.schema-version="1.0" 23 | 24 | # Application home 25 | ENV HOME /app 26 | ENV DEBIAN_FRONTEND noninteractive 27 | ENV NODE_PATH /usr/local/lib/node_modules 28 | 29 | RUN apt-get update \ 30 | && apt-get install -y --no-install-recommends \ 31 | ca-certificates \ 32 | git \ 33 | build-essential \ 34 | libssl-dev \ 35 | libffi-dev \ 36 | libunwind-dev \ 37 | libsnappy-dev \ 38 | libbz2-dev \ 39 | && rm -rf ~/.cache \ 40 | && rm -rf /var/lib/apt/lists/* 41 | 42 | # Crossbar.io connection defaults 43 | ENV CBURL ws://crossbar:8080/ws 44 | ENV CBREALM realm1 45 | 46 | # make sure HOME exists! 47 | RUN mkdir /app 48 | 49 | # set the app component directory as working directory 50 | WORKDIR /app 51 | 52 | # see: 53 | # - https://github.com/npm/uid-number/issues/3#issuecomment-287413039 54 | # - https://github.com/tootsuite/mastodon/issues/802 55 | RUN npm config set unsafe-perm true 56 | 57 | # install Autobahn|JS 58 | #https://github.com/npm/npm/issues/17431#issuecomment-325892798 59 | RUN npm install -g --unsafe-perm node-gyp 60 | RUN npm install -g --unsafe-perm autobahn@${AUTOBAHN_JS_VERSION} 61 | RUN npm install -g --unsafe-perm autobahn-xbr@${AUTOBAHN_JS_XBR_VERSION} 62 | 63 | # add example service 64 | COPY ./app/* /app/ 65 | 66 | # make /app a volume to allow external configuration 67 | VOLUME /app 68 | 69 | # run service entry script by default 70 | CMD ["sh", "/app/run"] 71 | -------------------------------------------------------------------------------- /docker/armhf/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: build 2 | 3 | HOSTIP=$(shell ip route get 1 | awk '{print $$NF;exit}') 4 | 5 | default: 6 | @echo "Targets: build, test, publish, .." 7 | 8 | 9 | qemu_deps: 10 | mkdir -p ./.qemu 11 | cp /usr/bin/qemu-arm-static ./.qemu/ 12 | 13 | 14 | #build: build_full build_alpine 15 | build: build_full 16 | 17 | build_full: 18 | time docker build \ 19 | --build-arg BUILD_DATE=${BUILD_DATE} \ 20 | --build-arg AUTOBAHN_JS_VCS_REF=${AUTOBAHN_JS_VCS_REF} \ 21 | --build-arg AUTOBAHN_JS_VERSION=${AUTOBAHN_JS_VERSION} \ 22 | --build-arg AUTOBAHN_JS_XBR_VERSION=${AUTOBAHN_JS_XBR_VERSION} \ 23 | -t crossbario/autobahn-js-armhf \ 24 | -t crossbario/autobahn-js-armhf:latest \ 25 | -t crossbario/autobahn-js-armhf:full \ 26 | -t crossbario/autobahn-js-armhf:full-${AUTOBAHN_JS_VERSION} \ 27 | -f Dockerfile.full . 28 | 29 | build_alpine: 30 | @echo "FIXME: crossbario/autobahn-js-armhf:alpine is broken" 31 | time docker build \ 32 | --build-arg BUILD_DATE=${BUILD_DATE} \ 33 | --build-arg AUTOBAHN_JS_VCS_REF=${AUTOBAHN_JS_VCS_REF} \ 34 | --build-arg AUTOBAHN_JS_VERSION=${AUTOBAHN_JS_VERSION} \ 35 | --build-arg AUTOBAHN_JS_XBR_VERSION=${AUTOBAHN_JS_XBR_VERSION} \ 36 | -t crossbario/autobahn-js-armhf:alpine \ 37 | -t crossbario/autobahn-js-armhf:alpine-${AUTOBAHN_JS_VERSION} \ 38 | -f Dockerfile.alpine . 39 | 40 | 41 | version: os_version node_version autobahn_version 42 | 43 | os_version: 44 | docker run -it --rm crossbario/autobahn-js-armhf:full uname -a 45 | docker run -it --rm crossbario/autobahn-js-armhf:alpine uname -a 46 | 47 | node_version: 48 | docker run -it --rm crossbario/autobahn-js-armhf:full node -v 49 | docker run -it --rm crossbario/autobahn-js-armhf:alpine node -v 50 | 51 | autobahn_version: 52 | docker run -it --rm crossbario/autobahn-js-armhf:full sh -c "echo \"console.log('autobahn-' + require('autobahn').version + ' is installed');\" | node" 53 | docker run -it --rm crossbario/autobahn-js-armhf:alpine sh -c "echo \"console.log('autobahn-' + require('autobahn').version + ' is installed');\" | node" 54 | 55 | 56 | ping: ping_full ping_alpine 57 | 58 | ping_full: 59 | docker run --add-host=crossbar:$(HOSTIP) -it --rm crossbario/autobahn-js-armhf:full ping crossbar 60 | 61 | ping_alpine: 62 | docker run --add-host=crossbar:$(HOSTIP) -it --rm crossbario/autobahn-js-armhf:alpine ping crossbar 63 | 64 | 65 | test: test_full test_alpine 66 | 67 | test_full: 68 | docker run -it --rm --link crossbar crossbario/autobahn-js-armhf:full 69 | 70 | test_alpine: 71 | docker run -it --rm --link crossbar crossbario/autobahn-js-armhf:alpine 72 | 73 | 74 | publish: publish_full publish_alpine 75 | 76 | publish_alpine: build_alpine 77 | docker push crossbario/autobahn-js-armhf:alpine 78 | docker push crossbario/autobahn-js-armhf:alpine-${AUTOBAHN_JS_VERSION} 79 | 80 | publish_full: build_full 81 | docker push crossbario/autobahn-js-armhf 82 | docker push crossbario/autobahn-js-armhf:latest 83 | docker push crossbario/autobahn-js-armhf:full 84 | docker push crossbario/autobahn-js-armhf:full-${AUTOBAHN_JS_VERSION} 85 | 86 | 87 | list: 88 | -docker images crossbario/autobahn-js-armhf:* 89 | 90 | clean: 91 | ./removeall.sh 92 | -------------------------------------------------------------------------------- /docker/armhf/README.md: -------------------------------------------------------------------------------- 1 | # AutobahnJS for Docker 2 | 3 | Here you find the Dockerfiles for creating the [AutobahnJS for Docker images](https://hub.docker.com/r/crossbario/autobahn-js/) maintained by the Crossbar.io Project. 4 | 5 | These images come with NodeJS and AutobahnJS preinstalled and are intended to base application service containers on. 6 | 7 | 8 | https://hub.docker.com/r/armhf/node/ 9 | https://hub.docker.com/r/aarch64/node/ 10 | 11 | 12 | ## Images 13 | 14 | 1. **`crossbario/autobahn-js:latest` == `crossbario/autobahnjs:alpine`: Alpine Linux based variant, the default (<27MB container size)** RECOMMENDED FOR GENERAL USE 15 | 2. `crossbario/autobahn-js:full`: Variant based on full Node image (650MB container size) 16 | 17 | ## Build, test and deploy 18 | 19 | To build, test and deploy the AutobahnJS images to DockerHub, do: 20 | 21 | ```console 22 | make build 23 | make test 24 | make publish 25 | ``` 26 | 27 | > You will need a Crossbar.io container running. Run `make crossbar` in the `crossbar` folder of this repo. 28 | -------------------------------------------------------------------------------- /docker/armhf/app/README.txt: -------------------------------------------------------------------------------- 1 | Put your microservice code and assets in here. 2 | 3 | The container will automatically start the script client.js in this folder. 4 | 5 | The environment of the script will have these variables set: 6 | 7 | * CBURL = ws://crossbar:8080/ws 8 | * CBREALM = realm1 9 | 10 | where the host crossbar resolves to a linked Docker container running Crossbar.io. 11 | -------------------------------------------------------------------------------- /docker/armhf/app/client.js: -------------------------------------------------------------------------------- 1 | // Example WAMP client for AutobahnJS connecting to a Crossbar.io WAMP router. 2 | 3 | // AutobahnJS, the WAMP client library to connect and talk to Crossbar.io: 4 | var autobahn = require('autobahn'); 5 | 6 | console.log("Running AutobahnJS " + autobahn.version); 7 | 8 | // We read the connection parameters from the command line in this example: 9 | const url = process.env.CBURL; 10 | const realm = process.env.CBREALM; 11 | 12 | // Make us a new connection .. 13 | var connection = new autobahn.Connection({url: url, realm: realm}); 14 | 15 | // .. and fire this code when we got a session 16 | connection.onopen = function (session, details) { 17 | console.log("session open!", details); 18 | 19 | // Your code goes here: use WAMP via the session you got to 20 | // call, register, subscribe and publish .. 21 | 22 | connection.close(); 23 | }; 24 | 25 | // .. and fire this code when our session has gone 26 | connection.onclose = function (reason, details) { 27 | console.log("session closed: " + reason, details); 28 | } 29 | 30 | // Don't forget to actually trigger the opening of the connection! 31 | connection.open(); 32 | -------------------------------------------------------------------------------- /docker/armhf/app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "crossbarclient", 3 | "version": "0.0.0", 4 | "description": "AutobahnJS demo client connecting to Crossbar.io", 5 | "dependencies": { 6 | }, 7 | "main": "client.js", 8 | "scripts": { 9 | "test": "echo \"Error: no test specified\" && exit 1" 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "git://github.com/crossbario/crossbar-docker.git" 14 | }, 15 | "author": "The Crossbar.io Project", 16 | "license": "MIT" 17 | } 18 | -------------------------------------------------------------------------------- /docker/armhf/app/run: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | npm install 4 | node client.js 5 | -------------------------------------------------------------------------------- /docker/armhf/removeall.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | docker rmi -f $(docker images -q crossbario/autobahn-js-armhf:* | uniq) 4 | -------------------------------------------------------------------------------- /docker/removeall.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | docker rmi -f $(docker images -q crossbario/autobahn-js*:* | uniq) 4 | -------------------------------------------------------------------------------- /docker/versions.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # CHANGE FOR NEW RELEASES (these need to be proper Git tags in the respective repo): 5 | # 6 | export AUTOBAHN_JS_VERSION='20.6.1' 7 | export AUTOBAHN_JS_XBR_VERSION='20.6.1' 8 | # 9 | # END OF CONFIG 10 | # 11 | 12 | # 13 | # Git working directories of all relevant repos must reside 14 | # in parallel (as siblings) to this repository 15 | # 16 | # export AUTOBAHN_PYTHON_VERSION=$(grep -E '^(__version__)' ../autobahn/_version.py | cut -d ' ' -f3 | sed -e 's|[u"'\'']||g') 17 | export AUTOBAHN_JS_VCS_REF=`git --git-dir="../.git" rev-list -n 1 v${AUTOBAHN_JS_VERSION} --abbrev-commit` 18 | export BUILD_DATE=`date -u +"%Y-%m-%d"` 19 | 20 | echo "" 21 | echo "The Crossbar.io Project (build date ${BUILD_DATE})" 22 | echo "" 23 | echo "autobahn-js ${AUTOBAHN_JS_VERSION} [${AUTOBAHN_JS_VCS_REF}]" 24 | echo "autobahn-js-xbr ${AUTOBAHN_JS_XBR_VERSION} [${AUTOBAHN_JS_VCS_REF}]" 25 | echo "" 26 | -------------------------------------------------------------------------------- /docker/x86_64/Dockerfile.alpine: -------------------------------------------------------------------------------- 1 | FROM alpine:edge 2 | 3 | MAINTAINER The Crossbar.io Project 4 | 5 | # Metadata 6 | ARG AUTOBAHN_JS_VERSION 7 | ARG AUTOBAHN_JS_XBR_VERSION 8 | ARG BUILD_DATE 9 | ARG AUTOBAHN_JS_VCS_REF 10 | 11 | # Metadata labeling 12 | LABEL org.label-schema.build-date=$BUILD_DATE \ 13 | org.label-schema.name="AutobahnJS Starter Template" \ 14 | org.label-schema.description="Quickstart template for application development with AutobahnJS" \ 15 | org.label-schema.url="http://crossbar.io" \ 16 | org.label-schema.vcs-ref=$AUTOBAHN_JS_VCS_REF \ 17 | org.label-schema.vcs-url="https://github.com/crossbario/autobahn-js" \ 18 | org.label-schema.vendor="The Crossbar.io Project" \ 19 | org.label-schema.version=$AUTOBAHN_JS_VERSION \ 20 | org.label-schema.schema-version="1.0" 21 | 22 | # Application home 23 | ENV HOME /app 24 | ENV DEBIAN_FRONTEND noninteractive 25 | ENV NODE_PATH /usr/lib/node_modules 26 | 27 | # we need a toolchain for the (optional) binary extensions used by Autobahn 28 | RUN apk add --update git build-base libffi-dev openssl-dev \ 29 | && rm -rf /var/cache/apk/* 30 | 31 | # Crossbar.io connection defaults 32 | ENV CBURL ws://crossbar:8080/ws 33 | ENV CBREALM realm1 34 | 35 | # make sure HOME exists! 36 | RUN mkdir /app 37 | 38 | # set the app component directory as working directory 39 | WORKDIR /app 40 | 41 | # install node 42 | RUN apk add --update nodejs nodejs-npm nodejs-dev build-base python \ 43 | && rm -rf /var/cache/apk/* 44 | 45 | # install Autobahn|JS 46 | # https://github.com/npm/npm/issues/17431#issuecomment-325892798 47 | RUN npm install -g --unsafe-perm node-gyp 48 | RUN npm install -g --unsafe-perm autobahn@${AUTOBAHN_JS_VERSION} 49 | RUN npm install -g --unsafe-perm autobahn-xbr@${AUTOBAHN_JS_XBR_VERSION} 50 | 51 | # add example service 52 | COPY ./app/* /app/ 53 | 54 | # make /app a volume to allow external configuration 55 | VOLUME /app 56 | 57 | # run service entry script by default 58 | CMD ["sh", "/app/run"] 59 | -------------------------------------------------------------------------------- /docker/x86_64/Dockerfile.full: -------------------------------------------------------------------------------- 1 | FROM node 2 | 3 | MAINTAINER The Crossbar.io Project 4 | 5 | # Metadata 6 | ARG AUTOBAHN_JS_VERSION 7 | ARG AUTOBAHN_JS_XBR_VERSION 8 | ARG BUILD_DATE 9 | ARG AUTOBAHN_JS_VCS_REF 10 | 11 | # Metadata labeling 12 | LABEL org.label-schema.build-date=$BUILD_DATE \ 13 | org.label-schema.name="AutobahnJS Starter Template" \ 14 | org.label-schema.description="Quickstart template for application development with AutobahnJS" \ 15 | org.label-schema.url="http://crossbar.io" \ 16 | org.label-schema.vcs-ref=$AUTOBAHN_JS_VCS_REF \ 17 | org.label-schema.vcs-url="https://github.com/crossbario/autobahn-js" \ 18 | org.label-schema.vendor="The Crossbar.io Project" \ 19 | org.label-schema.version=$AUTOBAHN_JS_VERSION \ 20 | org.label-schema.schema-version="1.0" 21 | 22 | # Application home 23 | ENV HOME /app 24 | ENV DEBIAN_FRONTEND noninteractive 25 | ENV NODE_PATH /usr/local/lib/node_modules 26 | 27 | RUN apt-get update \ 28 | && apt-get install -y --no-install-recommends \ 29 | ca-certificates \ 30 | git \ 31 | build-essential \ 32 | libssl-dev \ 33 | libffi-dev \ 34 | libunwind-dev \ 35 | libsnappy-dev \ 36 | libbz2-dev \ 37 | && rm -rf ~/.cache \ 38 | && rm -rf /var/lib/apt/lists/* 39 | 40 | # Crossbar.io connection defaults 41 | ENV CBURL ws://crossbar:8080/ws 42 | ENV CBREALM realm1 43 | 44 | # make sure HOME exists! 45 | RUN mkdir /app 46 | 47 | # set the app component directory as working directory 48 | WORKDIR /app 49 | 50 | # install Autobahn|JS 51 | #https://github.com/npm/npm/issues/17431#issuecomment-325892798 52 | RUN npm install -g --unsafe-perm node-gyp 53 | RUN npm install -g --unsafe-perm autobahn@${AUTOBAHN_JS_VERSION} 54 | RUN npm install -g --unsafe-perm autobahn-xbr@${AUTOBAHN_JS_XBR_VERSION} 55 | 56 | # add example service 57 | COPY ./app/* /app/ 58 | 59 | # make /app a volume to allow external configuration 60 | VOLUME /app 61 | 62 | # run service entry script by default 63 | CMD ["sh", "/app/run"] 64 | -------------------------------------------------------------------------------- /docker/x86_64/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: build 2 | 3 | HOSTIP=$(shell ip route get 1 | awk '{print $$NF;exit}') 4 | 5 | default: 6 | @echo "Targets: build, test, publish, .." 7 | 8 | 9 | #build: build_full build_alpine 10 | build: build_full 11 | 12 | build_full: 13 | time docker build \ 14 | --build-arg BUILD_DATE=${BUILD_DATE} \ 15 | --build-arg AUTOBAHN_JS_VCS_REF=${AUTOBAHN_JS_VCS_REF} \ 16 | --build-arg AUTOBAHN_JS_VERSION=${AUTOBAHN_JS_VERSION} \ 17 | --build-arg AUTOBAHN_JS_XBR_VERSION=${AUTOBAHN_JS_XBR_VERSION} \ 18 | -t crossbario/autobahn-js:full \ 19 | -t crossbario/autobahn-js:full-${AUTOBAHN_JS_VERSION} \ 20 | -f Dockerfile.full . 21 | 22 | build_alpine: 23 | time docker build \ 24 | --build-arg BUILD_DATE=${BUILD_DATE} \ 25 | --build-arg AUTOBAHN_JS_VCS_REF=${AUTOBAHN_JS_VCS_REF} \ 26 | --build-arg AUTOBAHN_JS_VERSION=${AUTOBAHN_JS_VERSION} \ 27 | --build-arg AUTOBAHN_JS_XBR_VERSION=${AUTOBAHN_JS_XBR_VERSION} \ 28 | -t crossbario/autobahn-js \ 29 | -t crossbario/autobahn-js:alpine \ 30 | -t crossbario/autobahn-js:alpine-${AUTOBAHN_JS_VERSION} \ 31 | -f Dockerfile.alpine . 32 | 33 | 34 | version: os_version node_version autobahn_version 35 | 36 | os_version: 37 | docker run -it --rm crossbario/autobahn-js:full uname -a 38 | docker run -it --rm crossbario/autobahn-js:alpine uname -a 39 | 40 | node_version: 41 | docker run -it --rm crossbario/autobahn-js:full node -v 42 | docker run -it --rm crossbario/autobahn-js:alpine node -v 43 | 44 | autobahn_version: 45 | docker run -it --rm crossbario/autobahn-js:full sh -c "echo \"console.log('autobahn-' + require('autobahn').version + ' is installed');\" | node" 46 | docker run -it --rm crossbario/autobahn-js:alpine sh -c "echo \"console.log('autobahn-' + require('autobahn').version + ' is installed');\" | node" 47 | 48 | 49 | ping: ping_full ping_alpine 50 | 51 | ping_full: 52 | docker run --add-host=crossbar:$(HOSTIP) -it --rm crossbario/autobahn-js:full ping crossbar 53 | 54 | ping_alpine: 55 | docker run --add-host=crossbar:$(HOSTIP) -it --rm crossbario/autobahn-js:alpine ping crossbar 56 | 57 | 58 | test: test_full test_alpine 59 | 60 | test_full: 61 | docker run -it --rm --link crossbar crossbario/autobahn-js:full 62 | 63 | test_alpine: 64 | docker run -it --rm --link crossbar crossbario/autobahn-js:alpine 65 | 66 | 67 | publish: publish_full publish_alpine 68 | 69 | publish_alpine: build_alpine 70 | docker push crossbario/autobahn-js 71 | docker push crossbario/autobahn-js:alpine 72 | docker push crossbario/autobahn-js:alpine-${AUTOBAHN_JS_VERSION} 73 | 74 | publish_full: build_full 75 | docker push crossbario/autobahn-js:full 76 | docker push crossbario/autobahn-js:full-${AUTOBAHN_JS_VERSION} 77 | 78 | 79 | list: 80 | -docker images crossbario/autobahn-js:* 81 | 82 | clean: 83 | ./removeall.sh 84 | -------------------------------------------------------------------------------- /docker/x86_64/README.md: -------------------------------------------------------------------------------- 1 | # AutobahnJS for Docker 2 | 3 | Here you find the Dockerfiles for creating the [AutobahnJS for Docker images](https://hub.docker.com/r/crossbario/autobahn-js/) maintained by the Crossbar.io Project. 4 | 5 | These images come with NodeJS and AutobahnJS preinstalled and are intended to base application service containers on. 6 | 7 | ## Images 8 | 9 | 1. **`crossbario/autobahn-js:latest` == `crossbario/autobahnjs:alpine`: Alpine Linux based variant, the default (<27MB container size)** RECOMMENDED FOR GENERAL USE 10 | 2. `crossbario/autobahn-js:full`: Variant based on full Node image (650MB container size) 11 | 12 | ## Build, test and deploy 13 | 14 | To build, test and deploy the AutobahnJS images to DockerHub, do: 15 | 16 | ```console 17 | make build 18 | make test 19 | make publish 20 | ``` 21 | 22 | > You will need a Crossbar.io container running. Run `make crossbar` in the `crossbar` folder of this repo. 23 | -------------------------------------------------------------------------------- /docker/x86_64/app/README.txt: -------------------------------------------------------------------------------- 1 | Put your microservice code and assets in here. 2 | 3 | The container will automatically start the script client.js in this folder. 4 | 5 | The environment of the script will have these variables set: 6 | 7 | * CBURL = ws://crossbar:8080/ws 8 | * CBREALM = realm1 9 | 10 | where the host crossbar resolves to a linked Docker container running Crossbar.io. 11 | -------------------------------------------------------------------------------- /docker/x86_64/app/client.js: -------------------------------------------------------------------------------- 1 | // Example WAMP client for AutobahnJS connecting to a Crossbar.io WAMP router. 2 | 3 | // AutobahnJS, the WAMP client library to connect and talk to Crossbar.io: 4 | var autobahn = require('autobahn'); 5 | 6 | console.log("Running AutobahnJS " + autobahn.version); 7 | 8 | // We read the connection parameters from the command line in this example: 9 | const url = process.env.CBURL; 10 | const realm = process.env.CBREALM; 11 | 12 | // Make us a new connection .. 13 | var connection = new autobahn.Connection({url: url, realm: realm}); 14 | 15 | // .. and fire this code when we got a session 16 | connection.onopen = function (session, details) { 17 | console.log("session open!", details); 18 | 19 | // Your code goes here: use WAMP via the session you got to 20 | // call, register, subscribe and publish .. 21 | 22 | connection.close(); 23 | }; 24 | 25 | // .. and fire this code when our session has gone 26 | connection.onclose = function (reason, details) { 27 | console.log("session closed: " + reason, details); 28 | } 29 | 30 | // Don't forget to actually trigger the opening of the connection! 31 | connection.open(); 32 | -------------------------------------------------------------------------------- /docker/x86_64/app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "crossbarclient", 3 | "version": "0.0.0", 4 | "description": "AutobahnJS demo client connecting to Crossbar.io", 5 | "dependencies": { 6 | }, 7 | "main": "client.js", 8 | "scripts": { 9 | "test": "echo \"Error: no test specified\" && exit 1" 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "git://github.com/crossbario/crossbar-docker.git" 14 | }, 15 | "author": "The Crossbar.io Project", 16 | "license": "MIT" 17 | } 18 | -------------------------------------------------------------------------------- /docker/x86_64/app/run: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | npm install 4 | node client.js 5 | -------------------------------------------------------------------------------- /docker/x86_64/removeall.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | docker rmi -f $(docker images -q crossbario/autobahn-js:* | uniq) 4 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "autobahn-development", 3 | "description": "Local development package (never pubished) for autobahn and autobahn-xbr library development and CI.", 4 | "private": true, 5 | "engines": { 6 | "node": ">= 4.2.6" 7 | }, 8 | "devDependencies": { 9 | "browserify": "^16.5.2", 10 | "deep-equal": ">= 1.0.1", 11 | "google-closure-compiler": ">= 20170218.0.0", 12 | "nodeunit": ">= 0.11.3", 13 | "random-bytes-seed": ">=1.0.3", 14 | "dotenv": "^16.0.3" 15 | }, 16 | "repository": { 17 | "type": "git", 18 | "url": "git://github.com/crossbario/autobahn-js.git" 19 | }, 20 | "author": "Crossbar.io Technologies GmbH", 21 | "license": "MIT", 22 | "dependencies": {} 23 | } 24 | -------------------------------------------------------------------------------- /packages/autobahn-xbr/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) Crossbar.io Technologies GmbH and contributors. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | the Software, and to permit persons to whom the Software is furnished to do so, 8 | subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | -------------------------------------------------------------------------------- /packages/autobahn-xbr/SConstruct: -------------------------------------------------------------------------------- 1 | import os 2 | import json 3 | import pkg_resources 4 | import subprocess 5 | from sys import platform 6 | 7 | taschenmesser = pkg_resources.resource_filename('taschenmesser', '..') 8 | #taschenmesser = "../../infrequent/taschenmesser" 9 | ENV=os.environ 10 | 11 | if 'JAVA_HOME' in ENV: 12 | print('Using from environment: JAVA_HOME={}'.format(ENV['JAVA_HOME'])) 13 | elif platform == "darwin": 14 | ENV['JAVA_HOME'] = subprocess.check_output("/usr/libexec/java_home").strip() 15 | print('Using OSX default: JAVA_HOME={}'.format(ENV['JAVA_HOME'])) 16 | elif platform == "linux" or platform == "linux2": 17 | ENV['JAVA_HOME'] = subprocess.check_output("echo 'System.out.println(java.lang.System.getProperty(\"java.home\"));' | jshell -", shell=True).strip() 18 | print('Using Linux default: JAVA_HOME={}'.format(ENV['JAVA_HOME'])) 19 | 20 | if 'JS_COMPILER' in ENV: 21 | print('Using from environment: JS_COMPILER={}'.format(ENV['JS_COMPILER'])) 22 | else: 23 | #ENV['JS_COMPILER'] = '/usr/local/lib/node_modules/google-closure-compiler-java/compiler.jar' 24 | ENV['JS_COMPILER'] = str(Dir('.').abspath) + '/node_modules/google-closure-compiler-java/compiler.jar' 25 | print('Using builtin: JS_COMPILER={}'.format(ENV['JS_COMPILER'])) 26 | 27 | env = Environment(tools = ['default', 'taschenmesser'], 28 | toolpath = [taschenmesser], 29 | ENV = ENV) 30 | 31 | # Get package version 32 | version = json.load(open('package.json'))['version'] 33 | print("Building AutobahnXBRJS {}".format(version)) 34 | 35 | env['JS_DEFINES'] = { 36 | # 'AUTOBAHNXBRJS_VERSION': "'%s'" % version 37 | } 38 | 39 | # Source for Autobahn XBR package 40 | sourcedir = 'lib' 41 | sources = [os.path.join(sourcedir, d) for d in os.listdir(sourcedir)] 42 | 43 | print("sources:", sources) 44 | 45 | # browserified 46 | ab = env.Command("build/autobahn-xbr.js", 47 | "lib/autobahn-xbr.js", 48 | "../../node_modules/browserify/bin/cmd.js $SOURCE --ignore-missing --standalone autobahn-xbr -o $TARGET") 49 | Depends(ab, sources) 50 | 51 | if False: 52 | # minimized (with Google Closure) 53 | ab_min = env.JavaScript("build/autobahn-xbr.min.js", 54 | ab, 55 | #JS_COMPILATION_LEVEL = "ADVANCED_OPTIMIZATIONS") 56 | #JS_COMPILATION_LEVEL = "SIMPLE_OPTIMIZATIONS", 57 | JS_COMPILATION_LEVEL = "WHITESPACE_ONLY", 58 | # --allow_method_call_decomposing 59 | #JS_OUTPUT_LANG = "ES5", 60 | ) 61 | 62 | # minimized & compressed 63 | ab_min_gz = env.GZip("build/autobahn-xbr.min.jgz", 64 | ab_min) 65 | 66 | 67 | # list of generated artifacts 68 | artifacts = [ab, 69 | ab_min, 70 | ab_min_gz] 71 | else: 72 | artifacts = [ab] 73 | 74 | # generate checksum files 75 | checksums = [] 76 | checksums.append(env.MD5("build/CHECKSUM.MD5", artifacts)) 77 | checksums.append(env.SHA1("build/CHECKSUM.SHA1", artifacts)) 78 | checksums.append(env.SHA256("build/CHECKSUM.SHA256", artifacts)) 79 | 80 | # fixed static files to be included 81 | statics = [] 82 | for f in ["LICENSE"]: 83 | statics.append(Command("build/{}".format(f), [], Copy("$TARGET", f))) 84 | 85 | # The default target consists of all artifacts that 86 | # would get published 87 | uploads = artifacts + checksums + statics 88 | Default(uploads) 89 | #Default(ab) 90 | 91 | # Upload to Amazon S3 92 | env['S3_BUCKET'] = 'autobahn' 93 | env['S3_OBJECT_ACL'] = 'public-read' 94 | 95 | published = [] 96 | 97 | for s in ['latest', version]: 98 | e = env.Clone(S3_BUCKET_PREFIX = 'autobahnxbrjs/{}/'.format(s)) # note the trailing slash! 99 | published.append(AlwaysBuild(e.S3("build/.S3UploadDone_{}".format(s), uploads))) 100 | 101 | 102 | # The uploaded stuff is always considered stale 103 | Depends(published, uploads) 104 | 105 | Alias("publish", published) 106 | -------------------------------------------------------------------------------- /packages/autobahn-xbr/index.js: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // AutobahnJS - http://autobahn.ws, http://wamp.ws 4 | // 5 | // A JavaScript library for WAMP ("The Web Application Messaging Protocol"). 6 | // 7 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 8 | // 9 | // Licensed under the MIT License. 10 | // http://www.opensource.org/licenses/mit-license.php 11 | // 12 | /////////////////////////////////////////////////////////////////////////////// 13 | 14 | module.exports = require('./lib/autobahn-xbr.js'); 15 | -------------------------------------------------------------------------------- /packages/autobahn-xbr/lib/autobahn-xbr.js: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // XBR Open Data Markets - https://xbr.network 4 | // 5 | // JavaScript client library for the XBR Network. 6 | // 7 | // Copyright (C) Crossbar.io Technologies GmbH and contributors 8 | // 9 | // Licensed under the MIT License. 10 | // http://www.opensource.org/licenses/mit-license.php 11 | // 12 | /////////////////////////////////////////////////////////////////////////////// 13 | 14 | // FIXME: this breaks MetaMask!? 15 | var web3 = require('web3'); 16 | var BN = web3.utils.BN; 17 | exports.web3 = web3; 18 | exports.BN = BN; 19 | 20 | var cbor = require('cbor'); 21 | exports.cbor = cbor; 22 | 23 | var pjson = require('../package.json'); 24 | exports.version = pjson.version; 25 | 26 | var ethereum = require('./ethereum.js'); 27 | 28 | var eip712 = require('./eip712.js'); 29 | exports.sign_eip712_data = eip712.sign_eip712_data; 30 | exports.recover_eip712_signer = eip712.recover_eip712_signer; 31 | exports.create_market_member_login = eip712.create_market_member_login; 32 | 33 | exports.SimpleBuyer = require('./buyer.js').SimpleBuyer; 34 | exports.SimpleSeller = require('./seller.js').SimpleSeller; 35 | exports.SimpleBlockchain = require('./blockchain.js'); 36 | 37 | // export XBR smart contract Web3 generated classes 38 | exports.XBRToken = ethereum.XBRToken; 39 | exports.XBRNetwork = ethereum.XBRNetwork; 40 | exports.XBRChannel = ethereum.XBRChannel; 41 | 42 | var setProvider = async function(provider) { 43 | await ethereum.setProvider(provider); 44 | exports.xbrtoken = ethereum.xbrtoken; 45 | exports.xbrnetwork = ethereum.xbrnetwork; 46 | exports.xbrchannel = ethereum.xbrchannel; 47 | }; 48 | 49 | exports.setProvider = setProvider; 50 | exports.xbrtoken = null; 51 | exports.xbrnetwork = null; 52 | 53 | // debug log output 54 | if ('XBR_DEBUG' in global && XBR_DEBUG) { 55 | console.log('XBR_DEBUG mode enabled'); 56 | } 57 | 58 | // Solidity enums are not supported in the ABI, so we replicate the enum 59 | // constants here manually 60 | // https://solidity.readthedocs.io/en/latest/frequently-asked-questions.html#if-i-return-an-enum-i-only-get-integer-values-in-web3-js-how-to-get-the-named-values 61 | 62 | exports.MemberLevel = ethereum.MemberLevel; 63 | exports.NodeType = ethereum.NodeType; 64 | exports.ActorType = ethereum.ActorType; 65 | 66 | let util = require('./util.js'); 67 | 68 | exports.uuid = util.uuid; 69 | exports.pack_uint256 = util.pack_uint256; 70 | exports.unpack_uint256 = util.unpack_uint256; 71 | exports.with_0x = util.with_0x; 72 | exports.without_0x = util.without_0x; 73 | exports.XBR = util.XBR; 74 | -------------------------------------------------------------------------------- /packages/autobahn-xbr/lib/blockchain.js: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // XBR Open Data Markets - https://xbr.network 4 | // 5 | // JavaScript client library for the XBR Network. 6 | // 7 | // Copyright (C) Crossbar.io Technologies GmbH and contributors 8 | // 9 | // Licensed under the MIT License. 10 | // http://www.opensource.org/licenses/mit-license.php 11 | // 12 | /////////////////////////////////////////////////////////////////////////////// 13 | 14 | var Web3 = require("web3"); 15 | var xbr = require('./ethereum.js'); 16 | 17 | var DomainStatus_NULL = 0; 18 | var DomainStatus_ACTIVE = 1; 19 | var DomainStatus_CLOSED = 2; 20 | 21 | var SimpleBlockchain = function (gateway) { 22 | this.gateway = gateway; 23 | this.w3 = null; 24 | }; 25 | 26 | SimpleBlockchain.prototype.start = function() { 27 | if (this.gateway != null) { 28 | return; 29 | } 30 | 31 | if (this.gateway == null) { 32 | this.w3 = new Web3(Web3.currentProvider); 33 | } else { 34 | this.w3 = new Web3(new Web3.providers.HttpProvider(this.gateway)); 35 | } 36 | 37 | if (this.w3.isConnected()) { 38 | throw `could not connect to Web3/Ethereum at: ${this.gateway || 'auto'}`; 39 | } else { 40 | console.log(`Connected to network ${this.w3.version.network} at provider ${this.gateway || 'auto'}`) 41 | } 42 | }; 43 | 44 | SimpleBlockchain.prototype.stop = function() { 45 | this.w3 = null; 46 | }; 47 | 48 | SimpleBlockchain.prototype.getMarketStatus = async function(marketID) { 49 | let owner = xbr.xbrnetwork.functions.getMarketOwner(marketID).call(); 50 | if (owner == null || owner == "0x0000000000000000000000000000000000000000") { 51 | return null; 52 | } else { 53 | return {'owner': owner} 54 | } 55 | }; 56 | 57 | SimpleBlockchain.prototype.getDomainStatus = async function(domainID) { 58 | status = xbr.xbrnetwork.functions.getDomainStatus(domainID).call(); 59 | if (status == DomainStatus_NULL) { 60 | return null; 61 | } else if (status == DomainStatus_ACTIVE) { 62 | return {'status': 'ACTIVE'} 63 | } else if (status == DomainStatus_CLOSED) { 64 | return {'status': 'CLOSED'} 65 | } 66 | }; 67 | 68 | SimpleBlockchain.prototype.getNodeStatus = function(delegateAddr) { 69 | 70 | }; 71 | 72 | SimpleBlockchain.prototype.getActorStatus = function(channelAddr) { 73 | 74 | }; 75 | 76 | SimpleBlockchain.prototype.getDelegateStatus = function(delegateAddr) { 77 | 78 | }; 79 | 80 | SimpleBlockchain.prototype.getChannelStatus = function(channelAddr) { 81 | 82 | }; 83 | 84 | SimpleBlockchain.prototype.getMemberStatus = async function(memberAddr) { 85 | var level = xbr.xbrnetwork.functions.getMemberLevel(memberAddr).call(); 86 | if (level == null) { 87 | return null; 88 | } 89 | var eula = xbr.xbrnetwork.functions.getMemberEula(memberAddr).call(); 90 | if (eula == null || eula.trim() == '') { 91 | return null; 92 | } 93 | var profile = xbr.xbrnetwork.functions.getMemberProfile(memberAddr).call(); 94 | if (profile == null || profile.trim() == '') { 95 | profile = null; 96 | } 97 | return { 98 | 'eula': eula, 99 | 'profile': profile, 100 | } 101 | }; 102 | 103 | SimpleBlockchain.prototype.getBalances = async function(accountAddr) { 104 | var balanceETH = this.w3.eth.getBalance(accountAddr); 105 | var balanceXBR = xbr.xbrtoken.functions.balanceOf(accountAddr).call() 106 | return { 107 | 'ETH': balanceETH, 108 | 'XBR': balanceXBR, 109 | } 110 | }; 111 | 112 | SimpleBlockchain.prototype.getContractAddr = function() { 113 | return { 114 | 'XBRToken': xbr.xbrtoken.address, 115 | 'XBRNetwork': xbr.xbrnetwork.address, 116 | } 117 | }; 118 | 119 | exports.SimpleBlockchain = SimpleBlockchain; 120 | -------------------------------------------------------------------------------- /packages/autobahn-xbr/lib/ethereum.js: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // XBR Open Data Markets - https://xbr.network 4 | // 5 | // JavaScript client library for the XBR Network. 6 | // 7 | // Copyright (C) Crossbar.io Technologies GmbH and contributors 8 | // 9 | // Licensed under the MIT License. 10 | // http://www.opensource.org/licenses/mit-license.php 11 | // 12 | /////////////////////////////////////////////////////////////////////////////// 13 | 14 | // https://truffleframework.com/docs/truffle/getting-started/package-management-via-npm#within-javascript-code 15 | var contract = require("@truffle/contract"); 16 | 17 | var XBRToken_json = require("./contracts/XBRToken.json"); 18 | var XBRNetwork_json = require("./contracts/XBRNetwork.json"); 19 | var XBRChannel_json = require("./contracts/XBRChannel.json"); 20 | 21 | var XBRToken = contract(XBRToken_json); 22 | var XBRNetwork = contract(XBRNetwork_json); 23 | var XBRChannel = contract(XBRChannel_json); 24 | 25 | // a Web3 provider must be set by the user first to use this library 26 | var setProvider = async function (provider) { 27 | XBRToken.setProvider(provider); 28 | XBRNetwork.setProvider(provider); 29 | XBRChannel.setProvider(provider); 30 | await init_xbr(); 31 | }; 32 | 33 | var MemberLevel = { 34 | NONE: 0, 35 | ACTIVE: 1, 36 | VERIFIED: 2, 37 | RETIRED: 3, 38 | PENALTY: 4, 39 | BLOCKED: 5, 40 | }; 41 | var NodeType = { 42 | NONE: 0, 43 | MASTER: 1, 44 | CORE: 2, 45 | EDGE: 3, 46 | }; 47 | var ActorType = { 48 | NONE: 0, 49 | NETWORK: 1, 50 | MARKET: 2, 51 | PROVIDER: 3, 52 | CONSUMER: 4, 53 | }; 54 | // 55 | // as long as we haven't deployed the XBR smart contracts to 56 | // any public network (testnets or mainnet), a user must set the 57 | // addresses of our deployed token and network smart contracts 58 | // on the (private) network the user is connecting to and where 59 | // the XBR contracts need to be deployed 60 | // 61 | async function init_xbr() { 62 | if ('XBR_DEBUG_TOKEN_ADDR' in global && XBR_DEBUG_TOKEN_ADDR) { 63 | exports.xbrtoken = await XBRToken.at(XBR_DEBUG_TOKEN_ADDR); 64 | } else { 65 | console.log('WARNING: The XBR smart contracts are not yet depoyed to public networks. Please set XBR_DEBUG_TOKEN_ADDR manually.'); 66 | exports.xbrtoken = await XBRToken.at("0xcfeb869f69431e42cdb54a4f4f105c19c080a601"); 67 | } 68 | 69 | if ('XBR_DEBUG_NETWORK_ADDR' in global && XBR_DEBUG_NETWORK_ADDR) { 70 | exports.xbrnetwork = await XBRNetwork.at(XBR_DEBUG_NETWORK_ADDR); 71 | } else { 72 | console.log('WARNING: The XBR smart contracts are not yet depoyed to public networks. Please set XBR_DEBUG_NETWORK_ADDR manually.'); 73 | exports.xbrnetwork = await XBRNetwork.at("0x254dffcd3277c0b1660f6d42efbb754edababc2b"); 74 | } 75 | 76 | if ('XBR_DEBUG_CHANNEL_ADDR' in global && XBR_DEBUG_CHANNEL_ADDR) { 77 | exports.xbrchannel = await XBRChannel.at(XBR_DEBUG_CHANNEL_ADDR); 78 | } else { 79 | console.log('WARNING: The XBR smart contracts are not yet depoyed to public networks. Please set XBR_DEBUG_CHANNEL_ADDR manually.'); 80 | exports.xbrchannel = await XBRChannel.at("0x670497A012322B99a5C18B8463940996141Cb952"); 81 | } 82 | } 83 | 84 | exports.XBRToken = XBRToken; 85 | exports.XBRNetwork = XBRNetwork; 86 | exports.XBRChannel = XBRChannel; 87 | exports.MemberLevel = MemberLevel; 88 | exports.NodeType = NodeType; 89 | exports.ActorType = ActorType; 90 | exports.setProvider = setProvider; 91 | -------------------------------------------------------------------------------- /packages/autobahn-xbr/lib/keyseries.js: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // XBR Open Data Markets - https://xbr.network 4 | // 5 | // JavaScript client library for the XBR Network. 6 | // 7 | // Copyright (C) Crossbar.io Technologies GmbH and contributors 8 | // 9 | // Licensed under the MIT License. 10 | // http://www.opensource.org/licenses/mit-license.php 11 | // 12 | /////////////////////////////////////////////////////////////////////////////// 13 | 14 | var cbor = require('cbor'); 15 | var nacl = require('tweetnacl'); 16 | var sealedbox = require('tweetnacl-sealedbox-js'); 17 | 18 | 19 | var KeySeries = function(api_id, prefix, price, interval, on_rotate) { 20 | 21 | this.api_id = api_id; 22 | this.price = price; 23 | this.interval = interval; 24 | this.prefix = prefix; 25 | this.on_rotate = on_rotate; 26 | this._archive = {}; 27 | this._started = false; 28 | }; 29 | 30 | 31 | KeySeries.prototype.encrypt = function (payload) { 32 | 33 | const nonce = nacl.randomBytes(nacl.secretbox.nonceLength); 34 | const box = nacl.secretbox(cbor.encode(payload), nonce, this._archive[this.key_id]); 35 | var ciphertext = new Uint8Array(nonce.length + box.length); 36 | 37 | ciphertext.set(nonce); 38 | ciphertext.set(box, nonce.length); 39 | 40 | return [this.key_id, 'cbor', ciphertext]; 41 | }; 42 | 43 | 44 | KeySeries.prototype.encryptKey = function(key_id, buyer_pubkey) { 45 | return sealedbox.seal(this._archive[key_id], buyer_pubkey) 46 | }; 47 | 48 | 49 | KeySeries.prototype.start = function() { 50 | if (!this._started) { 51 | this._rotate(this); 52 | this._started = true; 53 | } 54 | }; 55 | 56 | 57 | KeySeries.prototype._rotate = function (context) { 58 | context.key_id = Buffer.from(nacl.randomBytes(16)); 59 | context._archive[context.key_id] = nacl.randomBytes(nacl.secretbox.keyLength); 60 | context.on_rotate(context); 61 | 62 | // rotate key every "interval" seconds 63 | // FIXME: make this to wait for the above on_rotate callback to finish 64 | setTimeout(context._rotate, context.interval * 1000, context); 65 | }; 66 | 67 | 68 | KeySeries.prototype.stop = function() { 69 | if (this._started) { 70 | this._started = false; 71 | } 72 | }; 73 | 74 | 75 | exports.KeySeries = KeySeries; 76 | -------------------------------------------------------------------------------- /packages/autobahn-xbr/lib/log.js: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // XBR Open Data Markets - https://xbr.network 4 | // 5 | // JavaScript client library for the XBR Network. 6 | // 7 | // Copyright (C) Crossbar.io Technologies GmbH and contributors 8 | // 9 | // Licensed under the MIT License. 10 | // http://www.opensource.org/licenses/mit-license.php 11 | // 12 | /////////////////////////////////////////////////////////////////////////////// 13 | 14 | var debug = function () {}; 15 | 16 | if ('AUTOBAHN_DEBUG' in global && AUTOBAHN_DEBUG && 'console' in global) { 17 | debug = function () { 18 | console.log.apply(console, arguments); 19 | } 20 | } 21 | 22 | var warn = console.warn; 23 | 24 | exports.debug = debug; 25 | exports.warn = warn; 26 | -------------------------------------------------------------------------------- /packages/autobahn-xbr/lib/util.js: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // AutobahnJS - http://autobahn.ws, http://wamp.ws 4 | // 5 | // A JavaScript library for WAMP ("The Web Application Messaging Protocol"). 6 | // 7 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 8 | // 9 | // Licensed under the MIT License. 10 | // http://www.opensource.org/licenses/mit-license.php 11 | // 12 | /////////////////////////////////////////////////////////////////////////////// 13 | 14 | const assert = require('assert'); 15 | const web3 = require('web3'); 16 | const BN = web3.utils.BN; 17 | 18 | // https://www.npmjs.com/package/uuid 19 | const _uuid = require('uuid'); 20 | 21 | // https://www.npmjs.com/package/uuid-parse 22 | const uuid_parse = require('uuid-parse'); 23 | 24 | // the XBR token has 18 decimals 25 | const decimals = new BN('1000000000000000000'); 26 | 27 | 28 | function pack_uint256 (value) { 29 | assert(BN.isBN(value)); 30 | 31 | // if (typeof Buffer !== 'undefined') { 32 | if (global.process && global.process.versions.node) { 33 | // running on Node 34 | return value.toBuffer('be', 32); 35 | } else { 36 | // running in Browser 37 | /* 38 | https://github.com/indutny/bn.js/issues/147 39 | https://github.com/browserify/insert-module-globals 40 | https://github.com/browserify/browserify#compatibility 41 | 42 | we need Buffer, because of the following assert in BN: 43 | 44 | BN.prototype.toBuffer = function toBuffer (endian, length) { 45 | assert(typeof Buffer !== 'undefined'); 46 | return this.toArrayLike(Buffer, endian, length); 47 | }; 48 | */ 49 | return new Uint8Array(value.toArray('be', 32)); 50 | } 51 | } 52 | 53 | 54 | function unpack_uint256 (value) { 55 | let buffer = Buffer.from(value); 56 | return buffer.readUIntBE(0, value.length); 57 | } 58 | 59 | 60 | function uuid (value) { 61 | 62 | if (value !== undefined) { 63 | // parse UUID string 64 | 65 | // if (typeof Buffer !== 'undefined') { 66 | if (global.process && global.process.versions.node) { 67 | // running on Node 68 | return Buffer.from(uuid_parse.parse(value)); 69 | } else { 70 | // running in Browser 71 | return new Uint8Array(uuid_parse.parse(value)); 72 | } 73 | 74 | } else { 75 | // generate a new UUID 76 | 77 | // if (typeof Buffer !== 'undefined') { 78 | if (global.process && global.process.versions.node) { 79 | // running on Node 80 | const buffer = []; 81 | _uuid.v4(null, buffer); 82 | return Buffer.from(buffer); 83 | } else { 84 | // running in Browser 85 | const buffer = []; 86 | _uuid.v4(null, buffer); 87 | return new Uint8Array(buffer); 88 | } 89 | } 90 | } 91 | 92 | 93 | function without_0x (string) { 94 | assert(typeof string === 'string', 'Input must be a string') 95 | 96 | if (string.startsWith("0x")) { 97 | return string.substring(2); 98 | } 99 | 100 | return string; 101 | } 102 | 103 | 104 | function with_0x (string) { 105 | assert(typeof string === 'string', 'Input must be a string') 106 | 107 | if (!string.startsWith("0x")) { 108 | return '0x' + string; 109 | } 110 | 111 | return string; 112 | } 113 | 114 | 115 | function XBR(value) { 116 | return new BN(value).mul(decimals); 117 | } 118 | 119 | 120 | exports.pack_uint256 = pack_uint256; 121 | exports.unpack_uint256 = unpack_uint256; 122 | exports.uuid = uuid; 123 | exports.without_0x = without_0x; 124 | exports.with_0x = with_0x; 125 | exports.XBR = XBR; 126 | -------------------------------------------------------------------------------- /packages/autobahn-xbr/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "autobahn-xbr", 3 | "version": "22.11.1", 4 | "description": "The XBR Protocol (smart contracts package)", 5 | "main": "index.js", 6 | "files": [ 7 | "index.js", 8 | "/lib" 9 | ], 10 | "scripts": { 11 | "test": "nodeunit test/test.js" 12 | }, 13 | "engines": { 14 | "node": ">= 7.10.1" 15 | }, 16 | "dependencies": { 17 | "@truffle/contract": ">=4.1.5", 18 | "autobahn": "^20.4.1", 19 | "cbor": ">=3.0.0", 20 | "crypto-js": ">=3.1.8", 21 | "eth-sig-util": "^2.5.3", 22 | "ethereumjs-util": ">=6.1.0", 23 | "msgpack5": ">= 3.6.0", 24 | "sha3": ">=2.0.1", 25 | "tweetnacl": ">= 0.14.3", 26 | "tweetnacl-sealedbox-js": ">=1.1.0", 27 | "uuid": "^8.3.0", 28 | "uuid-parse": ">=1.1.0", 29 | "web3": ">=1.2.1", 30 | "web3-eth-accounts": "^1.2.11", 31 | "when": ">= 3.7.7", 32 | "ws": ">= 1.1.4" 33 | }, 34 | "browser": { 35 | "ws": false 36 | }, 37 | "repository": { 38 | "type": "git", 39 | "url": "git://github.com/crossbario/autobahn-js.git" 40 | }, 41 | "keywords": [ 42 | "ethereum", 43 | "solidity", 44 | "xbr", 45 | "crossbar", 46 | "autobahn", 47 | "wamp", 48 | "data-service", 49 | "data-monetization" 50 | ], 51 | "author": "Crossbar.io Technologies GmbH", 52 | "license": "Apache-2.0" 53 | } 54 | -------------------------------------------------------------------------------- /packages/autobahn-xbr/test/Makefile: -------------------------------------------------------------------------------- 1 | web: 2 | twistd -n web --listen tcp:8050 --path ./onchain 3 | -------------------------------------------------------------------------------- /packages/autobahn-xbr/test/README.md: -------------------------------------------------------------------------------- 1 | # XBR tests 2 | 3 | EIP712 signatures: 4 | 5 | ``` 6 | (cpy373_1) oberstet@intel-nuci7:~/scm/crossbario/autobahn-js/test/xbr$ node test_typed.js 7 | Using private key: 0xa4985a2ed93107886e9a1f12c7b8e2e351cc1d26c42f3aab7f220f3a7d08fda6 8 | Account canonical address: 0x3F979903ACBd194cA450DC956df17A6dF392ec08 9 | Ok, signed typed data using 0x3F979903ACBd194cA450DC956df17A6dF392ec08 10 | SIGNATURE = 0x84cb6534d5b9a3b2e5eeb5420ce45bd62380f04d5e08f64f3b9d44b1b3f2aedc56fd6c5eee942d1e490960988c1c9c4b2c082836e1d79d062eb88ad18a4eb62f1c 11 | Ok, verified signature was signed by 0x3F979903ACBd194cA450DC956df17A6dF392ec08 12 | ``` 13 | -------------------------------------------------------------------------------- /packages/autobahn-xbr/test/client/Makefile: -------------------------------------------------------------------------------- 1 | diff: 2 | clear 3 | @echo "" 4 | @echo "\n******* SELLER DIFF between browser/node:\n" 5 | -diff browser/seller.js nodejs/seller.js 6 | @echo "\n******* BUYER DIFF between browser/node:\n" 7 | -diff browser/buyer.js nodejs/buyer.js 8 | @echo "" 9 | -------------------------------------------------------------------------------- /packages/autobahn-xbr/test/client/README.md: -------------------------------------------------------------------------------- 1 | # XBR Seller/Buyer with Autobahn-JS 2 | 3 | Install NodeJS: 4 | 5 | ```bash 6 | cd $HOME 7 | wget https://nodejs.org/dist/v10.16.0/node-v10.16.0-linux-x64.tar.xz 8 | tar xvf node-v10.16.0-linux-x64.tar.xz 9 | ``` 10 | 11 | and add the following to `$HOME/.profile`: 12 | 13 | ```bash 14 | export PATH=${HOME}/node-v10.16.0-linux-x64/bin:${PATH} 15 | ``` 16 | 17 | Install dependencies 18 | 19 | ```bash 20 | make deps 21 | ``` 22 | 23 | To start the seller run 24 | 25 | ```bash 26 | make seller 27 | ``` 28 | 29 | For the buyer 30 | 31 | ```bash 32 | make buyer 33 | ``` 34 | -------------------------------------------------------------------------------- /packages/autobahn-xbr/test/client/browser/Makefile: -------------------------------------------------------------------------------- 1 | run: 2 | twistd -n web --listen tcp:8050 --path . 3 | -------------------------------------------------------------------------------- /packages/autobahn-xbr/test/client/browser/README.md: -------------------------------------------------------------------------------- 1 | # XBR Buyer/Seller for Browser 2 | 3 | This folder contains a simple XBR buyer and XBR seller that runs in a HTML5 browser (Firefox/Chrome tested). 4 | 5 | Open 6 | 7 | * [XBR Buyer](buyer.html) 8 | * [XBR Seller](seller.html) 9 | 10 | and hit F12 to watch console output. 11 | 12 | > The respective JS code is identical to the NodeJS examples - the only difference are the very top couple of lines that import the Autobahn libraries. 13 | -------------------------------------------------------------------------------- /packages/autobahn-xbr/test/client/browser/buyer.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |

XBR Buyer Example

9 |

Open JavaScript console to watch output.

10 | 11 | 12 | -------------------------------------------------------------------------------- /packages/autobahn-xbr/test/client/browser/buyer.js: -------------------------------------------------------------------------------- 1 | const xbr = autobahnXbr; 2 | 3 | 4 | console.log('Running Autobahn ' + autobahn.version); 5 | console.log('Running Autobahn-XBR ' + xbr.version); 6 | 7 | 8 | // WAMP connection 9 | var connection = new autobahn.Connection({ 10 | realm: "realm1", 11 | transports: [ 12 | { 13 | url: 'ws://localhost:8080/ws', 14 | type: 'websocket', 15 | serializers: [ new autobahn.serializer.MsgpackSerializer() ] 16 | } 17 | ] 18 | }); 19 | 20 | 21 | // callback fired upon new WAMP session 22 | connection.onopen = function (session, details) { 23 | 24 | console.log("WAMP session connected:", details); 25 | 26 | // ethereum private key of buyer2 delegate1 27 | const buyer2_delegate1_pkey = "0x21d7212f3b4e5332fd465877b64926e3532653e2798a11255a46f533852dfe46"; 28 | 29 | // market maker ethereum address 30 | const marketmaker_adr = "0x3E5e9111Ae8eB78Fe1CC3bb8915d5D461F3Ef9A9"; 31 | 32 | // the XBR token has 18 decimals 33 | const decimals = new xbr.BN('1000000000000000000'); 34 | 35 | // maximum price we are willing to pay per (single) key: 100 XBR 36 | const max_price = new xbr.BN('100').mul(decimals); 37 | 38 | // instantiate a simple buyer 39 | var buyer = new xbr.SimpleBuyer(marketmaker_adr, buyer2_delegate1_pkey, max_price); 40 | 41 | // start buying .. 42 | buyer.start(session).then( 43 | // success: we've got an active payment channel with remaining balance .. 44 | function (balance) { 45 | console.log("Buyer has started, remaining balance in active payment channel is " + balance.div(decimals) + " XBR"); 46 | 47 | session.subscribe("io.crossbar.example", function (args, kwargs, details) { 48 | let [key_id, enc_ser, ciphertext] = args; 49 | 50 | // decrypt the XBR payload, potentially automatically buying a new data encryption key 51 | buyer.unwrap(key_id, enc_ser, ciphertext).then( 52 | function (payload) { 53 | console.log("Received event " + details.publication, payload) 54 | }, 55 | function (failure) { 56 | console.log(failure); 57 | location.reload(true); 58 | } 59 | ) 60 | }); 61 | 62 | }, 63 | // we don't have an active payment channel => bail out 64 | function (error) { 65 | console.log("Failed to start buyer:", error); 66 | location.reload(true); 67 | } 68 | ); 69 | }; 70 | 71 | 72 | // open WAMP session 73 | connection.open(); 74 | -------------------------------------------------------------------------------- /packages/autobahn-xbr/test/client/browser/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

XBR Browser Buyer + Seller Examples

5 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /packages/autobahn-xbr/test/client/browser/seller.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |

XBR Seller Example

9 |

Open JavaScript console to watch output.

10 | 11 | 12 | -------------------------------------------------------------------------------- /packages/autobahn-xbr/test/client/browser/seller.js: -------------------------------------------------------------------------------- 1 | const xbr = autobahnXbr; 2 | 3 | 4 | console.log('Running Autobahn ' + autobahn.version); 5 | console.log('Running Autobahn-XBR ' + xbr.version); 6 | 7 | 8 | // WAMP connection 9 | var connection = new autobahn.Connection({ 10 | realm: "realm1", 11 | transports: [ 12 | { 13 | url: 'ws://localhost:8080/ws', 14 | type: 'websocket', 15 | serializers: [ new autobahn.serializer.MsgpackSerializer() ] 16 | } 17 | ] 18 | }); 19 | 20 | 21 | // callback fired upon new WAMP session 22 | connection.onopen = function (session, details) { 23 | 24 | console.log("WAMP session connected:", details); 25 | 26 | // ethereum private key of seller2 delegate1 27 | const seller2_delegate1_pkey = "0x0874049f95d55fb76916262dc70571701b5c4cc5900c0691af75f1a8a52c8268"; 28 | 29 | // market maker ethereum address 30 | const marketmaker_adr = "0x3E5e9111Ae8eB78Fe1CC3bb8915d5D461F3Ef9A9"; 31 | 32 | // the XBR token has 18 decimals 33 | const decimals = new xbr.BN('1000000000000000000'); 34 | 35 | // price in XBR per key 36 | const price = new xbr.BN(35).mul(decimals); 37 | 38 | // key rotation interval in seconds 39 | const key_rotation_interval = 10; 40 | 41 | // API ID of the interface of the offered service 42 | const api_id = xbr.uuid('bd65e220-aef7-43c0-a801-f8d95fa71f39'); 43 | 44 | // instantiate a simple seller 45 | var seller = new xbr.SimpleSeller(marketmaker_adr, seller2_delegate1_pkey); 46 | var counter = 1; 47 | 48 | seller.add(api_id, 'io.crossbar.example', price, key_rotation_interval); 49 | 50 | var do_publish = function() { 51 | const payload = {"data": "js-browser-seller", "counter": counter}; 52 | 53 | // encrypt the XBR payload, potentially automatically rotating & offering a new data encryption key 54 | let [key_id, enc_ser, ciphertext] = seller.wrap(api_id, 'io.crossbar.example', payload); 55 | 56 | const options = {acknowledge: true}; 57 | 58 | session.publish("io.crossbar.example", 59 | [key_id, enc_ser, ciphertext], 60 | {}, 61 | options).then( 62 | function (pub) { 63 | console.log("Published event " + pub.id); 64 | }, 65 | function (err) { 66 | console.log("Failed to publish event", err); 67 | } 68 | ); 69 | 70 | counter += 1; 71 | setTimeout(do_publish, 1000); 72 | }; 73 | 74 | // start selling 75 | seller.start(session).then( 76 | // success: we've got an active paying channel with remaining balance .. 77 | function (balance) { 78 | console.log("Seller has started, remaining balance in active paying channel is " + balance.div(decimals) + " XBR"); 79 | do_publish(); 80 | }, 81 | // we don't have an active paying channel => bail out 82 | function (error) { 83 | console.log("Failed to start seller:", error); 84 | process.exit(1); 85 | } 86 | ); 87 | }; 88 | 89 | 90 | // open WAMP session 91 | connection.open(); 92 | -------------------------------------------------------------------------------- /packages/autobahn-xbr/test/client/nodejs/.dockerignore: -------------------------------------------------------------------------------- 1 | Dockerfile 2 | .dockerignore 3 | node_modules 4 | -------------------------------------------------------------------------------- /packages/autobahn-xbr/test/client/nodejs/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:11-stretch 2 | 3 | WORKDIR /opt/xbr-example 4 | ADD package.json . 5 | RUN npm install 6 | ADD . . 7 | 8 | ENTRYPOINT /bin/bash 9 | -------------------------------------------------------------------------------- /packages/autobahn-xbr/test/client/nodejs/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: deps seller buyer 2 | 3 | all: 4 | @echo "Targets:" 5 | @echo "" 6 | @echo " clean Clean everything" 7 | @echo " install Install runtime dependencies" 8 | @echo " seller Run the XBR seller component" 9 | @echo " buyer Run the XBR buyer component" 10 | @echo "" 11 | 12 | clean: 13 | -rm -rf ./node_modules 14 | -rm ./package-lock.json 15 | 16 | seller: 17 | node seller.js 18 | 19 | buyer: 20 | node buyer.js 21 | 22 | install: 23 | npm install 24 | 25 | install_local: 26 | npm install ~/scm/crossbario/autobahn-js/packages/autobahn 27 | npm install ~/scm/crossbario/autobahn-js/packages/autobahn-xbr 28 | -------------------------------------------------------------------------------- /packages/autobahn-xbr/test/client/nodejs/buyer.js: -------------------------------------------------------------------------------- 1 | const autobahn = require('autobahn'); 2 | const xbr = require('autobahn-xbr'); 3 | const ethAccounts = require("web3-eth-accounts"); 4 | const ethSigUtils = require("eth-sig-util"); 5 | const ethUtil = require("ethereumjs-util"); 6 | 7 | console.log('Running on Autobahn ' + autobahn.version); 8 | console.log('Running Autobahn-XBR ' + xbr.version); 9 | 10 | const url = process.env.XBR_INSTANCE || "ws://localhost:8070/ws"; 11 | const realm = process.env.XBR_REALM || "idma"; 12 | const delegateEthKey = process.env.XBR_SELLER_DELEGATE_PRIVKEY || "77c5495fbb039eed474fc940f29955ed0531693cc9212911efd35dff0373153f"; 13 | const memberEthKey = process.env.XBR_SELLER_PRIVKEY || "2e114163041d2fb8d45f9251db259a68ee6bdbfd6d10fe1ae87c5c4bcd6ba491"; 14 | const cskey = process.env.XBR_SELLER_CS_KEY || "dc88492fcff5470fcc76f21fa03f1752e0738e1e5cd56cd61fc280bac4d4c4d9"; 15 | 16 | const wallet = new ethAccounts().privateKeyToAccount(memberEthKey); 17 | const seed = autobahn.util.htob(cskey); 18 | const keyPair = autobahn.nacl.sign.keyPair.fromSeed(seed); 19 | 20 | const pubKey = xbr.with_0x(autobahn.util.btoh(keyPair.publicKey)); 21 | const data = xbr.create_market_member_login(wallet.address, pubKey); 22 | const signature = ethSigUtils.signTypedData(ethUtil.toBuffer(xbr.with_0x(memberEthKey)), {data: data}) 23 | 24 | 25 | // WAMP connection 26 | // WAMP connection 27 | let connection = new autobahn.Connection({ 28 | url: url, 29 | authid: 'public', 30 | realm: realm, 31 | authextra: { 32 | pubkey: keyPair.publicKey, 33 | wallet_address: ethUtil.toBuffer(wallet.address), 34 | signature: ethUtil.toBuffer(signature) 35 | }, 36 | pkey: keyPair, 37 | authmethods: ['cryptosign'], 38 | onchallenge: (session, method, extra) => { 39 | // we only know how to process WAMP-cryptosign here! 40 | if (method === "cryptosign") { 41 | return autobahn.auth_cryptosign.sign_challenge(keyPair, extra); 42 | } else { 43 | throw "don't know how to authenticate using '" + method + "'"; 44 | } 45 | }, 46 | serializers: [new autobahn.serializer.MsgpackSerializer()] 47 | }); 48 | 49 | 50 | // callback fired upon new WAMP session 51 | connection.onopen = async function (session, details) { 52 | 53 | console.log("WAMP session connected:", details); 54 | 55 | // market maker ethereum address 56 | let config = await session.call('xbr.marketmaker.get_config'); 57 | let marketmaker_adr = config['marketmaker']; 58 | 59 | // the XBR token has 18 decimals 60 | const decimals = new xbr.BN('1000000000000000000'); 61 | 62 | // maximum price we are willing to pay per (single) key: 100 XBR 63 | const max_price = new xbr.BN('100').mul(decimals); 64 | 65 | // instantiate a simple buyer 66 | let buyer = new xbr.SimpleBuyer(marketmaker_adr, delegateEthKey, max_price); 67 | 68 | // start buying .. 69 | buyer.start(session).then( 70 | // success: we've got an active payment channel with remaining balance .. 71 | function (balance) { 72 | console.log("Buyer has started, remaining balance in active payment channel is " + balance.div(decimals) + " XBR"); 73 | 74 | session.subscribe("xbr.myapp.example", function (args, kwargs, details) { 75 | let [key_id, enc_ser, ciphertext] = args; 76 | 77 | // decrypt the XBR payload, potentially automatically buying a new data encryption key 78 | buyer.unwrap(key_id, enc_ser, ciphertext).then( 79 | function (payload) { 80 | console.log("Received event " + details.publication, payload) 81 | }, 82 | function (failure) { 83 | console.log(failure); 84 | process.exit(1); 85 | } 86 | ) 87 | }); 88 | 89 | }, 90 | // we don't have an active payment channel => bail out 91 | function (error) { 92 | console.log("Failed to start buyer:", error); 93 | process.exit(1); 94 | } 95 | ); 96 | }; 97 | 98 | 99 | // open WAMP session 100 | connection.open(); 101 | -------------------------------------------------------------------------------- /packages/autobahn-xbr/test/client/nodejs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "xbr-example", 3 | "version": "1.0.0", 4 | "description": "Install dependencies using ```bash make deps ``` To start the seller run ```bash make seller ``` For buyer ```bash make buyer ```", 5 | "main": "seller.js", 6 | "dependencies": { 7 | "autobahn": "^20.9.1", 8 | "autobahn-xbr": "^20.9.1", 9 | "cbor": "^4.3.0", 10 | "eth-sig-util": "^2.5.3", 11 | "ethereumjs-util": "^6.1.0", 12 | "uuid-buffer": "^1.0.3", 13 | "web3": "^1.2.1", 14 | "web3-eth-accounts": "^1.2.11", 15 | "web3-utils": "^1.2.11", 16 | "when": "^3.7.8", 17 | "ws": "^7.1.2" 18 | }, 19 | "devDependencies": {}, 20 | "scripts": { 21 | "test": "echo \"Error: no test specified\" && exit 1" 22 | }, 23 | "author": "", 24 | "license": "UNLICENSED" 25 | } 26 | -------------------------------------------------------------------------------- /packages/autobahn-xbr/test/eip712/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "eip712", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "sign-browser.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "web3": "^1.2.1" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /packages/autobahn-xbr/test/eip712/sign-browser.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 27 | 28 | 29 | 33 | 34 | 35 | 36 | 37 |

XBR Network: Typed Data Signing

38 |

Testing EIP712 .. open console.

39 | 40 |

Sign

41 |

42 | Sign the following data: 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 |
User ID
Address
Amount
57 | 58 | 59 |

60 | 61 | 62 | 63 |
64 | -------------------------------------------------------------------------------- /packages/autobahn-xbr/test/eip712/sign-cli.js: -------------------------------------------------------------------------------- 1 | // dicether/eip712 2 | // eth-sig-util 3 | // eth_sig_utils.signTypedData 4 | // eth_sig_utils.recoverTypedSignature 5 | // https://github.com/MetaMask/eth-sig-util#signtypeddata-privatekeybuffer-msgparams 6 | // https://github.com/MetaMask/eth-sig-util#signtypeddata-privatekeybuffer-msgparams 7 | 8 | var BigNumber = require('bignumber.js'); 9 | var w3_utils = require("web3-utils"); 10 | var eth_sig_utils = require("eth-sig-util"); 11 | var eth_accounts = require("web3-eth-accounts"); 12 | var eth_util = require("ethereumjs-util"); 13 | 14 | var buyer_key = "0x" + "a4985a2ed93107886e9a1f12c7b8e2e351cc1d26c42f3aab7f220f3a7d08fda6"; 15 | var buyer_key_bytes = w3_utils.hexToBytes(buyer_key); 16 | var account = new eth_accounts().privateKeyToAccount(buyer_key); 17 | var addr = eth_util.toBuffer(account.address); 18 | 19 | console.log("Using private key: " + buyer_key); 20 | //console.log(buyer_key_bytes); 21 | //console.log(account); 22 | console.log("Account canonical address: " + account.address); 23 | //console.log(addr); 24 | 25 | data = { 26 | 'types': { 27 | 'EIP712Domain': [ 28 | {'name': 'name', 'type': 'string'}, 29 | {'name': 'version', 'type': 'string'}, 30 | {'name': 'chainId', 'type': 'uint256'}, 31 | {'name': 'verifyingContract', 'type': 'address'}, 32 | ], 33 | 'Transaction': [ 34 | // The buyer/seller delegate Ed25519 public key. 35 | {'name': 'pubkey', 'type': 'uint256'}, 36 | 37 | // The UUID of the data encryption key bought/sold in the transaction. 38 | {'name': 'key_id', 'type': 'uint128'}, 39 | 40 | // Channel transaction sequence number. 41 | {'name': 'channel_seq', 'type': 'uint32'}, 42 | 43 | // Amount paid / earned. 44 | {'name': 'amount', 'type': 'uint256'}, 45 | 46 | // Amount remaining in the payment/paying channel after the transaction. 47 | {'name': 'balance', 'type': 'uint256'}, 48 | ], 49 | }, 50 | 'primaryType': 'Transaction', 51 | 'domain': { 52 | 'name': 'XBR', 53 | 'version': '1', 54 | 55 | // test chain/network ID 56 | 'chainId': 5777, 57 | 58 | // XBRNetwork contract address 59 | 'verifyingContract': '0x254dffcd3277c0b1660f6d42efbb754edababc2b', 60 | }, 61 | 'message': { 62 | 'pubkey': '0xebdfef6d225155873355bd4afeb2ed3100b0e0b5fddad12bd3cd498c1e0c1fbd', 63 | 'key_id': '0xc37ba03c32608744c3c06302bf81d174', 64 | 'channel_seq': 1, 65 | 'amount': new BigNumber('35000000000000000000'), 66 | 'balance': 2000, 67 | }, 68 | } 69 | 70 | //console.log(data); 71 | 72 | //var key = eth_util.toBuffer(buyer_key_bytes); 73 | var key = eth_util.toBuffer(buyer_key); 74 | 75 | // eth_util.toBuffer 76 | var sig = eth_sig_utils.signTypedData(key, {data: data}) 77 | console.log("Ok, signed typed data using " + account.address) 78 | console.log("SIGNATURE = " + sig); 79 | 80 | var signer = eth_sig_utils.recoverTypedSignature({data, sig}); 81 | signer = w3_utils.toChecksumAddress(signer); 82 | 83 | if (signer === account.address) { 84 | console.log("Ok, verified signature was signed by " + signer); 85 | } else { 86 | console.log("ERROR: signature verification failed"); 87 | } 88 | -------------------------------------------------------------------------------- /packages/autobahn-xbr/test/eip712/test_uint256.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var web3 = require('web3'); 3 | 4 | // https://web3js.readthedocs.io/en/v1.2.0/web3-utils.html#bn 5 | // https://github.com/indutny/bn.js/ 6 | var BN = web3.utils.BN; 7 | 8 | const nl = { 9 | '0': '0x0000000000000000000000000000000000000000000000000000000000000000', 10 | '1': '0x0000000000000000000000000000000000000000000000000000000000000001', 11 | '9007199254740992': '0x0000000000000000000000000000000000000000000000000020000000000000', 12 | '1000000000000000000': '0x0000000000000000000000000000000000000000000000000de0b6b3a7640000', 13 | '999000000000000000000': '0x00000000000000000000000000000000000000000000003627e8f712373c0000', 14 | '1000000000000000000000000000': '0x0000000000000000000000000000000000000000033b2e3c9fd0803ce8000000', 15 | '115792089237316195423570985008687907853269984665640564039457584007913129639935': '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16 | } 17 | 18 | for (const [key, value] of Object.entries(nl)) { 19 | console.log(value, key); 20 | 21 | const n = new BN(key); 22 | const x = n.toBuffer('big', 32); 23 | assert.equal('0x' + x.toString('hex'), value); 24 | 25 | const n2 = new BN(x); 26 | assert.equal(n2.cmp(n), 0); 27 | } 28 | 29 | 30 | /* 31 | var BigNumber = require('bignumber.js'); 32 | var eth_util = require("ethereumjs-util"); 33 | 34 | var nr = new BigNumber('35000000000000000000'); 35 | 36 | console.log(nr); 37 | console.log(nr.toString()); 38 | console.log(nr.toString(16)); 39 | 40 | var nr2 = new BN('35000000000000000000'); 41 | 42 | console.log(nr2); 43 | 44 | console.log(web3.utils.toHex(nr2)); 45 | 46 | console.log(web3.utils.padLeft(web3.utils.toHex(nr2), 64)); 47 | 48 | console.log(eth_util.toBuffer(web3.utils.padLeft(web3.utils.toHex(nr2), 32))); 49 | 50 | console.log(nr2.toBuffer('big', 32)); 51 | */ -------------------------------------------------------------------------------- /packages/autobahn-xbr/test/onchain/Makefile: -------------------------------------------------------------------------------- 1 | run: 2 | twistd -n web --path . --port tcp:8050 3 | -------------------------------------------------------------------------------- /packages/autobahn-xbr/test/onchain/autobahn-xbr.js: -------------------------------------------------------------------------------- 1 | ../../../packages/autobahn-xbr/build/autobahn-xbr.js -------------------------------------------------------------------------------- /packages/autobahn/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) Crossbar.io Technologies GmbH and contributors. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | the Software, and to permit persons to whom the Software is furnished to do so, 8 | subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | -------------------------------------------------------------------------------- /packages/autobahn/SConstruct: -------------------------------------------------------------------------------- 1 | import os 2 | import json 3 | import pkg_resources 4 | import subprocess 5 | from sys import platform 6 | 7 | taschenmesser = pkg_resources.resource_filename('taschenmesser', '..') 8 | #taschenmesser = "../../infrequent/taschenmesser" 9 | ENV=os.environ 10 | 11 | if 'JAVA_HOME' in ENV: 12 | print('Using from environment: JAVA_HOME={}'.format(ENV['JAVA_HOME'])) 13 | elif platform == "darwin": 14 | ENV['JAVA_HOME'] = subprocess.check_output("/usr/libexec/java_home").strip() 15 | print('Using OSX default: JAVA_HOME={}'.format(ENV['JAVA_HOME'])) 16 | elif platform == "linux" or platform == "linux2": 17 | ENV['JAVA_HOME'] = subprocess.check_output("echo 'System.out.println(java.lang.System.getProperty(\"java.home\"));' | jshell -", shell=True).strip() 18 | print('Using Linux default: JAVA_HOME={}'.format(ENV['JAVA_HOME'])) 19 | 20 | if 'JS_COMPILER' in ENV: 21 | print('Using from environment: JS_COMPILER={}'.format(ENV['JS_COMPILER'])) 22 | else: 23 | #ENV['JS_COMPILER'] = '/usr/local/lib/node_modules/google-closure-compiler-java/compiler.jar' 24 | ENV['JS_COMPILER'] = str(Dir('.').abspath) + '/node_modules/google-closure-compiler-java/compiler.jar' 25 | print('Using builtin: JS_COMPILER={}'.format(ENV['JS_COMPILER'])) 26 | 27 | env = Environment(tools = ['default', 'taschenmesser'], 28 | toolpath = [taschenmesser], 29 | ENV = ENV) 30 | 31 | # Get package version 32 | version = json.load(open('package.json'))['version'] 33 | print("Building AutobahnJS {}".format(version)) 34 | 35 | env['JS_DEFINES'] = { 36 | # 'AUTOBAHNJS_VERSION': "'%s'" % version 37 | } 38 | 39 | # Source for Autobahn package 40 | sourcedir = 'lib' 41 | sources = [os.path.join(sourcedir, d) for d in os.listdir(sourcedir)] 42 | 43 | # browserified 44 | ab = env.Command("build/autobahn.js", 45 | "lib/autobahn.js", 46 | "./node_modules/browserify/bin/cmd.js $SOURCE --ignore-missing --standalone autobahn -o $TARGET") 47 | Depends(ab, sources) 48 | 49 | if True: 50 | # minimized (with Google Closure) 51 | ab_min = env.JavaScript("build/autobahn.min.js", 52 | ab, 53 | #JS_COMPILATION_LEVEL = "ADVANCED_OPTIMIZATIONS") 54 | JS_COMPILATION_LEVEL = "SIMPLE_OPTIMIZATIONS", 55 | JS_OUTPUT_LANG = "ECMASCRIPT_2018", 56 | JS_STRICT_MODE = "0") 57 | 58 | # minimized & compressed 59 | ab_min_gz = env.GZip("build/autobahn.min.jgz", 60 | ab_min) 61 | 62 | # list of generated artifacts 63 | artifacts = [ab, 64 | ab_min, 65 | ab_min_gz] 66 | else: 67 | artifacts = [ab] 68 | 69 | # generate checksum files 70 | checksums = [] 71 | checksums.append(env.MD5("build/CHECKSUM.MD5", artifacts)) 72 | checksums.append(env.SHA1("build/CHECKSUM.SHA1", artifacts)) 73 | checksums.append(env.SHA256("build/CHECKSUM.SHA256", artifacts)) 74 | 75 | # fixed static files to be included 76 | statics = [] 77 | for f in ["LICENSE"]: 78 | statics.append(Command("build/{}".format(f), [], Copy("$TARGET", f))) 79 | 80 | # The default target consists of all artifacts that 81 | # would get published 82 | uploads = artifacts + checksums + statics 83 | Default(uploads) 84 | #Default(ab) 85 | 86 | # Upload to Amazon S3 87 | env['S3_BUCKET'] = 'autobahn' 88 | env['S3_OBJECT_ACL'] = 'public-read' 89 | 90 | published = [] 91 | 92 | for s in ['latest', version]: 93 | e = env.Clone(S3_BUCKET_PREFIX = 'autobahnjs/{}/'.format(s)) # note the trailing slash! 94 | published.append(AlwaysBuild(e.S3("build/.S3UploadDone_{}".format(s), uploads))) 95 | 96 | 97 | # The uploaded stuff is always considered stale 98 | Depends(published, uploads) 99 | 100 | Alias("publish", published) 101 | -------------------------------------------------------------------------------- /packages/autobahn/index.js: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // AutobahnJS - http://autobahn.ws, http://wamp.ws 4 | // 5 | // A JavaScript library for WAMP ("The Web Application Messaging Protocol"). 6 | // 7 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 8 | // 9 | // Licensed under the MIT License. 10 | // http://www.opensource.org/licenses/mit-license.php 11 | // 12 | /////////////////////////////////////////////////////////////////////////////// 13 | 14 | module.exports = require('./lib/autobahn.js'); 15 | -------------------------------------------------------------------------------- /packages/autobahn/lib/auth/cra.js: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // AutobahnJS - http://autobahn.ws, http://wamp.ws 4 | // 5 | // A JavaScript library for WAMP ("The Web Application Messaging Protocol"). 6 | // 7 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 8 | // 9 | // Licensed under the MIT License. 10 | // http://www.opensource.org/licenses/mit-license.php 11 | // 12 | /////////////////////////////////////////////////////////////////////////////// 13 | 14 | // require('assert') would be nice .. but it does not 15 | // work with Google Closure after Browserify 16 | 17 | var crypto = require('crypto-js'); 18 | 19 | // PBKDF2-base key derivation function for salted WAMP-CRA 20 | // 21 | function derive_key (secret, salt, iterations, keylen) { 22 | var iterations = iterations || 1000; 23 | var keylen = keylen || 32; 24 | var config = { 25 | keySize: keylen / 4, 26 | iterations: iterations, 27 | hasher: crypto.algo.SHA256 28 | } 29 | var key = crypto.PBKDF2(secret, salt, config); 30 | return key.toString(crypto.enc.Base64); 31 | } 32 | 33 | 34 | function sign (key, challenge) { 35 | return crypto.HmacSHA256(challenge, key).toString(crypto.enc.Base64); 36 | } 37 | 38 | exports.sign = sign; 39 | exports.derive_key = derive_key; 40 | -------------------------------------------------------------------------------- /packages/autobahn/lib/auth/persona.js: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // AutobahnJS - http://autobahn.ws, http://wamp.ws 4 | // 5 | // A JavaScript library for WAMP ("The Web Application Messaging Protocol"). 6 | // 7 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 8 | // 9 | // Licensed under the MIT License. 10 | // http://www.opensource.org/licenses/mit-license.php 11 | // 12 | /////////////////////////////////////////////////////////////////////////////// 13 | 14 | function auth(session, user, extra) { 15 | 16 | // Persona Issues: 17 | // 18 | // Chrome: https://github.com/mozilla/persona/issues/4083 19 | // IE11: https://groups.google.com/forum/#!topic/mozilla.dev.identity/keEkVpvfLA8 20 | 21 | var d = session.defer(); 22 | 23 | navigator.id.watch({ 24 | loggedInUser: user, 25 | onlogin: function (assertion) { 26 | // A user has logged in! Here you need to: 27 | // 1. Send the assertion to your backend for verification and to create a session. 28 | // 2. Update your UI. 29 | d.resolve(assertion); 30 | }, 31 | onlogout: function() { 32 | // A user has logged out! Here you need to: 33 | // Tear down the user's session by redirecting the user or making a call to your backend. 34 | // Also, make sure loggedInUser will get set to null on the next page load. 35 | // (That's a literal JavaScript null. Not false, 0, or undefined. null.) 36 | session.leave("wamp.close.logout"); 37 | } 38 | }); 39 | 40 | if (d.promise.then) { 41 | // whenjs has the actual user promise in an attribute 42 | return d.promise; 43 | } else { 44 | return d; 45 | } 46 | } 47 | 48 | exports.auth = auth; 49 | -------------------------------------------------------------------------------- /packages/autobahn/lib/autobahn.js: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // AutobahnJS - http://autobahn.ws, http://wamp.ws 4 | // 5 | // A JavaScript library for WAMP ("The Web Application Messaging Protocol"). 6 | // 7 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 8 | // 9 | // Licensed under the MIT License. 10 | // http://www.opensource.org/licenses/mit-license.php 11 | // 12 | /////////////////////////////////////////////////////////////////////////////// 13 | 14 | // Polyfills for <= IE9 15 | require('./polyfill.js'); 16 | 17 | var pjson = require('../package.json'); 18 | 19 | let when; 20 | let HAS_WHEN; 21 | try { 22 | when = require('when'); 23 | HAS_WHEN = true; 24 | } catch (e) { 25 | HAS_WHEN = false; 26 | } 27 | 28 | var msgpack = require('msgpack5'); 29 | var cbor = require('cbor'); 30 | var nacl = require('tweetnacl'); 31 | 32 | if ('AUTOBAHN_DEBUG' in global && AUTOBAHN_DEBUG) { 33 | // https://github.com/cujojs/when/blob/master/docs/api.md#whenmonitor 34 | require('when/monitor/console'); 35 | if ('console' in global) { 36 | console.log("AutobahnJS debug enabled"); 37 | } 38 | } 39 | 40 | var util = require('./util.js'); 41 | var log = require('./log.js'); 42 | var session = require('./session.js'); 43 | var connection = require('./connection.js'); 44 | var configure = require('./configure.js'); 45 | var serializer = require('./serializer.js'); 46 | 47 | var persona = require('./auth/persona.js'); 48 | var cra = require('./auth/cra.js'); 49 | var cryptosign = require('./auth/cryptosign.js'); 50 | 51 | exports.version = pjson.version; 52 | 53 | exports.transports = configure.transports; 54 | 55 | exports.Connection = connection.Connection; 56 | 57 | exports.Session = session.Session; 58 | exports.Invocation = session.Invocation; 59 | exports.Event = session.Event; 60 | exports.Result = session.Result; 61 | exports.Error = session.Error; 62 | exports.Subscription = session.Subscription; 63 | exports.Registration = session.Registration; 64 | exports.Publication = session.Publication; 65 | 66 | exports.serializer = serializer; 67 | 68 | exports.auth_persona = persona.auth; 69 | exports.auth_cra = cra; 70 | exports.auth_cryptosign = cryptosign; 71 | 72 | if (HAS_WHEN) { 73 | exports.when = when; 74 | } 75 | exports.msgpack = msgpack; 76 | exports.cbor = cbor; 77 | exports.nacl = nacl; 78 | 79 | exports.util = util; 80 | exports.log = log; 81 | -------------------------------------------------------------------------------- /packages/autobahn/lib/configure.js: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // AutobahnJS - http://autobahn.ws, http://wamp.ws 4 | // 5 | // A JavaScript library for WAMP ("The Web Application Messaging Protocol"). 6 | // 7 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 8 | // 9 | // Licensed under the MIT License. 10 | // http://www.opensource.org/licenses/mit-license.php 11 | // 12 | /////////////////////////////////////////////////////////////////////////////// 13 | 14 | 15 | function Transports() { 16 | this._repository = {}; 17 | } 18 | 19 | 20 | Transports.prototype.register = function (name, factory) { 21 | this._repository[name] = factory; 22 | }; 23 | 24 | 25 | Transports.prototype.isRegistered = function (name) { 26 | return this._repository[name] ? true : false; 27 | }; 28 | 29 | 30 | Transports.prototype.get = function (name) { 31 | if (this._repository[name] !== undefined) { 32 | return this._repository[name]; 33 | } else { 34 | throw "no such transport: " + name; 35 | } 36 | } 37 | 38 | 39 | Transports.prototype.list = function() { 40 | var items = []; 41 | for (var name in this._repository) { 42 | items.push(name); 43 | } 44 | return items; 45 | }; 46 | 47 | 48 | var _transports = new Transports(); 49 | 50 | 51 | // register default transports 52 | var websocket = require('./transport/websocket.js'); 53 | _transports.register("websocket", websocket.Factory); 54 | 55 | var longpoll = require('./transport/longpoll.js'); 56 | _transports.register("longpoll", longpoll.Factory); 57 | 58 | var rawsocket = require('./transport/rawsocket.js'); 59 | _transports.register("rawsocket", rawsocket.Factory); 60 | 61 | exports.transports = _transports; 62 | -------------------------------------------------------------------------------- /packages/autobahn/lib/log.js: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // AutobahnJS - http://autobahn.ws, http://wamp.ws 4 | // 5 | // A JavaScript library for WAMP ("The Web Application Messaging Protocol"). 6 | // 7 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 8 | // 9 | // Licensed under the MIT License. 10 | // http://www.opensource.org/licenses/mit-license.php 11 | // 12 | /////////////////////////////////////////////////////////////////////////////// 13 | 14 | 15 | // use empty debug() function as default 16 | let debug = function () {}; 17 | 18 | // log debug messages to console if AUTOBAHN_DEBUG is in globals or set as environment variable - works in browser and NodeJS 19 | if ('console' in global) { 20 | if (('AUTOBAHN_DEBUG' in global && AUTOBAHN_DEBUG) || ('process' in global && process.env.AUTOBAHN_DEBUG)) { 21 | debug = function () { 22 | // console.log.apply(console, arguments); 23 | 24 | // If you want to send an arguments list you need to use call: 25 | // https://stackoverflow.com/a/41354496/884770 26 | console.log.call(console, JSON.stringify(arguments[0], null, ' ')); 27 | } 28 | } 29 | } 30 | 31 | console.log('Sdfsdf'); 32 | 33 | // write debug messages to tracefile if AUTOBAHN_TRACE is set as environment variable - only works on NodeJS 34 | if ('process' in global && process.env.AUTOBAHN_TRACE) { 35 | debug = function () { 36 | const fs = require("fs"); 37 | fs.appendFileSync(process.env.AUTOBAHN_TRACE, JSON.stringify(arguments[0], null, ' ') + '\n\n'); 38 | } 39 | } 40 | 41 | let warn = console.warn.bind(console); 42 | 43 | exports.debug = debug; 44 | exports.warn = warn; 45 | -------------------------------------------------------------------------------- /packages/autobahn/lib/polyfill.js: -------------------------------------------------------------------------------- 1 | require('./polyfill/object.js'); 2 | require('./polyfill/array.js'); 3 | require('./polyfill/string.js'); 4 | require('./polyfill/function.js'); 5 | require('./polyfill/console.js'); 6 | require('./polyfill/typedarray.js'); 7 | require('./polyfill/json.js'); 8 | -------------------------------------------------------------------------------- /packages/autobahn/lib/polyfill/array.js: -------------------------------------------------------------------------------- 1 | if ( 'function' !== typeof Array.prototype.reduce ) { 2 | Array.prototype.reduce = function( callback /*, initialValue*/ ) { 3 | 'use strict'; 4 | var len, t, value, k; 5 | if ( null === this || 'undefined' === typeof this ) { 6 | throw new TypeError( 7 | 'Array.prototype.reduce called on null or undefined' ); 8 | } 9 | if ( 'function' !== typeof callback ) { 10 | throw new TypeError( callback + ' is not a function' ); 11 | } 12 | t = Object( this ); 13 | len = t.length >>> 0; 14 | k = 0; 15 | if ( arguments.length >= 2 ) { 16 | value = arguments[1]; 17 | } else { 18 | while ( k < len && ! k in t ) k++; 19 | if ( k >= len ) 20 | throw new TypeError('Reduce of empty array with no initial value'); 21 | value = t[ k++ ]; 22 | } 23 | for ( ; k < len ; k++ ) { 24 | if ( k in t ) { 25 | value = callback( value, t[k], k, t ); 26 | } 27 | } 28 | return value; 29 | }; 30 | } 31 | 32 | // Add ECMA262-5 Array methods if not supported natively 33 | // 34 | if (!('indexOf' in Array.prototype)) { 35 | Array.prototype.indexOf= function(find, i /*opt*/) { 36 | if (i===undefined) i= 0; 37 | if (i<0) i+= this.length; 38 | if (i<0) i= 0; 39 | for (var n= this.length; ithis.length-1) i= this.length-1; 50 | for (i++; i-->0;) /* i++ because from-argument is sadly inclusive */ 51 | if (i in this && this[i]===find) 52 | return i; 53 | return -1; 54 | }; 55 | } 56 | if (!('forEach' in Array.prototype)) { 57 | Array.prototype.forEach= function(action, that /*opt*/) { 58 | for (var i= 0, n= this.length; i>> 0, k = len - 1, value; 109 | if ( arguments.length >= 2 ) { 110 | value = arguments[1]; 111 | } else { 112 | while ( k >= 0 && ! k in t ) k--; 113 | if ( k < 0 ) 114 | throw new TypeError('Reduce of empty array with no initial value'); 115 | value = t[ k-- ]; 116 | } 117 | for ( ; k >= 0 ; k-- ) { 118 | if ( k in t ) { 119 | value = callback( value, t[k], k, t ); 120 | } 121 | } 122 | return value; 123 | }; 124 | } -------------------------------------------------------------------------------- /packages/autobahn/lib/polyfill/console.js: -------------------------------------------------------------------------------- 1 | 2 | (function(console) { 3 | /********************************************************************************************* 4 | * Make sure console exists because IE blows up if it's not open and you attempt to access it 5 | * Create some dummy functions if we need to, so we don't have to if/else everything 6 | *********************************************************************************************/ 7 | console||(console = window.console = { 8 | // all this "a, b, c, d, e" garbage is to make the IDEs happy, since they can't do variable argument lists 9 | /** 10 | * @param a 11 | * @param [b] 12 | * @param [c] 13 | * @param [d] 14 | * @param [e] 15 | */ 16 | log: function(a, b, c, d, e) {}, 17 | /** 18 | * @param a 19 | * @param [b] 20 | * @param [c] 21 | * @param [d] 22 | * @param [e] 23 | */ 24 | info: function(a, b, c, d, e) {}, 25 | /** 26 | * @param a 27 | * @param [b] 28 | * @param [c] 29 | * @param [d] 30 | * @param [e] 31 | */ 32 | warn: function(a, b, c, d, e) {}, 33 | /** 34 | * @param a 35 | * @param [b] 36 | * @param [c] 37 | * @param [d] 38 | * @param [e] 39 | */ 40 | error: function(a, b, c, d, e) {}, 41 | 42 | assert: function(test, message) {} 43 | }); 44 | 45 | // IE 9 won't allow us to call console.log.apply (WTF IE!) It also reports typeof(console.log) as 'object' (UNH!) 46 | // but together, those two errors can be useful in allowing us to fix stuff so it works right 47 | if( typeof(console.log) === 'object' ) { 48 | // Array.forEach doesn't work in IE 8 so don't try that :( 49 | console.log = Function.prototype.call.bind(console.log, console); 50 | console.info = Function.prototype.call.bind(console.info, console); 51 | console.warn = Function.prototype.call.bind(console.warn, console); 52 | console.error = Function.prototype.call.bind(console.error, console); 53 | console.debug = Function.prototype.call.bind(console.info, console); 54 | } 55 | 56 | /** 57 | * Support group and groupEnd functions 58 | */ 59 | ('group' in console) || 60 | (console.group = function(msg) { 61 | console.info("\n--- "+msg+" ---\n"); 62 | }); 63 | ('groupEnd' in console) || 64 | (console.groupEnd = function() { 65 | console.log("\n"); 66 | }); 67 | ('assert' in console) || 68 | (console.assert = function(test, message) { 69 | if (!test) { 70 | try { 71 | // attempt to preserve the stack 72 | throw new Error("assertion failed: " + message); 73 | } catch(error) { 74 | setTimeout(function(){ 75 | throw error; 76 | }, 0); 77 | } 78 | } 79 | }); 80 | 81 | /** 82 | * Support time and timeEnd functions 83 | */ 84 | ('time' in console) || 85 | (function() { 86 | var trackedTimes = {}; 87 | console.time = function(msg) { 88 | trackedTimes[msg] = new Date().getTime(); 89 | }; 90 | console.timeEnd = function(msg) { 91 | var end = new Date().getTime(), time = (msg in trackedTimes)? end - trackedTimes[msg] : 0; 92 | console.info(msg+': '+time+'ms') 93 | }; 94 | }()); 95 | 96 | })(typeof console !== 'undefined' ? console : undefined); -------------------------------------------------------------------------------- /packages/autobahn/lib/polyfill/function.js: -------------------------------------------------------------------------------- 1 | if (!Function.prototype.bind) { 2 | //credits: taken from bind_even_never in this discussion: https://prototype.lighthouseapp.com/projects/8886/tickets/215-optimize-bind-bindaseventlistener#ticket-215-9 3 | Function.prototype.bind = function(context) { 4 | var fn = this, args = Array.prototype.slice.call(arguments, 1); 5 | return function(){ 6 | return fn.apply(context, Array.prototype.concat.apply(args, arguments)); 7 | }; 8 | }; 9 | } -------------------------------------------------------------------------------- /packages/autobahn/lib/polyfill/object.js: -------------------------------------------------------------------------------- 1 | if (!Object.create) { 2 | Object.create = (function(){ 3 | function F(){} 4 | 5 | return function(o){ 6 | if (arguments.length != 1) { 7 | throw new Error('Object.create implementation only accepts one parameter.'); 8 | } 9 | F.prototype = o; 10 | return new F() 11 | } 12 | })() 13 | } 14 | // From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys 15 | if (!Object.keys) { 16 | Object.keys = (function () { 17 | 'use strict'; 18 | var hasOwnProperty = Object.prototype.hasOwnProperty, 19 | hasDontEnumBug = !({toString: null}).propertyIsEnumerable('toString'), 20 | dontEnums = [ 21 | 'toString', 22 | 'toLocaleString', 23 | 'valueOf', 24 | 'hasOwnProperty', 25 | 'isPrototypeOf', 26 | 'propertyIsEnumerable', 27 | 'constructor' 28 | ], 29 | dontEnumsLength = dontEnums.length; 30 | 31 | return function (obj) { 32 | if (typeof obj !== 'object' && (typeof obj !== 'function' || obj === null)) { 33 | throw new TypeError('Object.keys called on non-object'); 34 | } 35 | 36 | var result = [], prop, i; 37 | 38 | for (prop in obj) { 39 | if (hasOwnProperty.call(obj, prop)) { 40 | result.push(prop); 41 | } 42 | } 43 | 44 | if (hasDontEnumBug) { 45 | for (i = 0; i < dontEnumsLength; i++) { 46 | if (hasOwnProperty.call(obj, dontEnums[i])) { 47 | result.push(dontEnums[i]); 48 | } 49 | } 50 | } 51 | return result; 52 | }; 53 | }()); 54 | } -------------------------------------------------------------------------------- /packages/autobahn/lib/polyfill/string.js: -------------------------------------------------------------------------------- 1 | // Add ECMA262-5 string trim if not supported natively 2 | // 3 | if (!('trim' in String.prototype)) { 4 | String.prototype.trim= function() { 5 | return this.replace(/^\s+/, '').replace(/\s+$/, ''); 6 | }; 7 | } -------------------------------------------------------------------------------- /packages/autobahn/lib/serializer.js: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // AutobahnJS - http://autobahn.ws, http://wamp.ws 4 | // 5 | // A JavaScript library for WAMP ("The Web Application Messaging Protocol"). 6 | // 7 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 8 | // 9 | // Licensed under the MIT License. 10 | // http://www.opensource.org/licenses/mit-license.php 11 | // 12 | /////////////////////////////////////////////////////////////////////////////// 13 | 14 | var log = require('./log.js'); 15 | 16 | 17 | function JSONSerializer(replacer, reviver) { 18 | this.replacer = replacer; 19 | this.reviver = reviver; 20 | this.SERIALIZER_ID = 'json'; 21 | this.BINARY = false; 22 | } 23 | 24 | JSONSerializer.prototype.serialize = function (obj) { 25 | try { 26 | var payload = JSON.stringify(obj, this.replacer); 27 | return payload; 28 | } catch (e) { 29 | log.warn('JSON encoding error', e); 30 | throw e; 31 | } 32 | }; 33 | 34 | JSONSerializer.prototype.unserialize = function (payload) { 35 | try { 36 | var obj = JSON.parse(payload, this.reviver); 37 | return obj; 38 | } catch (e) { 39 | log.warn('JSON decoding error', e); 40 | throw e; 41 | } 42 | }; 43 | 44 | exports.JSONSerializer = JSONSerializer; 45 | 46 | 47 | try { 48 | // https://github.com/mcollina/msgpack5 49 | var msgpack = require('msgpack5')({forceFloat64: true}); 50 | 51 | function MsgpackSerializer() { 52 | this.SERIALIZER_ID = 'msgpack'; 53 | this.BINARY = true; 54 | } 55 | 56 | MsgpackSerializer.prototype.serialize = function (obj) { 57 | try { 58 | var payload = msgpack.encode(obj); 59 | return payload; 60 | } catch (e) { 61 | log.warn('MessagePack encoding error', e); 62 | throw e; 63 | } 64 | }; 65 | 66 | MsgpackSerializer.prototype.unserialize = function (payload) { 67 | try { 68 | var obj = msgpack.decode(payload); 69 | return obj; 70 | } catch (e) { 71 | log.warn('MessagePack decoding error', e); 72 | throw e; 73 | } 74 | }; 75 | 76 | exports.MsgpackSerializer = MsgpackSerializer; 77 | } catch (e) { 78 | log.warn('msgpack serializer not available', e); 79 | } 80 | 81 | 82 | try { 83 | // http://hildjj.github.io/node-cbor/ 84 | var cbor = require('cbor'); 85 | 86 | function CBORSerializer() { 87 | this.SERIALIZER_ID = 'cbor'; 88 | this.BINARY = true; 89 | } 90 | 91 | CBORSerializer.prototype.serialize = async function (obj) { 92 | try { 93 | var payload = await cbor.encodeAsync(obj); 94 | return payload; 95 | } catch (e) { 96 | log.warn('CBOR encoding error', e); 97 | throw e; 98 | } 99 | }; 100 | 101 | CBORSerializer.prototype.unserialize = function (payload) { 102 | try { 103 | //var obj = cbor.decodeAllSync(payload)[0]; 104 | var obj = cbor.decodeFirstSync(payload); 105 | return obj; 106 | } catch (e) { 107 | log.warn('CBOR decoding error', e); 108 | throw e; 109 | } 110 | }; 111 | 112 | exports.CBORSerializer = CBORSerializer; 113 | } catch (e) { 114 | log.warn('cbor serializer not available', e); 115 | } 116 | -------------------------------------------------------------------------------- /packages/autobahn/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "autobahn", 3 | "version": "22.11.1", 4 | "description": "An implementation of The Web Application Messaging Protocol (WAMP).", 5 | "main": "index.js", 6 | "files": [ 7 | "index.js", 8 | "/lib" 9 | ], 10 | "scripts": { 11 | "test": "nodeunit test/test.js" 12 | }, 13 | "engines": { 14 | "node": ">= 7.10.1" 15 | }, 16 | "dependencies": { 17 | "cbor": ">= 3.0.0", 18 | "crypto-js": ">=3.1.8", 19 | "msgpack5": ">= 3.6.0", 20 | "tweetnacl": ">= 0.14.3", 21 | "ws": "1.1.4 - 7" 22 | }, 23 | "optionalDependencies": { 24 | "bufferutil": ">= 1.2.1", 25 | "utf-8-validate": ">= 1.2.1", 26 | "when": ">= 3.7.7" 27 | }, 28 | "devDependencies": { 29 | "browserify": ">= 13.1.1", 30 | "deep-equal": ">= 1.0.1", 31 | "google-closure-compiler": ">= 20170218.0.0", 32 | "nodeunit": ">= 0.11.3", 33 | "random-bytes-seed": ">=1.0.3" 34 | }, 35 | "browser": { 36 | "ws": false, 37 | "./lib/transport/rawsocket.js": false 38 | }, 39 | "repository": { 40 | "type": "git", 41 | "url": "git://github.com/crossbario/autobahn-js.git" 42 | }, 43 | "keywords": [ 44 | "WAMP", 45 | "WebSocket", 46 | "RPC", 47 | "PubSub", 48 | "ethereum", 49 | "solidity", 50 | "xbr", 51 | "crossbar", 52 | "autobahn", 53 | "wamp", 54 | "data-service", 55 | "data-monetization" 56 | ], 57 | "author": "Crossbar.io Technologies GmbH", 58 | "license": "MIT" 59 | } 60 | -------------------------------------------------------------------------------- /packages/autobahn/test/README.md: -------------------------------------------------------------------------------- 1 | # Tests for AutobahnJS functionality 2 | 3 | Tests run using NodeJS and the nodeunit package. 4 | 5 | First, ensure that a Crossbar.io instance is running with the default configuration (use `crossbar init` if needed). This will run a WAMP-over-WebSocket transport at `ws://localhost:8080/ws`. 6 | 7 | > You should be able to use any compliant WAMP router (on `ws://localhost:8080/ws`) - your mileage may vary though. 8 | 9 | Then, open a terminal and run `npm test` in the `package` directory. 10 | 11 | ## First run 12 | 13 | * You need to have NodeJS installed. 14 | * Run `npm install` in the `package directory` 15 | 16 | If all assertions fail, this may be because of different line ending formats for the created test_*.txt files. 17 | In this case you need to remove the files and create a known good set of files on your system! 18 | 19 | Here is a successful testrun: 20 | 21 | ```console 22 | oberstet@thinkpad-t430s:~/scm/autobahn/AutobahnJS/package$ npm test 23 | 24 | > autobahn@0.9.7 test /home/oberstet/scm/autobahn/AutobahnJS/package 25 | > nodeunit test/test.js 26 | 27 | 28 | test.js 29 | ✔ testConnect 30 | ✔ testRpcArguments 31 | ✔ testRpcComplex 32 | ✔ testRpcError 33 | ✔ testRpcOptions 34 | ✔ testRpcProgress 35 | ✔ testRpcSlowsquare 36 | ✔ testRpcRouting 37 | ✔ testRpcCallerDiscloseMe 38 | ✔ testPubsubBasic 39 | ✔ testPubsubComplex 40 | ✔ testPubsubOptions 41 | ✔ testPubsubExcludeMe 42 | ✔ testPubsubExclude 43 | ✔ testPubsubPrefixSub 44 | ✔ testPubsubWildcardSub 45 | ✔ testPubsubPublisherDiscloseMe 46 | 47 | OK: 25 assertions (9444ms) 48 | ``` 49 | -------------------------------------------------------------------------------- /packages/autobahn/test/test.js: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // AutobahnJS - http://autobahn.ws, http://wamp.ws 4 | // 5 | // A JavaScript library for WAMP ("The Web Application Messaging Protocol"). 6 | // 7 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 8 | // 9 | // Licensed under the MIT License. 10 | // http://www.opensource.org/licenses/mit-license.php 11 | // 12 | /////////////////////////////////////////////////////////////////////////////// 13 | 14 | // this works via https://github.com/caolan/nodeunit 15 | 16 | var sync = require('./test_basic_sync.js'); 17 | var async = require('./test_basic_async.js'); 18 | 19 | var connect = require('./test_connect.js'); 20 | 21 | var serialization_json = require('./test_serialization_json.js'); 22 | var serialization_msgpack = require('./test_serialization_msgpack.js'); 23 | var serialization_cbor = require('./test_serialization_cbor.js'); 24 | 25 | var binary = require('./test_binary.js'); 26 | 27 | var rawsocket_transport = require('./test_rawsocket_transport.js'); 28 | 29 | var rpc_complex = require('./test_rpc_complex.js'); 30 | var rpc_arguments = require('./test_rpc_arguments.js'); 31 | var rpc_error = require('./test_rpc_error.js'); 32 | var rpc_options = require('./test_rpc_options.js'); 33 | var rpc_progress = require('./test_rpc_progress.js'); 34 | var rpc_slowsquare = require('./test_rpc_slowsquare.js'); 35 | var rpc_routing = require('./test_rpc_routing.js'); 36 | var rpc_request_id_sequence = require('./test_rpc_request_id_sequence.js'); 37 | 38 | var pubsub_basic = require('./test_pubsub_basic.js'); 39 | var pubsub_complex = require('./test_pubsub_complex.js'); 40 | // var pubsub_options = require('./test_pubsub_options.js'); 41 | var pubsub_excludme = require('./test_pubsub_excludeme.js'); 42 | var pubsub_exclude = require('./test_pubsub_exclude.js'); 43 | var pubsub_eligible = require('./test_pubsub_eligible.js'); 44 | var pubsub_prefix_sub = require('./test_pubsub_prefix_sub.js'); 45 | var pubsub_wildcard_sub = require('./test_pubsub_wildcard_sub.js'); 46 | // var pubsub_multiple_matching_subs = require('./test_pubsub_multiple_matching_subs.js'); 47 | var sealedbox = require('./test_sealedbox.js'); 48 | var util_is_object = require('./test_util_is_object'); 49 | 50 | exports.testUtilIsObjectSucceed = util_is_object.utilIsObjectSucceed; 51 | exports.testUtilIsObjectFail = util_is_object.utilIsObjectFail; 52 | exports.testUtilIsObjectVmFail = util_is_object.utilIsObjectVmFail; 53 | exports.testUtilIsObjectVmSucceed = util_is_object.utilIsObjectVmSucceed; 54 | 55 | exports.testSync = sync.testSync; 56 | exports.testAsync = async.testAsync; 57 | 58 | exports.testConnect = connect.testConnect; 59 | 60 | exports.testJSONSerialization = serialization_json.testJSONSerialization; 61 | exports.testMsgpackSerialization = serialization_msgpack.testMsgpackSerialization; 62 | exports.testCBORSerialization = serialization_cbor.testCBORSerialization; 63 | exports.testCBORLargePayload = serialization_cbor.testCBORLargePayload; 64 | 65 | exports.testBinaryCBOR = binary.testBinaryCBOR; 66 | // exports.testBinaryMsgPack = binary.testBinaryMsgPack; 67 | // exports.testBinaryJSON = binary.testBinaryJSON; 68 | 69 | exports.testRawSocketTransport = rawsocket_transport.testRawSocketTransport; 70 | 71 | exports.testRpcArguments = rpc_arguments.testRpcArguments; 72 | exports.testRpcComplex = rpc_complex.testRpcComplex; 73 | exports.testRpcError = rpc_error.testRpcError; 74 | exports.testRpcOptions = rpc_options.testRpcOptions; 75 | exports.testRpcProgress = rpc_progress.testRpcProgress; 76 | exports.testRpcSlowsquare = rpc_slowsquare.testRpcSlowsquare; 77 | exports.testRpcRouting = rpc_routing.testRpcRouting; 78 | exports.testRpcRequestIdSequence = rpc_request_id_sequence.testRpcRequestIdSequence; 79 | 80 | exports.testPubsubBasic = pubsub_basic.testPubsubBasic; 81 | exports.testPubsubComplex = pubsub_complex.testPubsubComplex; 82 | // exports.testPubsubOptions = pubsub_options.testPubsubOptions; 83 | exports.testPubsubExcludeMe = pubsub_excludme.testPubsubExcludeMe; 84 | exports.testPubsubExclude = pubsub_exclude.testPubsubExclude; 85 | exports.testPubsubEligible = pubsub_eligible.testPubsubEligible; 86 | exports.testPubsubPrefixSub = pubsub_prefix_sub.testPubsubPrefixSub; 87 | exports.testPubsubWildcardSub = pubsub_wildcard_sub.testPubsubWildcardSub; 88 | // exports.testPubsubMultipleMatchingSubs = pubsub_multiple_matching_subs.testPubsubMultipleMatchingSubs; 89 | // exports.testSealedBoxSealUnseal = sealedbox; 90 | 91 | exports.errorHandlingOnOpen = require('./test_error_handling').errorHandlingOnOpen; 92 | exports.errorHandlingOnClose = require('./test_error_handling').errorHandlingOnClose; 93 | exports.errorHandlingOnEvent = require('./test_error_handling').errorHandlingOnEvent; 94 | exports.errorHandlingOnInvocation = require('./test_error_handling').errorHandlingOnInvocation; 95 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_basic_async.js: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // AutobahnJS - http://autobahn.ws, http://wamp.ws 4 | // 5 | // A JavaScript library for WAMP ("The Web Application Messaging Protocol"). 6 | // 7 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 8 | // 9 | // Licensed under the MIT License. 10 | // http://www.opensource.org/licenses/mit-license.php 11 | // 12 | /////////////////////////////////////////////////////////////////////////////// 13 | 14 | var autobahn = require('../index.js'); 15 | var testutil = require('./testutil.js'); 16 | 17 | exports.testAsync = function (testcase) { 18 | 19 | testcase.expect(1); 20 | 21 | var test = new testutil.Testlog("test/test_basic_async.txt"); 22 | 23 | var d1 = autobahn.when.defer(); 24 | var d2 = autobahn.when.defer(); 25 | 26 | var df = autobahn.when.all([d1.promise, d2.promise]).then( 27 | function (res) { 28 | test.log(res); 29 | var chk = test.check(); 30 | testcase.ok(!chk, chk); 31 | testcase.done(); 32 | }, 33 | function (err) { 34 | test.log(err); 35 | testcase.done(); 36 | } 37 | ); 38 | 39 | d1.resolve(23); 40 | d2.resolve(42); 41 | } 42 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_basic_async.txt: -------------------------------------------------------------------------------- 1 | 0 [23,42] 2 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_basic_sync.js: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // AutobahnJS - http://autobahn.ws, http://wamp.ws 4 | // 5 | // A JavaScript library for WAMP ("The Web Application Messaging Protocol"). 6 | // 7 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 8 | // 9 | // Licensed under the MIT License. 10 | // http://www.opensource.org/licenses/mit-license.php 11 | // 12 | /////////////////////////////////////////////////////////////////////////////// 13 | 14 | var autobahn = require('../index.js'); 15 | var testutil = require('./testutil.js'); 16 | 17 | exports.testSync = function (testcase) { 18 | 19 | testcase.expect(1); 20 | 21 | var test = new testutil.Testlog("test/test_basic_sync.txt"); 22 | 23 | test.log(true); 24 | var chk = test.check(); 25 | testcase.ok(!chk, chk); 26 | testcase.done(); 27 | } 28 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_basic_sync.txt: -------------------------------------------------------------------------------- 1 | 0 true 2 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_binary_cbor.txt: -------------------------------------------------------------------------------- 1 | 0 "Connected: wamp.2.cbor" 2 | 1 "All registered." 3 | 2 "Serializer ID: cbor" 4 | 3 "Result [com.myapp.echo]: 1.7" 5 | 4 "Result [com.myapp.echo]: hello" 6 | 5 "Result [com.myapp.echo]: 1,2,-3" 7 | 6 "Result [com.myapp.echo]:" 8 | 7 " a, 5" 9 | 8 " b, hello2" 10 | 9 " c, 1,2,3" 11 | 10 "Result [com.myapp.echo]: -9007199254740991,9007199254740991" 12 | 11 "Result [com.myapp.echo]: null" 13 | 12 "Result [com.myapp.echo]: 1558266424841951553" 14 | 13 "Result [com.myapp.echo]: 340282366920938463463374607431768211455" 15 | 14 "Result [com.myapp.echo]: 0,1,2,3,4,5,6,7" 16 | 15 "Result [com.myapp.echo]: 8f44d509e0492acec4fc109a030a5c751f063fb743cc388f0ed722bacc3bc66c" 17 | 16 "Result [com.myapp.echo]:" 18 | 17 " a, 5" 19 | 18 " b, hello2" 20 | 19 " c, 035e7711c8da2e9434aab5039dc3d72046dee4e57af0e957e948fbbad15e48f8" 21 | 20 "Result [any.echo]: 1.7" 22 | 21 "Result [any.echo]: hello" 23 | 22 "Result [any.echo]: 1,2,-3" 24 | 23 "Result [any.echo]:" 25 | 24 " a, 5" 26 | 25 " b, hello2" 27 | 26 " c, 1,2,3" 28 | 27 "Result [any.echo]: -9007199254740991,9007199254740991" 29 | 28 "Result [any.echo]: null" 30 | 29 "Result [any.echo]: 1558266424841951553" 31 | 30 "Result [any.echo]: 340282366920938463463374607431768211455" 32 | 31 "Result [any.echo]: 0,1,2,3,4,5,6,7" 33 | 32 "Result [any.echo]: 8f44d509e0492acec4fc109a030a5c751f063fb743cc388f0ed722bacc3bc66c" 34 | 33 "Result [any.echo]:" 35 | 34 " a, 5" 36 | 35 " b, hello2" 37 | 36 " c, 035e7711c8da2e9434aab5039dc3d72046dee4e57af0e957e948fbbad15e48f8" 38 | 37 "All finished." 39 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_connect.js: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // AutobahnJS - http://autobahn.ws, http://wamp.ws 4 | // 5 | // A JavaScript library for WAMP ("The Web Application Messaging Protocol"). 6 | // 7 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 8 | // 9 | // Licensed under the MIT License. 10 | // http://www.opensource.org/licenses/mit-license.php 11 | // 12 | /////////////////////////////////////////////////////////////////////////////// 13 | 14 | var autobahn = require('../index.js'); 15 | var testutil = require('./testutil.js'); 16 | 17 | process.on('warning', e => console.warn(e.stack)); 18 | 19 | exports.testConnect = function (testcase) { 20 | 21 | testcase.expect(1); 22 | 23 | var test = new testutil.Testlog("test/test_connect.txt", true); 24 | var N = 10; 25 | 26 | test.log("connecting " + N + " sessions ..."); 27 | 28 | var dl = testutil.connect_n(N); 29 | 30 | autobahn.when.all(dl).then( 31 | function (res) { 32 | test.log("all " + res.length + " sessions connected"); 33 | 34 | for (var i = 0; i < res.length; ++i) { 35 | test.log("leaving session " + i); 36 | res[i].leave(); 37 | } 38 | 39 | var chk = test.check(); 40 | testcase.ok(!chk, chk); 41 | testcase.done(); 42 | }, 43 | function (err) { 44 | test.log(err); 45 | testcase.done(); 46 | } 47 | ); 48 | } 49 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_connect.txt: -------------------------------------------------------------------------------- 1 | 0 "connecting 10 sessions ..." 2 | 1 "all 10 sessions connected" 3 | 2 "leaving session 0" 4 | 3 "leaving session 1" 5 | 4 "leaving session 2" 6 | 5 "leaving session 3" 7 | 6 "leaving session 4" 8 | 7 "leaving session 5" 9 | 8 "leaving session 6" 10 | 9 "leaving session 7" 11 | 10 "leaving session 8" 12 | 11 "leaving session 9" 13 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_error_handling_on_colse.txt: -------------------------------------------------------------------------------- 1 | 0 "Step 1: open a connection" 2 | 1 "Step 2: the onopen handler is called." 3 | 2 "Step 3: close the connection." 4 | 3 "Step 4: the onclose handler is called" 5 | 4 "Step 5: the handler has a user error" 6 | 5 "Step 6: The error handler is called." 7 | 6 "Step 7: finishing the test case." 8 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_error_handling_on_event.txt: -------------------------------------------------------------------------------- 1 | 0 "Step 1: make two connections" 2 | 1 "Step 2: subscribe to a topic" 3 | 2 "step 3: publish to a topic" 4 | 3 "Step 4: the event handler is called" 5 | 4 "Step 5: an error thrown in the event handler" 6 | 5 "Step 6: the on user error is called" 7 | 6 "Step 7: finishing the test cases" 8 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_error_handling_on_invocation.txt: -------------------------------------------------------------------------------- 1 | 0 "Step 1: Create two sessions." 2 | 1 "Step 2: Register an invocation handler in the callee role." 3 | 2 "Step 3: Call the topic in the caller role." 4 | 3 "Step 4: The invocation handler is called." 5 | 4 "Step 5: An is error occurred in the handler." 6 | 5 "Step 7: The error handler is called" 7 | 6 "Step 8: The error is received on the callee side." 8 | 7 "Step 9: Finish the test case." 9 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_error_handling_on_open.txt: -------------------------------------------------------------------------------- 1 | 0 "Step 1: open a connection." 2 | 1 "Step 2: The onopen handler is called." 3 | 2 "Step 3: A user error is occurred in the handler." 4 | 3 "Step 4: The user error handler is called" 5 | 4 "Step 5: Finish the test case" 6 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_pubsub_basic.js: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // AutobahnJS - http://autobahn.ws, http://wamp.ws 4 | // 5 | // A JavaScript library for WAMP ("The Web Application Messaging Protocol"). 6 | // 7 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 8 | // 9 | // Licensed under the MIT License. 10 | // http://www.opensource.org/licenses/mit-license.php 11 | // 12 | /////////////////////////////////////////////////////////////////////////////// 13 | 14 | var autobahn = require('../index.js'); 15 | var testutil = require('./testutil.js'); 16 | 17 | 18 | exports.testPubsubBasic = function (testcase) { 19 | 20 | testcase.expect(1); 21 | 22 | var test = new testutil.Testlog("test/test_pubsub_basic.txt", true); 23 | 24 | var dl = testutil.connect_n(2); 25 | 26 | autobahn.when.all(dl).then( 27 | function (res) { 28 | test.log("all sessions connected"); 29 | 30 | var session1 = res[0]; 31 | var session2 = res[1]; 32 | 33 | var counter = 0; 34 | 35 | var t1 = setInterval(function () { 36 | test.log("publishing to topic 'com.myapp.topic1': " + counter); 37 | session1.publish('com.myapp.topic1', [counter]); 38 | counter += 1; 39 | }, 100); 40 | 41 | var received = 0; 42 | 43 | var sub; 44 | function onevent1(args) { 45 | test.log("Got event:", args[0]); 46 | received += 1; 47 | if (received > 5) { 48 | test.log("Closing .."); 49 | 50 | clearInterval(t1); 51 | 52 | session1.leave(); 53 | session2.leave(); 54 | 55 | var chk = test.check() 56 | testcase.ok(!chk, chk); 57 | testcase.done(); 58 | } 59 | } 60 | 61 | sub = session2.subscribe('com.myapp.topic1', onevent1); 62 | }, 63 | function (err) { 64 | test.log(err); 65 | } 66 | ); 67 | } 68 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_pubsub_basic.txt: -------------------------------------------------------------------------------- 1 | 0 "all sessions connected" 2 | 1 "publishing to topic 'com.myapp.topic1': 0" 3 | 2 "Got event:" 0 4 | 3 "publishing to topic 'com.myapp.topic1': 1" 5 | 4 "Got event:" 1 6 | 5 "publishing to topic 'com.myapp.topic1': 2" 7 | 6 "Got event:" 2 8 | 7 "publishing to topic 'com.myapp.topic1': 3" 9 | 8 "Got event:" 3 10 | 9 "publishing to topic 'com.myapp.topic1': 4" 11 | 10 "Got event:" 4 12 | 11 "publishing to topic 'com.myapp.topic1': 5" 13 | 12 "Got event:" 5 14 | 13 "Closing .." 15 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_pubsub_complex.js: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // AutobahnJS - http://autobahn.ws, http://wamp.ws 4 | // 5 | // A JavaScript library for WAMP ("The Web Application Messaging Protocol"). 6 | // 7 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 8 | // 9 | // Licensed under the MIT License. 10 | // http://www.opensource.org/licenses/mit-license.php 11 | // 12 | /////////////////////////////////////////////////////////////////////////////// 13 | 14 | var autobahn = require('../index.js'); 15 | var testutil = require('./testutil.js'); 16 | 17 | 18 | exports.testPubsubComplex = function (testcase) { 19 | 20 | testcase.expect(1); 21 | 22 | var test = new testutil.Testlog("test/test_pubsub_complex.txt"); 23 | 24 | var dl = testutil.connect_n(2); 25 | 26 | autobahn.when.all(dl).then( 27 | function (res) { 28 | test.log("all sessions connected"); 29 | 30 | var session1 = res[0]; 31 | var session2 = res[1]; 32 | 33 | var counter = 0; 34 | 35 | var t1 = setInterval(function () { 36 | var lst = []; 37 | for (var i = 0; i < counter; ++i) { 38 | lst.push(i); 39 | } 40 | var obj = { 41 | 'counter': counter, 42 | 'foo': [1, counter, 2 * counter], 43 | 'bar': 'This is a test text.', 44 | 'baz': { 45 | 'a': 1.23456, 'b': 10000, 'c': null, 'd': 'foo' 46 | } 47 | }; 48 | session1.publish('com.myapp.topic1', lst, obj); 49 | 50 | counter += 1; 51 | 52 | test.log("events published", counter); 53 | }, 100); 54 | 55 | 56 | var received = 0; 57 | 58 | function on_topic1(args, kwargs) { 59 | test.log("got event:", args, kwargs); 60 | received += 1; 61 | if (received > 5) { 62 | test.log("closing .."); 63 | 64 | clearInterval(t1); 65 | 66 | session1.leave(); 67 | session2.leave(); 68 | 69 | var chk = test.check() 70 | testcase.ok(!chk, chk); 71 | testcase.done(); 72 | } 73 | } 74 | 75 | session2.subscribe('com.myapp.topic1', on_topic1); 76 | }, 77 | function (err) { 78 | test.log(err); 79 | } 80 | ); 81 | } 82 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_pubsub_complex.txt: -------------------------------------------------------------------------------- 1 | 0 "all sessions connected" 2 | 1 "events published" 1 3 | 2 "got event:" [] {"bar":"This is a test text.","baz":{"a":1.23456,"b":10000,"c":null,"d":"foo"},"counter":0,"foo":[1,0,0]} 4 | 3 "events published" 2 5 | 4 "got event:" [0] {"bar":"This is a test text.","baz":{"a":1.23456,"b":10000,"c":null,"d":"foo"},"counter":1,"foo":[1,1,2]} 6 | 5 "events published" 3 7 | 6 "got event:" [0,1] {"bar":"This is a test text.","baz":{"a":1.23456,"b":10000,"c":null,"d":"foo"},"counter":2,"foo":[1,2,4]} 8 | 7 "events published" 4 9 | 8 "got event:" [0,1,2] {"bar":"This is a test text.","baz":{"a":1.23456,"b":10000,"c":null,"d":"foo"},"counter":3,"foo":[1,3,6]} 10 | 9 "events published" 5 11 | 10 "got event:" [0,1,2,3] {"bar":"This is a test text.","baz":{"a":1.23456,"b":10000,"c":null,"d":"foo"},"counter":4,"foo":[1,4,8]} 12 | 11 "events published" 6 13 | 12 "got event:" [0,1,2,3,4] {"bar":"This is a test text.","baz":{"a":1.23456,"b":10000,"c":null,"d":"foo"},"counter":5,"foo":[1,5,10]} 14 | 13 "closing .." 15 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_pubsub_eligible.txt: -------------------------------------------------------------------------------- 1 | 0 "all sessions connected" 2 | 1 "" 3 | 2 "Case 1: 'eligible' unset" 4 | 3 "===========================" 5 | 4 "-----------" 6 | 5 "Session 2 got event: 0" 7 | 6 "Session 2 got event: 1" 8 | 7 "Session 2 got event: 2" 9 | 8 "Session 2 got event: 3" 10 | 9 "Session 2 got event: 4" 11 | 10 "Session 2 got event: 5" 12 | 11 "----------" 13 | 12 "-----------" 14 | 13 "Session 3 got event: 0" 15 | 14 "Session 3 got event: 1" 16 | 15 "Session 3 got event: 2" 17 | 16 "Session 3 got event: 3" 18 | 17 "Session 3 got event: 4" 19 | 18 "Session 3 got event: 5" 20 | 19 "----------" 21 | 20 "" 22 | 21 "Case 2: 'eligible' session3 " 23 | 22 "===========================" 24 | 23 "Session 3 got event:" 0 25 | 24 "Session 3 got event:" 1 26 | 25 "Session 3 got event:" 2 27 | 26 "Session 3 got event:" 3 28 | 27 "Session 3 got event:" 4 29 | 28 "Session 3 got event:" 5 30 | 29 "" 31 | 30 "" 32 | 31 "" 33 | 32 "" 34 | 33 "Case 3: 'eligible' session 2 + session 3" 35 | 34 "===========================" 36 | 35 "-----------" 37 | 36 "Session 2 got event: 0" 38 | 37 "Session 2 got event: 1" 39 | 38 "Session 2 got event: 2" 40 | 39 "Session 2 got event: 3" 41 | 40 "Session 2 got event: 4" 42 | 41 "Session 2 got event: 5" 43 | 42 "----------" 44 | 43 "-----------" 45 | 44 "Session 3 got event: 0" 46 | 45 "Session 3 got event: 1" 47 | 46 "Session 3 got event: 2" 48 | 47 "Session 3 got event: 3" 49 | 48 "Session 3 got event: 4" 50 | 49 "Session 3 got event: 5" 51 | 50 "----------" 52 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_pubsub_exclude.txt: -------------------------------------------------------------------------------- 1 | 0 "all sessions connected" 2 | 1 "" 3 | 2 "Case 1: 'exclude' unset" 4 | 3 "===========================" 5 | 4 "-----------" 6 | 5 "Session 2 got event: 0" 7 | 6 "Session 2 got event: 1" 8 | 7 "Session 2 got event: 2" 9 | 8 "Session 2 got event: 3" 10 | 9 "Session 2 got event: 4" 11 | 10 "Session 2 got event: 5" 12 | 11 "----------" 13 | 12 "-----------" 14 | 13 "Session 3 got event: 0" 15 | 14 "Session 3 got event: 1" 16 | 15 "Session 3 got event: 2" 17 | 16 "Session 3 got event: 3" 18 | 17 "Session 3 got event: 4" 19 | 18 "Session 3 got event: 5" 20 | 19 "----------" 21 | 20 "" 22 | 21 "Case 2: 'exclude' session2 " 23 | 22 "===========================" 24 | 23 "Session 3 got event:" 0 25 | 24 "Session 3 got event:" 1 26 | 25 "Session 3 got event:" 2 27 | 26 "Session 3 got event:" 3 28 | 27 "Session 3 got event:" 4 29 | 28 "Session 3 got event:" 5 30 | 29 "" 31 | 30 "" 32 | 31 "" 33 | 32 "" 34 | 33 "Case 3: 'exclude' sessions 2 and 3" 35 | 34 "==================================" 36 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_pubsub_excludeme.txt: -------------------------------------------------------------------------------- 1 | 0 "all sessions connected" 2 | 1 "" 3 | 2 "Case 1: 'exclude_me' unset" 4 | 3 "===========================" 5 | 4 "Session 2 got event:" 0 6 | 5 "Session 2 got event:" 1 7 | 6 "Session 2 got event:" 2 8 | 7 "Session 2 got event:" 3 9 | 8 "Session 2 got event:" 4 10 | 9 "Session 2 got event:" 5 11 | 10 "" 12 | 11 "" 13 | 12 "Case 2: 'exclude_me: true' " 14 | 13 "===========================" 15 | 14 "Session 2 got event:" 0 16 | 15 "Session 2 got event:" 1 17 | 16 "Session 2 got event:" 2 18 | 17 "Session 2 got event:" 3 19 | 18 "Session 2 got event:" 4 20 | 19 "Session 2 got event:" 5 21 | 20 "" 22 | 21 "" 23 | 22 "Case 3: 'exclude_me: false' " 24 | 23 "===========================" 25 | 24 "" 26 | 25 "Session 1 got event: 0" 27 | 26 "Session 1 got event: 1" 28 | 27 "Session 1 got event: 2" 29 | 28 "Session 1 got event: 3" 30 | 29 "Session 1 got event: 4" 31 | 30 "Session 1 got event: 5" 32 | 31 "" 33 | 32 "Session 2 got event: 0" 34 | 33 "Session 2 got event: 1" 35 | 34 "Session 2 got event: 2" 36 | 35 "Session 2 got event: 3" 37 | 36 "Session 2 got event: 4" 38 | 37 "Session 2 got event: 5" 39 | 38 "" 40 | 39 "Finished." 41 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_pubsub_multiple_matching_subs.txt: -------------------------------------------------------------------------------- 1 | 0 "all sessions connected" 2 | 1 "all test sessions subscribed!" 3 | 2 "session_ident=B subscribed with topic=com..topic1, match=wildcard" 4 | 3 "session_ident=C subscribed with topic=com.myapp, match=prefix" 5 | 4 "session_ident=D subscribed with topic=com, match=prefix" 6 | 5 "session_ident=E subscribed with topic=com.myapp.topic1, match=exact" 7 | 6 "publishing test events .." 8 | 7 "event: args=" ["hello subscriber!",1] ", kwargs=" {} 9 | 8 "subscription: sub_topic=" "com.myapp.topic1" ", sub_match=" "exact" ", session_ident=" "E" 10 | 9 "received 1 events up to this point .." 11 | 10 "event: args=" ["hello subscriber!",1] ", kwargs=" {} 12 | 11 "subscription: sub_topic=" "com" ", sub_match=" "prefix" ", session_ident=" "D" 13 | 12 "received 2 events up to this point .." 14 | 13 "event: args=" ["hello subscriber!",1] ", kwargs=" {} 15 | 14 "subscription: sub_topic=" "com.myapp" ", sub_match=" "prefix" ", session_ident=" "C" 16 | 15 "received 3 events up to this point .." 17 | 16 "event: args=" ["hello subscriber!",1] ", kwargs=" {} 18 | 17 "subscription: sub_topic=" "com..topic1" ", sub_match=" "wildcard" ", session_ident=" "B" 19 | 18 "received 4 events up to this point .." 20 | 19 "event: args=" ["hello subscriber!",2] ", kwargs=" {} 21 | 20 "subscription: sub_topic=" "com" ", sub_match=" "prefix" ", session_ident=" "D" 22 | 21 "received 5 events up to this point .." 23 | 22 "event: args=" ["hello subscriber!",2] ", kwargs=" {} 24 | 23 "subscription: sub_topic=" "com.myapp" ", sub_match=" "prefix" ", session_ident=" "C" 25 | 24 "received 6 events up to this point .." 26 | 25 "event: args=" ["hello subscriber!",3] ", kwargs=" {} 27 | 26 "subscription: sub_topic=" "com" ", sub_match=" "prefix" ", session_ident=" "D" 28 | 27 "received 7 events up to this point .." 29 | 28 "event: args=" ["hello subscriber!",3] ", kwargs=" {} 30 | 29 "subscription: sub_topic=" "com.myapp" ", sub_match=" "prefix" ", session_ident=" "C" 31 | 30 "received 8 events up to this point .." 32 | 31 "all test events published!" 33 | 32 "event: args=" ["hello subscriber!",5] ", kwargs=" {} 34 | 33 "subscription: sub_topic=" "com" ", sub_match=" "prefix" ", session_ident=" "D" 35 | 34 "closing .." 36 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_pubsub_options.js: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // AutobahnJS - http://autobahn.ws, http://wamp.ws 4 | // 5 | // A JavaScript library for WAMP ("The Web Application Messaging Protocol"). 6 | // 7 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 8 | // 9 | // Licensed under the MIT License. 10 | // http://www.opensource.org/licenses/mit-license.php 11 | // 12 | /////////////////////////////////////////////////////////////////////////////// 13 | 14 | var autobahn = require('../index.js'); 15 | var testutil = require('./testutil.js'); 16 | 17 | 18 | exports.testPubsubOptions = function (testcase) { 19 | 20 | testcase.expect(1); 21 | 22 | var test = new testutil.Testlog("test/test_pubsub_options.txt"); 23 | 24 | var dl = testutil.connect_n(2); 25 | 26 | autobahn.when.all(dl).then( 27 | function (res) { 28 | test.log("all sessions connected"); 29 | 30 | var session1 = res[0]; 31 | var session2 = res[1]; 32 | 33 | var counter = 0; 34 | var received = 0; 35 | var sub; 36 | 37 | function onevent1(args, kwargs, details) { 38 | // FIXME: publisher disclosure now is a strictly router configured 39 | // test.log("got event:", typeof(details), typeof(details.publication), typeof(details.publisher), details.publisher == session1.id, args[0]); 40 | test.log("got event:", typeof(details), typeof(details.publication), args[0]); 41 | 42 | received += 1; 43 | if (received > 5) { 44 | test.log("Closing .."); 45 | 46 | clearInterval(t1); 47 | 48 | session1.leave(); 49 | session2.leave(); 50 | 51 | var chk = test.check() 52 | testcase.ok(!chk, chk); 53 | testcase.done(); 54 | } 55 | } 56 | 57 | sub = session2.subscribe('com.myapp.topic1', onevent1); 58 | 59 | var t1 = setInterval(function () { 60 | var options = {acknowledge: true}; 61 | 62 | session1.publish('com.myapp.topic1', [counter], {}, options).then( 63 | function (pub) { 64 | test.log("event published", typeof(pub), typeof(pub.id)); 65 | } 66 | ); 67 | counter += 1; 68 | }, 1000); 69 | }, 70 | function (err) { 71 | test.log(err); 72 | } 73 | ); 74 | } 75 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_pubsub_options.txt: -------------------------------------------------------------------------------- 1 | 0 "all sessions connected" 2 | 1 "event published" "object" "number" 3 | 2 "got event:" "object" "number" 0 4 | 3 "event published" "object" "number" 5 | 4 "got event:" "object" "number" 1 6 | 5 "event published" "object" "number" 7 | 6 "got event:" "object" "number" 2 8 | 7 "event published" "object" "number" 9 | 8 "got event:" "object" "number" 3 10 | 9 "event published" "object" "number" 11 | 10 "got event:" "object" "number" 4 12 | 11 "event published" "object" "number" 13 | 12 "got event:" "object" "number" 5 14 | 13 "Closing .." 15 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_pubsub_prefix_sub.js: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // AutobahnJS - http://autobahn.ws, http://wamp.ws 4 | // 5 | // A JavaScript library for WAMP ("The Web Application Messaging Protocol"). 6 | // 7 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 8 | // 9 | // Licensed under the MIT License. 10 | // http://www.opensource.org/licenses/mit-license.php 11 | // 12 | /////////////////////////////////////////////////////////////////////////////// 13 | 14 | var autobahn = require('../index.js'); 15 | var testutil = require('./testutil.js'); 16 | 17 | 18 | exports.testPubsubPrefixSub = function (testcase) { 19 | 20 | testcase.expect(1); 21 | 22 | var test = new testutil.Testlog("test/test_pubsub_prefix_sub.txt"); 23 | 24 | var dl = testutil.connect_n(2); 25 | 26 | autobahn.when.all(dl).then( 27 | function (res) { 28 | test.log("all sessions connected"); 29 | 30 | var session1 = res[0]; 31 | var session2 = res[1]; 32 | var received = 0; 33 | 34 | function onevent1 (args) { 35 | test.log("Got event:", args); 36 | received += 1; 37 | if (received >= 7) { 38 | test.log("Closing .."); 39 | 40 | session1.leave(); 41 | session2.leave(); 42 | 43 | var chk = test.check() 44 | testcase.ok(!chk, chk); 45 | testcase.done(); 46 | } 47 | } 48 | 49 | var options = {match: 'prefix'}; 50 | var msg = "Hello prefix pattern subscriber!"; 51 | var counter = 0; 52 | 53 | session2.subscribe('com.myapp', onevent1, options).then( 54 | function (subscription) { 55 | // these are all received 56 | session1.publish('com.myapp.topic1.foobar', [msg, counter++]); 57 | session1.publish('com.myapp.topic1', [msg, counter++]); 58 | session1.publish('com.myapp.topi', [msg, counter++]); 59 | session1.publish('com.myapp2.foobar', [msg, counter++]); 60 | session1.publish('com.myapp2', [msg, counter++]); 61 | session1.publish('com.myapp.2', [msg, counter++]); 62 | session1.publish('com.myapp', [msg, counter++]); 63 | 64 | // these are not received 65 | session1.publish('com.app.topic1', [msg, counter++]); 66 | session1.publish('com.myap', [msg, counter++]); 67 | session1.publish('com', [msg, counter++]); 68 | }, 69 | function (err) { 70 | test.log(err); 71 | } 72 | ); 73 | }, 74 | function (err) { 75 | test.log(err); 76 | } 77 | ); 78 | } 79 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_pubsub_prefix_sub.txt: -------------------------------------------------------------------------------- 1 | 0 "all sessions connected" 2 | 1 "Got event:" ["Hello prefix pattern subscriber!",0] 3 | 2 "Got event:" ["Hello prefix pattern subscriber!",1] 4 | 3 "Got event:" ["Hello prefix pattern subscriber!",2] 5 | 4 "Got event:" ["Hello prefix pattern subscriber!",3] 6 | 5 "Got event:" ["Hello prefix pattern subscriber!",4] 7 | 6 "Got event:" ["Hello prefix pattern subscriber!",5] 8 | 7 "Got event:" ["Hello prefix pattern subscriber!",6] 9 | 8 "Closing .." 10 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_pubsub_wildcard_sub.js: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // AutobahnJS - http://autobahn.ws, http://wamp.ws 4 | // 5 | // A JavaScript library for WAMP ("The Web Application Messaging Protocol"). 6 | // 7 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 8 | // 9 | // Licensed under the MIT License. 10 | // http://www.opensource.org/licenses/mit-license.php 11 | // 12 | /////////////////////////////////////////////////////////////////////////////// 13 | 14 | var autobahn = require('../index.js'); 15 | var testutil = require('./testutil.js'); 16 | 17 | 18 | exports.testPubsubWildcardSub = function (testcase) { 19 | 20 | testcase.expect(1); 21 | 22 | var test = new testutil.Testlog("test/test_pubsub_wildcard_sub.txt"); 23 | 24 | var dl = testutil.connect_n(2); 25 | 26 | autobahn.when.all(dl).then( 27 | function (res) { 28 | test.log("all sessions connected"); 29 | 30 | var session1 = res[0]; 31 | var session2 = res[1]; 32 | var received = 0; 33 | 34 | function onevent1 (args) { 35 | test.log("Got event:", args); 36 | received += 1; 37 | if (received >= 2) { 38 | test.log("Closing .."); 39 | 40 | session1.leave(); 41 | session2.leave(); 42 | 43 | var chk = test.check() 44 | testcase.ok(!chk, chk); 45 | testcase.done(); 46 | } 47 | } 48 | 49 | var options = {match: 'wildcard'}; 50 | var msg = "Hello wildcard pattern subscriber!"; 51 | var counter = 0; 52 | 53 | session2.subscribe('com.example..create', onevent1, options).then( 54 | function (subscription) { 55 | // these are all received 56 | session1.publish('com.example.foobar.create', [msg, counter++]); 57 | session1.publish('com.example.1.create', [msg, counter++]); 58 | 59 | // these are not received 60 | session1.publish('com.example.foobar.delete', [msg, counter++]); 61 | session1.publish('com.example.foobar.create2', [msg, counter++]); 62 | session1.publish('com.example.foobar.create.barbaz', [msg, counter++]); 63 | session1.publish('com.example.foobar', [msg, counter++]); 64 | session1.publish('com.example.create', [msg, counter++]); 65 | session1.publish('com.example', [msg, counter++]); 66 | }, 67 | function (err) { 68 | test.log(err); 69 | } 70 | ); 71 | }, 72 | function (err) { 73 | test.log(err); 74 | } 75 | ); 76 | } 77 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_pubsub_wildcard_sub.txt: -------------------------------------------------------------------------------- 1 | 0 "all sessions connected" 2 | 1 "Got event:" ["Hello wildcard pattern subscriber!",0] 3 | 2 "Got event:" ["Hello wildcard pattern subscriber!",1] 4 | 3 "Closing .." 5 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_rawsocket_transport.js: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // AutobahnJS - http://autobahn.ws, http://wamp.ws 4 | // 5 | // A JavaScript library for WAMP ("The Web Application Messaging Protocol"). 6 | // 7 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 8 | // 9 | // Licensed under the MIT License. 10 | // http://www.opensource.org/licenses/mit-license.php 11 | // 12 | /////////////////////////////////////////////////////////////////////////////// 13 | 14 | var autobahn = require('../index.js'); 15 | var testutil = require('./testutil.js'); 16 | 17 | exports.testRawSocketTransport = function (testcase) { 18 | 19 | testcase.expect(1); 20 | 21 | var test = new testutil.Testlog("test/test_rawsocket_transport.txt"); 22 | var N = 2; 23 | 24 | test.log("connecting " + N + " sessions ..."); 25 | 26 | var connection_config = { 27 | realm: testutil.config.realm, 28 | transports: [ 29 | { 30 | type: 'rawsocket', 31 | host: '127.0.0.1', 32 | port: 8080 33 | } 34 | ], 35 | // FIXME - serializer is ignored! sth wrong 36 | serializers: [ 37 | new autobahn.serializer.MsgpackSerializer() 38 | ], 39 | protocols: ['wamp.2.msgpack'] 40 | }; 41 | 42 | var dl = testutil.connect_n(N, connection_config); 43 | 44 | autobahn.when.all(dl).then( 45 | function (res) { 46 | test.log("all " + res.length + " sessions connected"); 47 | 48 | for (var i = 0; i < res.length; ++i) { 49 | test.log("session._socket.info", res[i]._socket.info); 50 | } 51 | 52 | var session1 = res[0]; 53 | var session2 = res[1]; 54 | 55 | var counter = 0; 56 | 57 | var t1 = setInterval(function () { 58 | test.log("publishing to topic 'com.myapp.topic1': " + counter); 59 | session1.publish('com.myapp.topic1', [counter]); 60 | counter += 1; 61 | }, 100); 62 | 63 | var received = 0; 64 | 65 | var sub; 66 | function onevent1(args) { 67 | test.log("Got event:", args[0]); 68 | received += 1; 69 | if (received > 5) { 70 | test.log("Closing .."); 71 | 72 | clearInterval(t1); 73 | 74 | session1.leave(); 75 | session2.leave(); 76 | 77 | var chk = test.check() 78 | testcase.ok(!chk, chk); 79 | testcase.done(); 80 | } 81 | } 82 | 83 | sub = session2.subscribe('com.myapp.topic1', onevent1); 84 | }, 85 | function (err) { 86 | test.log(err); 87 | 88 | var chk = test.check(); 89 | testcase.ok(!chk, chk); 90 | testcase.done(); 91 | } 92 | ); 93 | } 94 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_rawsocket_transport.txt: -------------------------------------------------------------------------------- 1 | 0 "connecting 2 sessions ..." 2 | 1 "all 2 sessions connected" 3 | 2 "session._socket.info" {"protocol":"wamp.2.json","type":"rawsocket","url":null} 4 | 3 "session._socket.info" {"protocol":"wamp.2.json","type":"rawsocket","url":null} 5 | 4 "publishing to topic 'com.myapp.topic1': 0" 6 | 5 "Got event:" 0 7 | 6 "publishing to topic 'com.myapp.topic1': 1" 8 | 7 "Got event:" 1 9 | 8 "publishing to topic 'com.myapp.topic1': 2" 10 | 9 "Got event:" 2 11 | 10 "publishing to topic 'com.myapp.topic1': 3" 12 | 11 "Got event:" 3 13 | 12 "publishing to topic 'com.myapp.topic1': 4" 14 | 13 "Got event:" 4 15 | 14 "publishing to topic 'com.myapp.topic1': 5" 16 | 15 "Got event:" 5 17 | 16 "Closing .." 18 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_rpc_arguments.txt: -------------------------------------------------------------------------------- 1 | 0 "Connected" 2 | 1 "All registered." 3 | 2 "ping()" 4 | 3 "add2()" [2,3] 5 | 4 "stars" [] {"nick":"somebody","stars":0} 6 | 5 "stars" [] {"nick":"Homer","stars":0} 7 | 6 "stars" [] {"nick":"somebody","stars":5} 8 | 7 "stars" [] {"nick":"Homer","stars":5} 9 | 8 "orders()" ["coffee"] {"limit":5} 10 | 9 "orders()" ["coffee"] {"limit":10} 11 | 10 "arglen()" [] {} 12 | 11 "arglen()" [1,2,3] {} 13 | 12 "arglen()" [] {"a":1,"b":2,"c":3} 14 | 13 "arglen()" [1,2,3] {"a":1,"b":2,"c":3} 15 | 14 "Pinged" 16 | 15 "Add2:" 5 17 | 16 "Starred 1:" "somebody starred 0x" 18 | 17 "Starred 2:" "Homer starred 0x" 19 | 18 "Starred 3:" "somebody starred 5x" 20 | 19 "Starred 4:" "Homer starred 5x" 21 | 20 "Orders 1:" [0,1,2,3,4] 22 | 21 "Orders 2:" [0,1,2,3,4,5,6,7,8,9] 23 | 22 "Arglen 1" [0,0] 24 | 23 "Arglen 2" [3,0] 25 | 24 "Arglen 3" [0,3] 26 | 25 "Arglen 4" [3,3] 27 | 26 "All finished." 28 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_rpc_complex.js: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // AutobahnJS - http://autobahn.ws, http://wamp.ws 4 | // 5 | // A JavaScript library for WAMP ("The Web Application Messaging Protocol"). 6 | // 7 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 8 | // 9 | // Licensed under the MIT License. 10 | // http://www.opensource.org/licenses/mit-license.php 11 | // 12 | /////////////////////////////////////////////////////////////////////////////// 13 | 14 | var autobahn = require('../index.js'); 15 | var testutil = require('./testutil.js'); 16 | 17 | 18 | exports.testRpcComplex = function (testcase) { 19 | 20 | testcase.expect(1); 21 | 22 | var test = new testutil.Testlog("test/test_rpc_complex.txt"); 23 | 24 | var connection = new autobahn.Connection(testutil.config); 25 | 26 | connection.onopen = function (session) { 27 | 28 | test.log('Connected'); 29 | 30 | function add_complex(args, kwargs) { 31 | test.log("add_complex()", args, kwargs); 32 | return new autobahn.Result([], {c: args[0] + args[2], ci: args[1] + args[3]}); 33 | } 34 | 35 | function split_name(args) { 36 | test.log("split_name()", args); 37 | return new autobahn.Result(args[0].split(" ")); 38 | } 39 | 40 | function echo_complex(args, kwargs) { 41 | test.log("echo_complex()", args, kwargs); 42 | return new autobahn.Result(args, kwargs); 43 | } 44 | 45 | var endpoints = { 46 | 'com.myapp.add_complex': add_complex, 47 | 'com.myapp.split_name': split_name, 48 | 'com.myapp.echo_complex': echo_complex 49 | }; 50 | 51 | var pl1 = []; 52 | 53 | for (var uri in endpoints) { 54 | pl1.push(session.register(uri, endpoints[uri])); 55 | } 56 | 57 | autobahn.when.all(pl1).then( 58 | function () { 59 | test.log("All registered."); 60 | 61 | // we enforce sequential execution of RPCs to get "stable" test results 62 | 63 | var d = session.call('com.myapp.add_complex', [2, 3, 4, 5]).then( 64 | function (res) { 65 | test.log("Result: " + res.kwargs.c + " + " + res.kwargs.ci + "i"); 66 | } 67 | ); 68 | 69 | d = d.then(function () { 70 | return session.call('com.myapp.split_name', ['Homer Simpson']).then( 71 | function (res) { 72 | test.log("Forename: " + res.args[0] + ", Surname: " + res.args[1]); 73 | } 74 | ); 75 | }); 76 | 77 | var params = [ 78 | [null, null], 79 | [null, {a: 23, b: "hello"}], 80 | [[1, 2, 3], null], 81 | [[], {}], 82 | [[], {a: 23, b: "hello"}], 83 | [[1, 2, 3], {}], 84 | [[1, 2, 3], {a: 23, b: "hello"}], 85 | [[1, 2, 3, {a: 23, b: "hello"}], {a: 23, b: "hello", c: [1, 2, 3]}], 86 | ]; 87 | 88 | for (var i = 0; i < params.length; ++i) { 89 | (function (i, args, kwargs) { 90 | d = d.then(function () { 91 | return session.call('com.myapp.echo_complex', args, kwargs).then( 92 | function (res) { 93 | test.log("Complex echo", res); 94 | } 95 | ); 96 | }); 97 | })(i, params[i][0], params[i][1]); 98 | } 99 | 100 | d.then(function () { 101 | test.log("All finished."); 102 | connection.close(); 103 | 104 | var chk = test.check() 105 | testcase.ok(!chk, chk); 106 | testcase.done(); 107 | }); 108 | }, 109 | function () { 110 | test.log("Registration failed!", arguments); 111 | } 112 | ); 113 | }; 114 | 115 | connection.open(); 116 | } 117 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_rpc_complex.txt: -------------------------------------------------------------------------------- 1 | 0 "Connected" 2 | 1 "All registered." 3 | 2 "add_complex()" [2,3,4,5] {} 4 | 3 "Result: 6 + 8i" 5 | 4 "split_name()" ["Homer Simpson"] 6 | 5 "Forename: Homer, Surname: Simpson" 7 | 6 "echo_complex()" [] {} 8 | 7 "Complex echo" null 9 | 8 "echo_complex()" [] {"a":23,"b":"hello"} 10 | 9 "Complex echo" {"args":[],"kwargs":{"a":23,"b":"hello"}} 11 | 10 "echo_complex()" [1,2,3] {} 12 | 11 "Complex echo" {"args":[1,2,3],"kwargs":{}} 13 | 12 "echo_complex()" [] {} 14 | 13 "Complex echo" null 15 | 14 "echo_complex()" [] {"a":23,"b":"hello"} 16 | 15 "Complex echo" {"args":[],"kwargs":{"a":23,"b":"hello"}} 17 | 16 "echo_complex()" [1,2,3] {} 18 | 17 "Complex echo" {"args":[1,2,3],"kwargs":{}} 19 | 18 "echo_complex()" [1,2,3] {"a":23,"b":"hello"} 20 | 19 "Complex echo" {"args":[1,2,3],"kwargs":{"a":23,"b":"hello"}} 21 | 20 "echo_complex()" [1,2,3,{"a":23,"b":"hello"}] {"a":23,"b":"hello","c":[1,2,3]} 22 | 21 "Complex echo" {"args":[1,2,3,{"a":23,"b":"hello"}],"kwargs":{"a":23,"b":"hello","c":[1,2,3]}} 23 | 22 "All finished." 24 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_rpc_error.js: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // AutobahnJS - http://autobahn.ws, http://wamp.ws 4 | // 5 | // A JavaScript library for WAMP ("The Web Application Messaging Protocol"). 6 | // 7 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 8 | // 9 | // Licensed under the MIT License. 10 | // http://www.opensource.org/licenses/mit-license.php 11 | // 12 | /////////////////////////////////////////////////////////////////////////////// 13 | 14 | var autobahn = require('../index.js'); 15 | var testutil = require('./testutil.js'); 16 | 17 | 18 | exports.testRpcError = function (testcase) { 19 | 20 | testcase.expect(1); 21 | 22 | var test = new testutil.Testlog("test/test_rpc_error.txt"); 23 | 24 | var connection = new autobahn.Connection(testutil.config); 25 | 26 | connection.onopen = function (session) { 27 | 28 | test.log('Connected'); 29 | 30 | function sqrt(args) { 31 | var x = args[0]; 32 | if (x === 0) { 33 | throw "don't ask folly questions;)"; 34 | } 35 | var res = Math.sqrt(x); 36 | if (res !== res) { 37 | //throw "cannot take sqrt of negative"; 38 | throw new autobahn.Error('com.myapp.error', ['fuck'], {a: 23, b: 9}); 39 | } 40 | return res.toFixed(6); 41 | } 42 | 43 | var endpoints = { 44 | 'com.myapp.sqrt': sqrt 45 | }; 46 | 47 | var pl1 = []; 48 | 49 | for (var uri in endpoints) { 50 | pl1.push(session.register(uri, endpoints[uri])); 51 | } 52 | 53 | autobahn.when.all(pl1).then( 54 | function () { 55 | test.log("All registered."); 56 | 57 | var pl2 = []; 58 | 59 | var vals1 = [2, 0, -2]; 60 | 61 | for (var i = 0; i < vals1.length; ++i) { 62 | 63 | pl2.push(session.call('com.myapp.sqrt', [vals1[i]]).then( 64 | function (res) { 65 | test.log("Result:", res); 66 | }, 67 | function (err) { 68 | test.log("Error:", err.error, err.args, err.kwargs); 69 | } 70 | )); 71 | } 72 | 73 | autobahn.when.all(pl2).then(function () { 74 | test.log("All finished."); 75 | connection.close(); 76 | 77 | var chk = test.check() 78 | testcase.ok(!chk, chk); 79 | testcase.done(); 80 | }); 81 | }, 82 | function () { 83 | test.log("Registration failed!", arguments); 84 | } 85 | ); 86 | }; 87 | 88 | connection.open(); 89 | } 90 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_rpc_error.txt: -------------------------------------------------------------------------------- 1 | 0 "Connected" 2 | 1 "All registered." 3 | 2 "Result:" "1.414214" 4 | 3 "Error:" "wamp.error.runtime_error" ["don't ask folly questions;)"] {} 5 | 4 "Error:" "com.myapp.error" ["fuck"] {"a":23,"b":9} 6 | 5 "All finished." 7 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_rpc_options.js: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // AutobahnJS - http://autobahn.ws, http://wamp.ws 4 | // 5 | // A JavaScript library for WAMP ("The Web Application Messaging Protocol"). 6 | // 7 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 8 | // 9 | // Licensed under the MIT License. 10 | // http://www.opensource.org/licenses/mit-license.php 11 | // 12 | /////////////////////////////////////////////////////////////////////////////// 13 | 14 | var autobahn = require('../index.js'); 15 | var testutil = require('./testutil.js'); 16 | 17 | 18 | exports.testRpcOptions = function (testcase) { 19 | 20 | testcase.expect(1); 21 | 22 | var test = new testutil.Testlog("test/test_rpc_options.txt"); 23 | 24 | var connection = new autobahn.Connection(testutil.config); 25 | 26 | connection.onopen = function (session) { 27 | 28 | test.log('Connected'); 29 | 30 | function square(args, kwargs, details) { 31 | 32 | if (details && details.caller) { 33 | // with this test case, the caller and callee are identical! 34 | // subtract both to make the result fixed in the OK case only 35 | details.caller -= session.id; 36 | } 37 | 38 | test.log("Someone is calling me;)", details); 39 | 40 | var val = args[0]; 41 | if (val < 0) { 42 | session.publish('com.myapp.square_on_nonpositive', [val]); 43 | } else if (val === 0) { 44 | var options = {}; 45 | if (details && details.caller) { 46 | options = {exclude: [details.caller]}; 47 | } 48 | session.publish('com.myapp.square_on_nonpositive', [val], {}, options); 49 | } 50 | return args[0] * args[0] 51 | } 52 | 53 | var endpoints = { 54 | 'com.myapp.square': square 55 | }; 56 | 57 | var pl1 = []; 58 | 59 | for (var uri in endpoints) { 60 | pl1.push(session.register(uri, endpoints[uri])); 61 | } 62 | 63 | autobahn.when.all(pl1).then( 64 | function () { 65 | test.log("All registered."); 66 | 67 | function on_event(val) { 68 | test.log("Someone requested to square non-positive:", val); 69 | } 70 | 71 | session.subscribe('com.myapp.square_on_nonpositive', on_event); 72 | 73 | var pl2 = []; 74 | 75 | var vals = [2, 0, -2]; 76 | for (var i = 0; i < vals.length; ++i) { 77 | 78 | pl2.push(session.call('com.myapp.square', [vals[i]], {}, {}).then( 79 | function (res) { 80 | test.log("Squared", res); 81 | }, 82 | function (error) { 83 | test.log("Call failed:", error); 84 | } 85 | )); 86 | } 87 | 88 | autobahn.when.all(pl2).then(function () { 89 | test.log("All finished."); 90 | connection.close(); 91 | 92 | var chk = test.check() 93 | testcase.ok(!chk, chk); 94 | testcase.done(); 95 | }); 96 | }, 97 | function () { 98 | test.log("Registration failed!", arguments); 99 | } 100 | ); 101 | }; 102 | 103 | connection.open(); 104 | } 105 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_rpc_options.txt: -------------------------------------------------------------------------------- 1 | 0 "Connected" 2 | 1 "All registered." 3 | 2 "Someone is calling me;)" {"caller":undefined,"caller_authid":undefined,"caller_authrole":undefined,"procedure":"com.myapp.square","progress":null} 4 | 3 "Someone is calling me;)" {"caller":undefined,"caller_authid":undefined,"caller_authrole":undefined,"procedure":"com.myapp.square","progress":null} 5 | 4 "Someone is calling me;)" {"caller":undefined,"caller_authid":undefined,"caller_authrole":undefined,"procedure":"com.myapp.square","progress":null} 6 | 5 "Squared" 4 7 | 6 "Squared" 0 8 | 7 "Squared" 4 9 | 8 "All finished." 10 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_rpc_progress.js: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // AutobahnJS - http://autobahn.ws, http://wamp.ws 4 | // 5 | // A JavaScript library for WAMP ("The Web Application Messaging Protocol"). 6 | // 7 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 8 | // 9 | // Licensed under the MIT License. 10 | // http://www.opensource.org/licenses/mit-license.php 11 | // 12 | /////////////////////////////////////////////////////////////////////////////// 13 | 14 | var autobahn = require('../index.js'); 15 | var testutil = require('./testutil.js'); 16 | 17 | 18 | exports.testRpcProgress = function (testcase) { 19 | 20 | testcase.expect(1); 21 | 22 | var test = new testutil.Testlog("test/test_rpc_progress.txt"); 23 | 24 | var connection = new autobahn.Connection(testutil.config); 25 | 26 | connection.onopen = function (session) { 27 | 28 | test.log('Connected'); 29 | 30 | function longop(args, kwargs, details) { 31 | 32 | test.log("longop()", args, kwargs); 33 | 34 | var n = args[0]; 35 | var interval_id = null; 36 | 37 | if (details.progress) { 38 | var i = 0; 39 | details.progress([i]); 40 | i += 1; 41 | interval_id = setInterval(function () { 42 | if (i < n) { 43 | test.log("longop() - progress", i); 44 | details.progress([i]); 45 | i += 1; 46 | } else { 47 | clearInterval(interval_id); 48 | } 49 | }, 100); 50 | } 51 | 52 | var d = autobahn.when.defer(); 53 | 54 | setTimeout(function () { 55 | d.resolve(n); 56 | }, 1000 * n); 57 | 58 | return d.promise; 59 | } 60 | 61 | var endpoints = { 62 | 'com.myapp.longop': longop 63 | }; 64 | 65 | var pl1 = []; 66 | 67 | for (var uri in endpoints) { 68 | pl1.push(session.register(uri, endpoints[uri])); 69 | } 70 | 71 | autobahn.when.all(pl1).then( 72 | function () { 73 | test.log("All registered."); 74 | 75 | var pl2 = []; 76 | 77 | pl2.push(session.call('com.myapp.longop', [3], {}, {receive_progress: true}).then( 78 | function (res) { 79 | test.log("Final:", res); 80 | }, 81 | function (err) { 82 | test.log("Error:", err); 83 | }, 84 | function (progress) { 85 | test.log("Progress:", progress); 86 | } 87 | )); 88 | 89 | autobahn.when.all(pl2).then(function () { 90 | test.log("All finished."); 91 | connection.close(); 92 | 93 | var chk = test.check() 94 | testcase.ok(!chk, chk); 95 | testcase.done(); 96 | }); 97 | }, 98 | function () { 99 | test.log("Registration failed!", arguments); 100 | } 101 | ); 102 | }; 103 | 104 | connection.open(); 105 | } 106 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_rpc_progress.txt: -------------------------------------------------------------------------------- 1 | 0 "Connected" 2 | 1 "All registered." 3 | 2 "longop()" [3] {} 4 | 3 "Progress:" 0 5 | 4 "longop() - progress" 1 6 | 5 "Progress:" 1 7 | 6 "longop() - progress" 2 8 | 7 "Progress:" 2 9 | 8 "Final:" 3 10 | 9 "All finished." 11 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_rpc_request_id_sequence.js: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // AutobahnJS - http://autobahn.ws, http://wamp.ws 4 | // 5 | // A JavaScript library for WAMP ("The Web Application Messaging Protocol"). 6 | // 7 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 8 | // 9 | // Licensed under the MIT License. 10 | // http://www.opensource.org/licenses/mit-license.php 11 | // 12 | /////////////////////////////////////////////////////////////////////////////// 13 | 14 | var autobahn = require('../index.js'); 15 | var testutil = require('./testutil.js'); 16 | 17 | var REGISTER_MSG_TYPE = 64; 18 | var CALL_MSG_TYPE = 48; 19 | 20 | exports.testRpcRequestIdSequence = function (testcase) { 21 | 22 | testcase.expect(2); 23 | 24 | var test = new testutil.Testlog("test/test_rpc_request_id_sequence.txt"); 25 | 26 | var connection = new autobahn.Connection(testutil.config); 27 | 28 | connection.onopen = function (session) { 29 | 30 | test.log('Connected'); 31 | 32 | // Hijack invocation processing to collect request IDs of incoming calls. 33 | var sent_request_ids = []; 34 | var original_send_wamp = session._send_wamp; 35 | session._send_wamp = function(msg) { 36 | if ((msg[0] === CALL_MSG_TYPE) || ((msg[0] === REGISTER_MSG_TYPE))) { 37 | var requestId = msg[1]; 38 | test.log('' + 'Sent call with id ' + requestId); 39 | sent_request_ids.push(requestId); 40 | } 41 | return original_send_wamp(msg) 42 | }; 43 | 44 | function noop() { return null; } 45 | 46 | session.register('com.myapp.do_nothing', noop).then( 47 | function () { 48 | test.log("Procedure registered."); 49 | 50 | // Enforce sequential execution of RPCs to get "stable" test results 51 | var d = session.call('com.myapp.do_nothing'); 52 | d = d.then(function (res) { 53 | test.log('Received response.'); 54 | return session.call('com.myapp.do_nothing') 55 | }); 56 | d = d.then(function (res) { 57 | test.log('Received response.'); 58 | return session.call('com.myapp.do_nothing') 59 | }); 60 | d = d.then(function (res) { 61 | test.log('Received response.'); 62 | }); 63 | 64 | d.then(function () { 65 | test.log("All calls made."); 66 | testcase.deepEqual(sent_request_ids, [1, 2, 3, 4]); 67 | 68 | session._send_wamp = original_send_wamp; 69 | connection.close(); 70 | 71 | var chk = test.check(); 72 | testcase.ok(!chk, chk); 73 | testcase.done(); 74 | }); 75 | }, 76 | function () { 77 | test.log("Registration failed!", arguments); 78 | } 79 | ); 80 | }; 81 | 82 | connection.open(); 83 | }; 84 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_rpc_request_id_sequence.txt: -------------------------------------------------------------------------------- 1 | 0 "Connected" 2 | 1 "Sent call with id 1" 3 | 2 "Procedure registered." 4 | 3 "Sent call with id 2" 5 | 4 "Received response." 6 | 5 "Sent call with id 3" 7 | 6 "Received response." 8 | 7 "Sent call with id 4" 9 | 8 "Received response." 10 | 9 "All calls made." 11 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_rpc_routing.js: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // AutobahnJS - http://autobahn.ws, http://wamp.ws 4 | // 5 | // A JavaScript library for WAMP ("The Web Application Messaging Protocol"). 6 | // 7 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 8 | // 9 | // Licensed under the MIT License. 10 | // http://www.opensource.org/licenses/mit-license.php 11 | // 12 | /////////////////////////////////////////////////////////////////////////////// 13 | 14 | var autobahn = require('../index.js'); 15 | var testutil = require('./testutil.js'); 16 | 17 | 18 | exports.testRpcRouting = function (testcase) { 19 | 20 | testcase.expect(2); 21 | 22 | var test = new testutil.Testlog("test/test_rpc_routing.txt"); 23 | 24 | var dl = testutil.connect_n(2); 25 | 26 | autobahn.when.all(dl).then( 27 | function (res) { 28 | test.log("all sessions connected"); 29 | 30 | var session1 = res[0]; 31 | var session2 = res[1]; 32 | 33 | function square(args, kwargs, details) { 34 | var x = args[0]; 35 | test.log("square() called from session 2", x); 36 | 37 | // FIXME: caller disclosure now is pure router config based 38 | // testcase.ok(details.caller == session2.id); 39 | return x * x; 40 | } 41 | 42 | session1.register('com.math.square', square).then( 43 | function (res) { 44 | 45 | test.log("square() registered on session 1"); 46 | 47 | session2.call('com.math.square', [23], {}, {}).then( 48 | function (res) { 49 | test.log("result:", res); 50 | 51 | session1.leave(); 52 | session2.leave(); 53 | 54 | testcase.ok(res == (23*23)); 55 | 56 | var chk = test.check() 57 | testcase.ok(!chk, chk); 58 | 59 | testcase.done(); 60 | }) 61 | } 62 | ); 63 | }, 64 | function (err) { 65 | test.log(err); 66 | } 67 | ); 68 | } 69 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_rpc_routing.txt: -------------------------------------------------------------------------------- 1 | 0 "all sessions connected" 2 | 1 "square() registered on session 1" 3 | 2 "square() called from session 2" 23 4 | 3 "result:" 529 5 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_rpc_slowsquare.js: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // AutobahnJS - http://autobahn.ws, http://wamp.ws 4 | // 5 | // A JavaScript library for WAMP ("The Web Application Messaging Protocol"). 6 | // 7 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 8 | // 9 | // Licensed under the MIT License. 10 | // http://www.opensource.org/licenses/mit-license.php 11 | // 12 | /////////////////////////////////////////////////////////////////////////////// 13 | 14 | var autobahn = require('../index.js'); 15 | var testutil = require('./testutil.js'); 16 | 17 | 18 | exports.testRpcSlowsquare = function (testcase) { 19 | 20 | testcase.expect(1); 21 | 22 | var test = new testutil.Testlog("test/test_rpc_slowsquare.txt"); 23 | 24 | var connection = new autobahn.Connection(testutil.config); 25 | 26 | connection.onopen = function (session) { 27 | 28 | test.log('Connected'); 29 | 30 | // a "fast" function or a function that returns 31 | // a direct value (not a promise) 32 | function square(x) { 33 | return x * x; 34 | } 35 | 36 | // simulates a "slow" function or a function that 37 | // returns a promise 38 | function slowsquare(x) { 39 | 40 | // create a deferred 41 | var d = autobahn.when.defer(); 42 | 43 | // resolve the promise after 1s 44 | setTimeout(function () { 45 | d.resolve(x * x); 46 | }, 500); 47 | 48 | // need to return the promise 49 | return d.promise; 50 | } 51 | 52 | var endpoints = { 53 | 'com.math.square': square, 54 | 'com.math.slowsquare': slowsquare 55 | }; 56 | 57 | var pl1 = []; 58 | 59 | for (var uri in endpoints) { 60 | pl1.push(session.register(uri, endpoints[uri])); 61 | } 62 | 63 | autobahn.when.all(pl1).then( 64 | function () { 65 | test.log("All registered."); 66 | 67 | var pl2 = []; 68 | 69 | var t1 = process.hrtime(); 70 | pl2.push(session.call('com.math.slowsquare', [3]).then( 71 | function (res) { 72 | var duration = process.hrtime(t1); 73 | test.log("Slow Square:", res); 74 | }, 75 | function (err) { 76 | test.log("Error", err); 77 | } 78 | )); 79 | 80 | var t2 = process.hrtime(); 81 | pl2.push(session.call('com.math.square', [3]).then( 82 | function (res) { 83 | var duration = process.hrtime(t2); 84 | test.log("Quick Square:", res); 85 | }, 86 | function (err) { 87 | test.log("Error", err); 88 | } 89 | )); 90 | 91 | autobahn.when.all(pl2).then(function () { 92 | test.log("All finished."); 93 | connection.close(); 94 | 95 | var chk = test.check() 96 | testcase.ok(!chk, chk); 97 | testcase.done(); 98 | }); 99 | }, 100 | function () { 101 | test.log("Registration failed!", arguments); 102 | } 103 | ); 104 | }; 105 | 106 | connection.open(); 107 | } 108 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_rpc_slowsquare.txt: -------------------------------------------------------------------------------- 1 | 0 "Connected" 2 | 1 "All registered." 3 | 2 "Quick Square:" 9 4 | 3 "Slow Square:" 9 5 | 4 "All finished." 6 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_sealedbox.js: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // AutobahnJS - http://autobahn.ws, http://wamp.ws 4 | // 5 | // A JavaScript library for WAMP ("The Web Application Messaging Protocol"). 6 | // 7 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 8 | // 9 | // Licensed under the MIT License. 10 | // http://www.opensource.org/licenses/mit-license.php 11 | // 12 | /////////////////////////////////////////////////////////////////////////////// 13 | 14 | // this works via https://github.com/caolan/nodeunit 15 | 16 | var autobahn = require('../index.js'); 17 | 18 | 19 | exports.testSealUnseal = function (testcase) { 20 | 21 | testcase.expect(1); 22 | var plainText = 'Sample Text'; 23 | var buffer = Buffer.from(plainText); 24 | var keyPair = autobahn.nacl.box.keyPair(); 25 | var sealed = autobahn.nacl.sealedbox.seal(buffer, keyPair.publicKey); 26 | var unsealed = autobahn.nacl.sealedbox.open(sealed, keyPair.publicKey, keyPair.secretKey); 27 | var text = String.fromCharCode.apply(null, unsealed); 28 | testcase.ok(plainText == text, "Text must match"); 29 | testcase.done(); 30 | } 31 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_serialization_cbor.js: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // AutobahnJS - http://autobahn.ws, http://wamp.ws 4 | // 5 | // A JavaScript library for WAMP ("The Web Application Messaging Protocol"). 6 | // 7 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 8 | // 9 | // Licensed under the MIT License. 10 | // http://www.opensource.org/licenses/mit-license.php 11 | // 12 | /////////////////////////////////////////////////////////////////////////////// 13 | 14 | const {randomBytes} = require("tweetnacl"); 15 | 16 | var autobahn = require('../index.js'); 17 | var testutil = require('./testutil.js'); 18 | 19 | exports.testCBORSerialization = function (testcase) { 20 | 21 | testcase.expect(1); 22 | 23 | var test = new testutil.Testlog("test/test_serialization_cbor.txt"); 24 | 25 | var ser = new autobahn.serializer.CBORSerializer(); 26 | 27 | var config = { 28 | url: testutil.config.url, 29 | realm: testutil.config.realm, 30 | serializers: [ser] 31 | }; 32 | var connection = new autobahn.Connection(config); 33 | 34 | connection.onopen = function (session) { 35 | 36 | test.log('Connected'); 37 | 38 | function echo(args) { 39 | return args[0]; 40 | } 41 | 42 | var endpoints = { 43 | 'com.myapp.echo': echo 44 | }; 45 | 46 | var pl1 = []; 47 | 48 | for (var uri in endpoints) { 49 | pl1.push(session.register(uri, endpoints[uri])); 50 | } 51 | 52 | autobahn.when.all(pl1).then( 53 | function () { 54 | test.log("All registered."); 55 | test.log("Serializer ID: " + session._socket.serializer.SERIALIZER_ID); 56 | 57 | var pl2 = []; 58 | 59 | var vals1 = [1.7, "hello", [1, 2, -3], {a: 5, b: "hello2"}, [-9007199254740991, 9007199254740991], null]; 60 | 61 | for (var i = 0; i < vals1.length; ++i) { 62 | 63 | pl2.push(session.call('com.myapp.echo', [vals1[i]]).then( 64 | function (res) { 65 | test.log("Result:", res); 66 | }, 67 | function (err) { 68 | test.log("Error:", err.error, err.args, err.kwargs); 69 | } 70 | )); 71 | } 72 | 73 | autobahn.when.all(pl2).then(function () { 74 | test.log("All finished."); 75 | connection.close(); 76 | 77 | var chk = test.check(); 78 | testcase.ok(!chk, chk); 79 | testcase.done(); 80 | }); 81 | }, 82 | function () { 83 | test.log("Registration failed!", arguments); 84 | } 85 | ); 86 | }; 87 | 88 | connection.open(); 89 | }; 90 | 91 | // see https://github.com/crossbario/autobahn-js/issues/565 92 | exports.testCBORLargePayload = function (testcase) { 93 | let ser = new autobahn.serializer.CBORSerializer(); 94 | 95 | let config = { 96 | url: testutil.config.url, 97 | realm: testutil.config.realm, 98 | serializers: [ser] 99 | }; 100 | let connection = new autobahn.Connection(config); 101 | 102 | connection.onopen = async function (session) { 103 | await session.register("com.myapp.payload", function (args) { 104 | return args[0] 105 | }) 106 | 107 | let payload = [] 108 | let data = randomBytes(16350) 109 | payload.push({data1: data, city: "x"}) 110 | let response = await session.call("com.myapp.payload", [payload]) 111 | 112 | testcase.ok(response.length === payload.length); 113 | testcase.done(); 114 | } 115 | 116 | connection.open(); 117 | } 118 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_serialization_cbor.txt: -------------------------------------------------------------------------------- 1 | 0 "Connected" 2 | 1 "All registered." 3 | 2 "Serializer ID: cbor" 4 | 3 "Result:" 1.7 5 | 4 "Result:" "hello" 6 | 5 "Result:" [1,2,-3] 7 | 6 "Result:" {"a":5,"b":"hello2"} 8 | 7 "Result:" [-9007199254740991,9007199254740991] 9 | 8 "Result:" null 10 | 9 "All finished." 11 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_serialization_json.js: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // AutobahnJS - http://autobahn.ws, http://wamp.ws 4 | // 5 | // A JavaScript library for WAMP ("The Web Application Messaging Protocol"). 6 | // 7 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 8 | // 9 | // Licensed under the MIT License. 10 | // http://www.opensource.org/licenses/mit-license.php 11 | // 12 | /////////////////////////////////////////////////////////////////////////////// 13 | 14 | var autobahn = require('../index.js'); 15 | var testutil = require('./testutil.js'); 16 | 17 | 18 | exports.testJSONSerialization = function (testcase) { 19 | 20 | testcase.expect(1); 21 | 22 | var test = new testutil.Testlog("test/test_serialization_json.txt"); 23 | 24 | var ser = new autobahn.serializer.JSONSerializer(); 25 | 26 | var config = { 27 | url: testutil.config.url, 28 | realm: testutil.config.realm, 29 | serializers: [ser] 30 | }; 31 | var connection = new autobahn.Connection(config); 32 | 33 | connection.onopen = function (session) { 34 | 35 | test.log('Connected'); 36 | 37 | function echo(args) { 38 | return args[0]; 39 | } 40 | 41 | var endpoints = { 42 | 'com.myapp.echo': echo 43 | }; 44 | 45 | var pl1 = []; 46 | 47 | for (var uri in endpoints) { 48 | pl1.push(session.register(uri, endpoints[uri])); 49 | } 50 | 51 | autobahn.when.all(pl1).then( 52 | function () { 53 | test.log("All registered."); 54 | test.log("Serializer ID: " + session._socket.serializer.SERIALIZER_ID); 55 | 56 | var pl2 = []; 57 | 58 | var vals1 = [1.7, "hello", [1, 2, -3], {a: 5, b: "hello2"}, [-9007199254740991, 9007199254740991], null]; 59 | 60 | for (var i = 0; i < vals1.length; ++i) { 61 | 62 | pl2.push(session.call('com.myapp.echo', [vals1[i]]).then( 63 | function (res) { 64 | test.log("Result:", res); 65 | }, 66 | function (err) { 67 | test.log("Error:", err.error, err.args, err.kwargs); 68 | } 69 | )); 70 | } 71 | 72 | autobahn.when.all(pl2).then(function () { 73 | test.log("All finished."); 74 | connection.close(); 75 | 76 | var chk = test.check(); 77 | testcase.ok(!chk, chk); 78 | testcase.done(); 79 | }); 80 | }, 81 | function () { 82 | test.log("Registration failed!", arguments); 83 | } 84 | ); 85 | }; 86 | 87 | connection.open(); 88 | }; 89 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_serialization_json.txt: -------------------------------------------------------------------------------- 1 | 0 "Connected" 2 | 1 "All registered." 3 | 2 "Serializer ID: json" 4 | 3 "Result:" 1.7 5 | 4 "Result:" "hello" 6 | 5 "Result:" [1,2,-3] 7 | 6 "Result:" {"a":5,"b":"hello2"} 8 | 7 "Result:" [-9007199254740991,9007199254740991] 9 | 8 "Result:" null 10 | 9 "All finished." 11 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_serialization_msgpack.js: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // AutobahnJS - http://autobahn.ws, http://wamp.ws 4 | // 5 | // A JavaScript library for WAMP ("The Web Application Messaging Protocol"). 6 | // 7 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 8 | // 9 | // Licensed under the MIT License. 10 | // http://www.opensource.org/licenses/mit-license.php 11 | // 12 | /////////////////////////////////////////////////////////////////////////////// 13 | 14 | var autobahn = require('../index.js'); 15 | var testutil = require('./testutil.js'); 16 | 17 | 18 | exports.testMsgpackSerialization = function (testcase) { 19 | 20 | testcase.expect(1); 21 | 22 | var test = new testutil.Testlog("test/test_serialization_msgpack.txt"); 23 | 24 | var ser = new autobahn.serializer.MsgpackSerializer(); 25 | 26 | var config = { 27 | url: testutil.config.url, 28 | realm: testutil.config.realm, 29 | serializers: [ser] 30 | }; 31 | var connection = new autobahn.Connection(config); 32 | 33 | connection.onopen = function (session) { 34 | 35 | test.log('Connected'); 36 | 37 | function echo(args) { 38 | return args[0]; 39 | } 40 | 41 | var endpoints = { 42 | 'com.myapp.echo': echo 43 | }; 44 | 45 | var pl1 = []; 46 | 47 | for (var uri in endpoints) { 48 | pl1.push(session.register(uri, endpoints[uri])); 49 | } 50 | 51 | autobahn.when.all(pl1).then( 52 | function () { 53 | test.log("All registered."); 54 | test.log("Serializer ID: " + session._socket.serializer.SERIALIZER_ID); 55 | 56 | var pl2 = []; 57 | 58 | var vals1 = [1.7, "hello", [1, 2, -3], {a: 5, b: "hello2"}, [-9007199254740991, 9007199254740991], null]; 59 | 60 | for (var i = 0; i < vals1.length; ++i) { 61 | 62 | pl2.push(session.call('com.myapp.echo', [vals1[i]]).then( 63 | function (res) { 64 | test.log("Result:", res); 65 | }, 66 | function (err) { 67 | test.log("Error:", err.error, err.args, err.kwargs); 68 | } 69 | )); 70 | } 71 | 72 | autobahn.when.all(pl2).then(function () { 73 | test.log("All finished."); 74 | connection.close(); 75 | 76 | var chk = test.check(); 77 | testcase.ok(!chk, chk); 78 | testcase.done(); 79 | }); 80 | }, 81 | function () { 82 | test.log("Registration failed!", arguments); 83 | } 84 | ); 85 | }; 86 | 87 | connection.open(); 88 | }; 89 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_serialization_msgpack.txt: -------------------------------------------------------------------------------- 1 | 0 "Connected" 2 | 1 "All registered." 3 | 2 "Serializer ID: msgpack" 4 | 3 "Result:" 1.7 5 | 4 "Result:" "hello" 6 | 5 "Result:" [1,2,-3] 7 | 6 "Result:" {"a":5,"b":"hello2"} 8 | 7 "Result:" [-9007199254740991,9007199254740991] 9 | 8 "Result:" null 10 | 9 "All finished." 11 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_util_is_object.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Unit test to make sure objects from vm instances also pass object checks 3 | */ 4 | 5 | var autobahn = require('../index.js'); 6 | var testutil = require('./testutil.js'); 7 | var vm = require('vm'); 8 | 9 | // It should pass for objects 10 | exports.utilIsObjectSucceed = function (testcase) { 11 | testcase.expect(1); 12 | var test = new testutil.Testlog("test/test_util_is_object_success.txt"); 13 | const obj = {foo: 'bar'}; 14 | var isObj = autobahn.util.is_object(obj); 15 | test.log(isObj); 16 | var chk = test.check(); 17 | testcase.ok(!chk, chk); 18 | testcase.done(); 19 | }; 20 | 21 | // It should fail for scalars and arrays 22 | exports.utilIsObjectFail = function (testcase) { 23 | testcase.expect(1); 24 | const invalids = [1, [], 'string']; 25 | var test = new testutil.Testlog("test/test_util_is_object_fail.txt"); 26 | for (var k in invalids) { 27 | var obj = invalids[k]; 28 | var isObj = autobahn.util.is_object(obj); 29 | test.log(isObj); 30 | } 31 | var chk = test.check(); 32 | testcase.ok(!chk, chk); 33 | testcase.done(); 34 | }; 35 | 36 | 37 | exports.utilIsObjectVmFail = function (testcase) { 38 | testcase.expect(1); 39 | var context = {kwargs: {foo: 'bar'}, isObj: false}; 40 | vm.createContext(context); 41 | var code = 'kwargs.baz = \'bax\'; isObj = kwargs instanceof Object'; 42 | vm.runInContext(code, context); 43 | testcase.ok(!context.isObj, 'instanceof checks inside VMs should fail'); 44 | testcase.done(); 45 | }; 46 | 47 | // It should pass for checks executed in a VM 48 | exports.utilIsObjectVmSucceed = function (testcase) { 49 | testcase.expect(1); 50 | var test = new testutil.Testlog("test/test_util_is_object_vm.txt"); 51 | var context = { 52 | kwargs: {foo: 'bar'}, 53 | util: autobahn.util, 54 | check1: null, 55 | check2: null 56 | }; 57 | vm.createContext(context); 58 | var code = 'kwargs.baz = \'bax\'; check1 = kwargs instanceof Object; check2 = util.is_object(kwargs);'; 59 | vm.runInContext(code, context); 60 | test.log(context.check1); 61 | test.log(context.check2); 62 | var chk = test.check(); 63 | testcase.ok(!chk, chk); 64 | testcase.done(); 65 | }; 66 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_util_is_object_fail.txt: -------------------------------------------------------------------------------- 1 | 0 false 2 | 1 false 3 | 2 false 4 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_util_is_object_success.txt: -------------------------------------------------------------------------------- 1 | 0 true 2 | -------------------------------------------------------------------------------- /packages/autobahn/test/test_util_is_object_vm.txt: -------------------------------------------------------------------------------- 1 | 0 false 2 | 1 true 3 | --------------------------------------------------------------------------------