Skip to content

Instantly share code, notes, and snippets.

@Davidsoff
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Davidsoff/decc81b069d8be789889 to your computer and use it in GitHub Desktop.
Save Davidsoff/decc81b069d8be789889 to your computer and use it in GitHub Desktop.
ding
var autobahn = require("autobahn");
module.exports = new autobahn.Connection({
url: "ws://188.226.208.149:3000/",
realm: "realm"
});
'use strict';
var React = require('react');
var WampMixin = {
componentWillMount: function() {
this.subscriptions = [];
},
subscribe: function(topic, cb){
var component = this;
if(typeof connection.session === 'object'){
connection.session.subscribe(topic, cb)
.then(
function(sub){
component.subscriptions.push(sub);
},
function(err){
console.log(err);
}
);
}
},
publish: function(topic, args){
if(typeof connection.session === 'object'){
connection.session.publish(topic, args);
}
},
call: function(procedure, args, cb){
if(typeof connection.session === 'object'){
connection.session.call(procedure, args)
.then(
function(result){
cb(result);
},
function(err){
console.log(err);
}
);
}
},
componentWillUnmount: function(){
this.subscriptions.map(
function(sub){
connection.session.unsubscribe(sub)
.then(
function(gone){},
function(error){
console.dir(error);
}
);
}
);
}
};
module.exports = WampMixin;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment