Search code examples
eventsfirefox-os

Broadcast events in Firefox OS


I am wondering if there is a way for a Firefox OS app to broadcast an event to all other apps and for the interested apps to hook on that event and trigger a corresponding action.

An example of use case I have in mind: the Camera app broadcasts the event "picture taken" and another app hooks on this event and take some action on the new picture that has been taken (for example, uploads it to a server).


Solution

  • There's not currently a web API in Firefox OS to broadcast events to all open and/or interested apps.

    For your particular use-case of apps being notified when a new photo is taken by Camera, the best approach is probably to open DeviceStorage for "pictures" and listen to "change" events.

    Documentation for this is at:

    https://developer.mozilla.org/en-US/docs/Web/API/DeviceStorage

    Alternatives exist but are more restricted functionally, and available in fewer releases and contexts:

    Note: For every example here, your app would have to be running for it to work. There's no mechanism for waking an app up when a specific action or event occurs. Web Activities is the closest API for event-specific app loading. Timers API is for non-specific app loading.