riccardocagnasso

Untitled

Jun 11th, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class NAV {
  2.     constructor(name, url="ws://localhost:8080/ws", realm="realm1"){
  3.         this.name = name;
  4.         this.url = url;
  5.         this.realm = realm;
  6.         this.channel = 'org.nav.modules.' + this.name;
  7.  
  8.         this.connection = new autobahn.Connection({
  9.            url: this.url,
  10.            realm: this.realm
  11.         });
  12.  
  13.         this.connection.onopen = (session => this.on_open(session))
  14.         this.connection.open()
  15.     }
  16.  
  17.     on_open(session){
  18.         this.session = session;
  19.         this.session.subscribe(this.channel, this.on_message);
  20.         this.session.publish('org.nav.announce', [this.name]);
  21.     }
  22.  
  23.     on_message(message){
  24.         console.log("THIS ON MESSAGE")
  25.         console.log(message);
  26.     }
  27.  
  28.     send_command(target, subject, payload={}){
  29.         this.session.publish(this.channel, [{
  30.             type: 'command',
  31.             target: target,
  32.             subject: subject,
  33.             payload: payload
  34.         }])
  35.     }
  36. }
  37.  
  38. var nav = new NAV('test_module');
  39.  
  40. setTimeout(function(){
  41.     nav.send_command('testplayer', 'pause');
  42. }, 3000);
  43.  
  44. setTimeout(function(){
  45.     nav.send_command('testplayer', 'resume');
  46. }, 6000);
Advertisement
Add Comment
Please, Sign In to add comment