Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class NAV {
- constructor(name, url="ws://localhost:8080/ws", realm="realm1"){
- this.name = name;
- this.url = url;
- this.realm = realm;
- this.channel = 'org.nav.modules.' + this.name;
- this.connection = new autobahn.Connection({
- url: this.url,
- realm: this.realm
- });
- this.connection.onopen = (session => this.on_open(session))
- this.connection.open()
- }
- on_open(session){
- this.session = session;
- this.session.subscribe(this.channel, this.on_message);
- this.session.publish('org.nav.announce', [this.name]);
- }
- on_message(message){
- console.log("THIS ON MESSAGE")
- console.log(message);
- }
- send_command(target, subject, payload={}){
- this.session.publish(this.channel, [{
- type: 'command',
- target: target,
- subject: subject,
- payload: payload
- }])
- }
- }
- var nav = new NAV('test_module');
- setTimeout(function(){
- nav.send_command('testplayer', 'pause');
- }, 3000);
- setTimeout(function(){
- nav.send_command('testplayer', 'resume');
- }, 6000);
Advertisement
Add Comment
Please, Sign In to add comment