Confirmed users
483
edits
No edit summary |
|||
Line 163: | Line 163: | ||
} | } | ||
if (connectionRequest.callerInfo.accessLevel | if (connectionRequest.callerInfo.accessLevel === 'certified' || | ||
connectionRequest.callerInfo.accessLevel === 'privileged') { | |||
connectionRequest.port.onmessage = onMusicTrackHandler; | connectionRequest.port.onmessage = onMusicTrackHandler; | ||
} else { | } else { | ||
Line 174: | Line 175: | ||
=== Music controls in the lockscreen === | === Music controls in the lockscreen === | ||
The | 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) { | ||
Line 181: | Line 182: | ||
... | ... | ||
}, { | }, { | ||
origin: ['music.gaiamobile.org'] | |||
}); | }); | ||
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: | |||
'Do you want to allow System to communicate with Music to Play, pause and stop music tracks? [Accept|Reject]' | |||
Even if Songbirdy and iTunos advertise themselves as able to connect through the 'musicremotecontrol' keyword, as the request is done with a specific rule that requires the receiver to have the 'music.gaiamobile.org' origin, these apps won't be listed in the above UI and won't receive any connection request. | |||
The user allows that connection and a system message is sent to the Music app. This app only wants to be controlled only by certified apps, so it checks for this kind of applications. | |||
navigator.setMessageHandler('connect', function(connectionRequest) { | |||
if (connectionRequest.keyword !== 'musicremotecontrol') { | |||
return; | |||
} | |||
if (connectionRequest.callerInfo.accessLevel === 'certified') { | |||
connectionRequest.port.onmessage = onMusicRemoteControlHandler; | |||
} else { | |||
connectionRequest.reject(); | |||
} | |||
}); | |||
'''TODO''' | '''TODO''' |