rx.wamp
A Reactive wrapper library for the autobahn wamp v1/v2 library in the browser/node
If you have been using below version 0.2.0 please see below for important API changes!
Installation
Regular browser
<script type="application/javascript" src="javascripts/lib/autobahn.js"></script><script type="application/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/2.3.22/rx.lite.js"></script><script type="application/javascript" src="javascripts/rx.wamp.js" ></script>
RequireJS
;
NodeJS
var rxwamp = ; //Do stuff with the autobahn//This works for both versions, though realm is only required in version 2RxObservable ;
Connection
{ console;} var connectionSubscription = RxObservable ; //Close our current connection and don't retryconnectionSubscription;
Subscribing to topics
{ return valueargs && valueargslength > 1;} { return valueargs1;} //You may optionally pass in an observer to listen for the subscription completingvar openObserver = RxObserver; var topic = RxObservable; //Do all the normal reactive operations on itvar topicSubscription = topic ; //Unsubscribe from topic, you will no longer receive updates from this topictopicSubscription;
New in version 0.3!
You can now pass your connection observable directly into your subscription so that it will persist across sessions
RxObservable;
New in version 0.5!
You can now use an even shorter-hand for subscription. These will automatically persist across sessions if you use the
fromConnection()
overload.
var connection = RxObservable; //You can subscribe to as many items as you wantvar subscriber = RxObservable ; //You may cancel all of the items with one command as wellsubscriber;
Publishing to topic
//Version 2var published = RxObservable; //Version 1 - OverloadsRxObservable;RxObservable;RxObservable;
Or use them together
//Surfaces a subject which can do both publication and subscriptionvar topic = RxObservable; //When the topic successfully subscribes it is surfaced through the 'opened' propertytopicopened; //Errors in publishing are surfaced through the 'errors' propertytopicerrors; //subscribe to the observertopic; //publish to the observerRxObservable ;
Registering methods
Note that this will only work in version 2
{ if args === undefined || argslength < 1 throw "No values to sum!"; else if argslength > 2 throw "Too many values!"; else return args0 + args1; } { //This will get called for all errors.} var registration = RxObservable //This will bubble up all errors that occur either //during registration or unregistration. ; //Unregisterregistration;
New in version 0.3!
You can now pass your connection observable directly into your registration so that it will persist across sessions
var connection = RxObservable; RxObservable;
Calling methods
We can call methods, like the one in the example above, as well.
var caller = session; //Version 2 ; //Resubscribing will yield the cached resultaddResult; //Version 1 ;
Authentication
Currently only available in V1
//In this case the *this* of the onchallenge function will be the session.RxObservable;
Advanced
Weather Station Monitor
//listen for sensor readingsvar sensorReadings = RxObservable; //A remote service for analyzing our readings, it might be aggregating across several different sourcesvar analyzer = RxObservable; //Home control settingsvar desiredTemperature = RxObservable; var dailyForecast = sensorReadings // At most once every second //Milliseconds in a day ; //Warn of inclement weather coming in dailyForecast //only get warnings //Publish it to our klaxon service to warn everyone on the block ; //Notify the climate control to turn offdailyForecast ; //Create a pipeline of distributed computationvar adder = sessioncaller"wamp.my.add";var multiplier = sessioncaller"wamp.my.multiply"; //Somewhat contrived but you get the ideavar pipeline = ; pipeline
TODO
- [Major]
Implement cross-platform compatibility (currently only works in node) - [Major] Bug fixing
- [Major] Improve API semantics and readability
- [Major] Push to cdn platforms (
npm/bower/cdnjs or microjs). - [Minor]
Add v1 backward compatibility