1.2.0 • Published 3 years ago

crowbarjs v1.2.0

Weekly downloads
39
License
-
Repository
gitlab
Last release
3 years ago

crowbarjs

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, the features are limited to only the ones that were needed.

Installation

npm install crowbarjs
npm install rxjs
npm install ws // only when using with Node

Usage

import {Client} from "crowbarjs";

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

Call

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

Register

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

wamp.topic('example.topic').subscribe((v)=>console.log(v));

Angular Example

Create a wamp service

import {Injectable} from '@angular/core';
import {Client} from 'crowbarjs';

@Injectable()
export class WampService extends Client {
    constructor() {
        super('wss://demo.crossbar.io/ws', '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 'crowbarjs/src/Messages/EventMessage';

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

    constructor(private wamp: WampService) {}
}

Node Example

const Thruway = require("crowbarjs");
const Rx = require("rxjs");

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

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

3 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.3

4 years ago

1.0.0

4 years ago