Skip to content
OpenVireoDeveloper
GitHub

Live updates

React to changes from other devices and to access changes.

The sync server keeps an events stream open to each signed-in device, so apps can react as soon as another device uploads a vault or someone changes who may open what.

const live = account.subscribe({
onVaultChanged: (e) => {
// another device uploaded (or deleted) a vault this account can open
if (e.vaultId === vault.id && e.etag !== vault.etag) void vault.sync({ localChanged: false });
},
onVaultsChanged: (vaults) => render(vaults), // access changed: vaults added, removed or re-keyed
onError: (e) => console.warn("events", e),
});
live.close(); // when the app no longer needs it
  • onVaultChanged gets { kind: "vaultChanged", vaultId, etag, revision, deleted }. Compare etag with vault.etag to skip your own uploads.
  • When the account is scheduled for deletion or erased elsewhere, subscribe closes the stream and signs this device out (onSignedOut reports deletion_scheduled or account_deleted; the latter also forgets the Secret Key).
  • On an access change (a grant, a revoke, a key rotation, an organisation change), subscribe refreshes the access token so it lists the new vaults, reloads the vault list, reconnects the stream, and then calls onVaultsChanged.
  • The stream reconnects on its own after network errors, with backoff, and when the access token expires.

Events are a hint, not a guarantee: a device that was offline misses them. Sync on start-up and when the app comes back to the foreground too, with vault.sync({ localChanged: false }), which costs one HEAD when nothing changed.

For a self-hosted server, server.events({ onEvent }) gives the same stream with database events.