Broadcasting events in Firefox OS
I am wondering if there is a way for a Firefox OS application to broadcast the event to all other applications and for interested applications to connect to that event and trigger the appropriate action.
A use case I mean: the Camera application broadcasts a "captured image" event, and another application intercepts this event and takes some action on the new image that was taken (for example, uploading it to the server).
source to share
Currently, the web API in Firefox does not exist to broadcast events to all open and / or interested applications.
For your specific application notification use case, when the camera takes a new photo, the best way is to open DeviceStorage for "pictures" and listen for "change" events.
Documentation for this:
https://developer.mozilla.org/en-US/docs/Web/API/DeviceStorage
There are alternatives, but they are more limited in functionality and available in fewer editions and contexts:
-
The system can broadcast messages, but only certified applications can be listened to. https://developer.mozilla.org/en-US/docs/Web/API/Navigator.mozSetMessageHandler
-
The InterAppCommunication API allows web applications to communicate to one or more other applications, but is more tightly coupled than generic communication. However, this API has not yet been standardized and is only available for certified applications. https://bugzilla.mozilla.org/show_bug.cgi?id=876397
-
Access to system settings is coming soon for uncertified applications and could possibly be used to do so, but this is a hacky way of doing messaging and data exchange. https://developer.mozilla.org/en-US/docs/Web/API/SettingsManager
Note. For each example here, your application must be working for it to work. There is no mechanism for waking up the application when a certain action or event occurs. Web Activity is the closest API for loading applications on specific events. The timer API is intended for non-specific application loading.
source to share
From this article [1]:
Application authors can create an application that will handle one or more actions. This means that the application will be called by another application to perform certain actions defined by this activity. For example, let's pretend we want to create a photo manager. It can be used by another application to select a photo. As an activity handler, our application will become part of another application workflow.
[1] https://developer.mozilla.org/en-US/docs/Web/API/Web_Activities
source to share