Last active
August 29, 2015 14:20
-
-
Save Davidsoff/decc81b069d8be789889 to your computer and use it in GitHub Desktop.
ding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var autobahn = require("autobahn"); | |
module.exports = new autobahn.Connection({ | |
url: "ws://188.226.208.149:3000/", | |
realm: "realm" | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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