Confirmed users
483
edits
No edit summary |
|||
| Line 93: | Line 93: | ||
(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 and an agreed bidirectional API, but I wanted a wider example) | ||
The lockscreen wants to be able to control the music played by the Gaia Music app | The lockscreen wants to be able to: | ||
* control the music played by the Gaia Music app | |||
* display information about the currently played track from the Gaia Music app or any other 3rd party music privileged app. | |||
In order to receive information about the currently played music track, the System app needs to add the following 'connect' field to its manifest | In order to receive information about the currently played music track, the System app needs to add the following 'connect' field to its manifest | ||
| Line 108: | Line 110: | ||
where it advertises itself as able to receive connection requests through the 'musictrack' keyword. | where it advertises itself as able to receive connection requests through the 'musictrack' keyword. | ||
On the other side, music apps (lets say the Gaia Music app | On the other side, music apps (lets say the Gaia Music app and a fictitious Songbirdy privileged app installed from the Firefox Marketplace and an also fictitious iTunos unprivileged app installed from an unknown source) that wants to be controlled from the lockscreen should add the following 'connect' field to its manifest: | ||
{ | { | ||
'name': 'Music', (or Songbirdy or iTunos) | 'name': 'Music', (or Songbirdy or iTunos) | ||
/* ... */ | /* ... */ | ||
'connect': { | 'connect': { | ||
| Line 126: | Line 127: | ||
connect('musictrack').then(function onConnectionAccepted(ports) { | connect('musictrack').then(function onConnectionAccepted(ports) { | ||
// If the connection is allowed at least by one peer, the resolved callback | // If the connection is allowed at least by one peer, the resolved callback | ||
// will be triggered with a list of MessagePorts as | // will be triggered with a list of MessagePorts as parameter (ports in this case). | ||
// At this point the Gaia Music app can start sending information about | // At this point the Gaia Music app can start sending information about | ||
// the currently played track. | // the currently played track. | ||
| Line 136: | Line 137: | ||
// In this example approach, we probably don't need a bidirectional communication | // In this example approach, we probably don't need a bidirectional communication | ||
// as we have that through a different keyword, but we can always set a message | // as we have that through a different keyword, but we can always set a message | ||
// handler via MessagePort.onmessage at this point to handle the | // handler via MessagePort.onmessage at this point to handle the messages sent from | ||
// the peer on the other side of the port. | // the peer on the other side of the port. | ||
port.onmessage = myMessageHandler; | port.onmessage = myMessageHandler; | ||
| Line 150: | Line 151: | ||
Do you want to allow ''Music'' to connect with ''System'' to ''Show the currently played music track information in the lockscreen''? [Allow|Deny] | Do you want to allow ''Music'' to connect with ''System'' to ''Show the currently played music track information in the lockscreen''? [Allow|Deny] | ||
In case that there would be more than one app subscribed to the 'musictrack' keyword, a different UI with a list of these apps would have been shown. | |||
There is no need to show this UI again unless a new app subscribing to 'musictrack' is installed. | |||
The user allows the connection and a system message is sent to the lockscreen. The lockscreen only allows connections with privileged apps, so it checks that in the connection request handler, and set a handler for the messages sent through the MessagePort via ''MessagePort.onmessage'' | The user allows the connection and a system message is sent to the lockscreen. The lockscreen only allows connections with privileged apps, so it checks that in the connection request handler, and set a handler for the messages sent through the MessagePort via ''MessagePort.onmessage'' | ||
| Line 160: | Line 165: | ||
if (connectionRequest.callerInfo.accessLevel !== 'web') { | if (connectionRequest.callerInfo.accessLevel !== 'web') { | ||
connectionRequest.port.onmessage = onMusicTrackHandler; | connectionRequest.port.onmessage = onMusicTrackHandler; | ||
} else { | |||
connectionRequest.reject(); | |||
} | } | ||
}); | }); | ||
A similar connection request coming from Sonbirdy would also be accepted, cause we said that this app is privileged. However a connection request coming from iTunos would be rejected, since this app is unprivileged web content. | |||
=== Music controls in the lockscreen === | === Music controls in the lockscreen === | ||
Assuming that the three example music apps mentioned above are installed, 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). Assuming that the three example music apps mentioned above are installed, 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) { | ||
| Line 171: | Line 180: | ||
}, function onConnectionRejected(reason) { | }, function onConnectionRejected(reason) { | ||
... | ... | ||
}, { | |||
}); | }); | ||