This page is not complete.
This article describes the lifecycle of a social service worker, how the social service lets the browser interact with a social media site, and so forth.
A social service provider is defined by a structured text file (JSON) containing a number of keyed URLs, a name, and an icon. URLs have the same origin as the JSON file if remotely loaded.
The service worker lives until terminated, either by browser shutdown or by an explicit control command from the user.
If the browser determines that termination of the service worker is necessary, all of the service-level content associated with the service worker is unloaded (that is, all
ServiceWindows and sidebars are closed) as part of the termination.
If the browser starts (or restarts) the service during a normal user session, the service worker is fully loaded first, and sidebars are then instantiated on existing windows.
ServiceWindows (such as chats) are not restarted automatically.
This section illustrates how the social service is started up, communicates with the social media site, and shuts down.
<<<add an actual diagram>>>
- The service is registered with a service, sidebar widget, and share widget.
- At browser startup time, the service worker is instantiated.
- The service opens a connection to its service, if a user session is available, and starts receiving push events.
- When a browser window is created, the sidebar widget content is instantiated.
- The sidebar may connect with the background worker by using
- The service worker catches the "hello" message and adds the
sidebarContentWindowto a list of event sinks.
- The sidebar content may then perform more elaborate publish-subscribe handshaking, to limit what events it receives.
- When the service receives events from the server (or from other content), it may communicate those events to any, or all, of the windows by invoking
window.postMessage()on each window reference.
- If the user clicks in the sidebar to, for example, open a chat window,
MozSocial.openChatWindow()is called and a new window is created. The chat window registers with the service by using
mozSocial.getWorker().postMessage("hello")and receives a message back telling it who to open a chat with. The service might then deliver server-pushed events to the chat window, perhaps through a publish-subscribe system.