WebAPI/Inter App Communication Alt proposal: Difference between revisions

No edit summary
Line 91: Line 91:
== Lockscreen and Music ==
== Lockscreen and Music ==


(Disclaimer: this is just a rough example of a possible solution for this use case. This can probably be done with an unique keyword and an agreed bidirectional API, but I wanted a wider example)
(Disclaimer: this is just a rough example of a possible solution for this use case. This can probably be done with an unique keyword, different access rules and an agreed bidirectional API, but I wanted a wider example)


The lockscreen wants to be able to:  
The lockscreen wants to be able to:  
Line 177: Line 177:
The Lockscreen, in this example, wants to control '''only''' the music from the Gaia Music app (certified and with a known origin). Once the lockscreen is ready it sends a connection request of this kind:
The Lockscreen, in this example, wants to control '''only''' the music from the Gaia Music app (certified and with a known origin). Once the lockscreen is ready it sends a connection request of this kind:


  connect('musicremotecontrol').then(function onConnectionAccepted(ports) {
  connect('musicremotecontrol').then((function onConnectionAccepted(ports) {
   ...
   if (ports.length > 1) {
    // We shouldn't be here as we only want to communicate with the Gaia Music app.
    return;
  }
 
  let musicPort = ports[0];
  this.madeUpPlayButton.onclick = function() {
    musicPort.postMessage({
      action: 'play'
    });
  };
  this.madeUpPauseButton.onclick = function() {
    musicPort.postMessage({
      action: 'pause'
    });
  };
  this.madeUpStopButton.onclick = function () {
    musicPort.postMessage({
      action: 'stop'
    });
  };
  }, function onConnectionRejected(reason) {
  }, function onConnectionRejected(reason) {
   ...
   ...
  }, {
  }, {
   origin: ['music.gaiamobile.org']
   origin: ['music.gaiamobile.org']
  });
  }).bind(this));


If no previous connection through the 'musicremotecontrol' keyword between the Lockscreen and the Gaia Music app has been previously allowed an UI is shown to the user with a message like:
If no previous connection through the 'musicremotecontrol' keyword between the Lockscreen and the Gaia Music app has been previously allowed an UI is shown to the user with a message like:
Line 204: Line 224:
   }
   }
  });
  });
'''TODO'''


== Other use case ==
== Other use case ==
Confirmed users
483

edits