Thruway.js Save

RxJS WAMPv2 Client

Project README

Build Status


This project is a WAMP v2 client written in TypeScript that uses RxJS v5 Observables instead of promises and event emitters. It's designed to work with modern frontend frameworks like Angular v2/4 as well as node.js.

If you don't know what WAMP is, you should read up on it.

If you don't know what RxJS or ReactiveExtensions is, you're missing out...

note: This library is stable, but may not have all of the WAMP features implemented. Since this project originated as an internal project for Voryx, the features are limited to only the ones that were needed.


npm install thruway.js
npm install rxjs
npm install ws // only when using with Node


import {Client} from "thruway.js";

const wamp = new Client('ws://localhost:9090', 'realm1');

Call'add.rpc', [1, 2])
    .map((r: ResultMessage) => r.args[0])
    .subscribe(r => console.log(r));


wamp.register('add.rpc', (a, b) => a + b).subscribe();

If you need keyword arguments, you can set the extended option.

wamp.register('add.rpc', (args, argskw) => argskw.a + argskw.b, {extended: true}).subscribe();

Publish to topic

wamp.publish('example.topic', 'some value');
wamp.publish('example.topic', Observable.interval(1000)); // you can also publish an observable

Subscribe to topic


Angular Example

Create a wamp service

import {Injectable} from '@angular/core';
import {Client} from 'thruway.js';

export class WampService extends Client {
    constructor() {
        super('wss://', 'realm1');

Inject and use the service in your component

import {Component} from '@angular/core';
import {WampService} from '../wamp.service';
import {Observable} from 'rxjs/Observable';
import {EventMessage} from 'thruway.js/src/Messages/EventMessage';

    selector: 'app-counter',
    template: '<span>{{counter | async}}</span>'
export class CounterComponent {
    counter: Observable<number> = this.wamp
        .map((r: EventMessage) => r.args[0]);

    constructor(private wamp: WampService) {}

Node Example

const Thruway = require("thruway.js");
const Rx = require("rxjs");

const wamp = new Thruway.Client('wss://', 'realm1');

wamp.publish('com.myapp.counter', Rx.Observable.interval(1000));

PHP Example

Install the RxThruway Client

composer require rx/thruway-client


use Rx\Observable;
use Rx\Thruway\Client;

require __DIR__ . '/vendor/autoload.php';

$wamp = new Client('wss://', 'realm1');

$wamp->publish('com.myapp.counter', Observable::interval(1000));
Open Source Agenda is not affiliated with "Thruway.js" Project. README Source: voryx/thruway.js
Open Issues
Last Commit
2 months ago

Open Source Agenda Badge

Open Source Agenda Rating