This repository contains two plugins:
plugin-sync-ipc: This plugin instantiates a Twilio Sync client and exposes it to other plugins via the actions framework, using a newSyncDocIPCaction.plugin-sync-things: This plugin has no Twilio Sync client, but accesses and manipulates data in Sync via theSyncDocIPCaction exposed byplugin-sync-ipc. As a simple example of usage, this plugin stores each worker's current activity in a Sync doc, and logs the data from Sync before and after each operation to the browser console.
This pattern takes advantage of a few behaviors of the Flex actions framework:
- Action callbacks can modify the action payload
afteraction listeners receive the modified payload- By
awaiting an action invocation, allbeforeandafteraction listeners have executed (assuming they didn't also execute async code withoutawaiting it)
Using these three behaviors, we can access Sync via actions by performing the following:
- The single plugin that is running the Sync client registers an action for other plugins to invoke (called
SyncDocIPC). The action callback will call the Sync client to perform get/update/close operations, and updatepayload.datawith the data from Sync. - Each plugin that needs to use Sync registers an
afterSyncDocIPCaction listener to receive the updatedpayload.datavalue and store it in a cache - To perform Sync operations, the plugin invokes the
SyncDocIPCaction andawaits its completion - The cache object is accessed to retrieve the result
This software is to be considered "sample code", a Type B Deliverable, and is delivered "as-is" to the user. Twilio bears no responsibility to support the use or implementation of this software.