Constructs a TabSyncNetwork.
You typically only need one TabSyncNetwork per app, since it can subscribe multiple documents.
Set to true to forward all doc updates over the BroadcastChannel, not just local operations.
The name of the BroadcastChannel to use. Default: "@collabs/tab-sync".
The name of this class's BroadcastChannel, set in the constructor.
Default: "@collabs/tab-sync".
Closes our BroadcastChannel and unsubscribes all documents.
Future subscribe calls will throw an error.
Emits an event, which triggers all the registered event handlers.
Event handlers are called in the order they are added. Errors in
event handlers are captured and logged (with console.error
),
not propagated to the caller.
Name of the event to emit.
Event object to pass to the event handlers.
Registers an event handler that is triggered when the event happens.
Name of the event to listen on.
Callback that handles the event.
If true, the event handler is triggered at most once (the next time the event happens), then unsubscribed.
An "off" function that removes the event handler when called.
Registers an event handler that is triggered when the event happens.
An "off" function that removes the event handler when called.
Subscribes doc
to updates for docID
.
doc
will send and receive updates with other tabs
that are subscribed to docID
. It will also sync initial states with
other tabs, to ensure that they start up-to-date.
The document to subscribe.
An arbitrary string that identifies which updates to use.
Unsubscribes doc
from its subscribed docID
(if any).
doc
will no longer send or receive updates with other tabs.
Generated using TypeDoc
Syncs updates to Collabs documents across different tabs for the same origin, using BroadcastChannel.
By default, this only forwards local operations to other tabs. Updates from other sources (e.g., a remote server via @collabs/ws-client) are not sent over the BroadcastChannel, since we expect that other tabs will get a copy from their own sources. You can override this with the
allUpdates
constructor option.Likewise, our other providers do not forward or store operations from TabSyncNetwork. Instead, it is expected that each tab sets up its own providers to forward/store updates.