Store sync
storeSink(store) of @dovetail-ts/warp-drive applies each
feed op. A join with a cursor gets only the ops that it did not see.
Real-time and offline sync for Ember Preview
Dovetail pushes server changes into the WarpDrive store, applies optimistic writes, queues writes when the client is offline, and gives live co-edit in Tiptap through CRDTs, with presence and notifications.
pnpm add @dovetail-ts/ember
This is not a video. Two clients run in this page on an in-page server, with no network.
The store
The server pushes JSON:API documents and delete operations on the store feed of each room. Dovetail upserts them in the WarpDrive store, so each record in each tab shows the server state, with no fetch.
storeSink(store) of @dovetail-ts/warp-drive applies each
feed op. A join with a cursor gets only the ops that it did not see.
A local change shows at once. The server answer rebases it. A reject rolls it back and shows an error.
Offline, writes go to a queue in IndexedDB. One leader tab (Web Locks) sends them when the device is online. Network errors retry with backoff, and a 4xx reject goes to a dead-letter list that the user can retry or discard.
Co-edit
<Dovetail::Editor> co-edits a document of a room through a CRDT, with
remote carets, per-user undo, version history and anchored comments. The engine is
pluggable: one DocEngine interface, three engines.
| Feature | Yjs | Loro | Automerge |
|---|---|---|---|
| Tiptap binding | Yes | Yes | No |
| Remote carets | Yes | Yes | No |
| Per-user undo | Yes | Yes (local changes) | No |
| Version history | Yes | Yes | Yes (engine API) |
| Comment anchors | Yes | Yes | Yes (engine API) |
Yjs is the reference engine. Automerge has no Tiptap binding, because
@automerge/prosemirror makes its own schema. The matrix is in the README of
each engine package.
Presence
The presence components take a presence source and use the Joinery tokens. Each one has a
harness in @dovetail-ts/test-support and Jig stories.
AvatarStack
An avatar for each user, with an online or away dot, and an overflow count.
LiveCursors
The pointers of the peers over any block, with names. A pointer is a fraction of the box, so boxes of other sizes show it at the same place.
Typing
“Ana is typing”. A live region that a screen reader reads at each change.
ConnectionBadge
Online, Reconnecting or Offline · 3 queued.
SyncStatus
Saved, Syncing 3 changes or
Offline: 3 changes wait.
DeadLetters
The writes that the server refused, each with Retry and Discard.
Notifications
A notification is a JSON:API resource on the per-user room of the store feed. One stream feeds toasts, an inbox and activity feeds. Read state is optimistic, so it works offline too.
<Dovetail::ToastBridge> shows new notifications and sync events
(offline, back online, a refused write) in the Joinery Toaster.
<Dovetail::InboxButton> with the unread count, and
<Dovetail::Inbox> with Unread and All tabs, mark as read, archive
and pages of older items.
<Dovetail::ActivityFeed> groups similar events of one actor: “Ana
edited 3 notes”.
Servers
Both servers speak one wire protocol and pass one conformance suite. Each one has the same
auth hooks: getToken() on the client, and authenticate and
authorize(user, room, action) on the server.
| Server | Package | Transports |
|---|---|---|
| Node |
@dovetail-ts/server on npm
|
WebSocket and SSE |
| Rails |
dovetail and dovetail-rails gems
|
ActionCable |
Hosted adapters
| Provider | Package | Supported |
|---|---|---|
| Hocuspocus |
@dovetail-ts/hocuspocus
|
Doc sync and presence |
| Liveblocks |
@dovetail-ts/liveblocks
|
Doc sync, presence and the store feed |
| PartyKit and PartyServer |
@dovetail-ts/partykit
|
Doc sync, presence and the store feed |
| Supabase Realtime |
@dovetail-ts/supabase
|
The store feed and presence |
| Neon Realtime | @dovetail-ts/neon |
The store feed, in Dovetail 1.1 |
Get started
The second command is only for notifications and co-edit.
pnpm add @dovetail-ts/core @dovetail-ts/ember @dovetail-ts/warp-drive @dovetail-ts/transport-ws
pnpm add @dovetail-ts/notifications @dovetail-ts/tiptap @dovetail-ts/crdt-yjs
pnpm add @ember-joinery/ember
Configure the service
import { WebSocketTransport } from '@dovetail-ts/transport-ws'
import { storeSink } from '@dovetail-ts/warp-drive'
await this.dovetail.configure({
transport: () => new WebSocketTransport({ url: 'wss://example.com/dovetail/ws' }),
getToken: () => this.session.token,
user: { id: 'u1', name: 'Ana Lima', color: '#1d4ed8' },
sink: storeSink(this.store),
})
Show a room
import { Editor } from '@dovetail-ts/ember/editor'
<template>
<Editor @room='note:1' @label='Note' as |editor|>
<Dovetail::AvatarStack @presence={{editor.presence}} />
</Editor>
<Dovetail::ConnectionBadge />
<Dovetail::SyncStatus />
</template>
A Node server
pnpm add @dovetail-ts/server
import { createDovetailServer, listen } from '@dovetail-ts/server'
import { authenticate } from './auth' // Null for a blank token. Read “Auth hooks”.
const server = createDovetailServer({
authenticate,
// Only true allows. A doc edit needs 'write'.
authorize: async (user, room, action) => (await canAccess(user, room, action)) === true,
})
await listen(server, { port: 3000, path: '/dovetail' })
A Rails app
bundle add dovetail-rails
bin/rails generate dovetail:install
class Note < ApplicationRecord
broadcasts_dovetail to: ->(note) { "note:#{note.id}" },
attributes: %i[title body updated_at]
end
Start with the introduction of the guide. See each component in the stories. Before production, read the security page.
Ember Workbench
Dovetail is a tool of Ember Workbench. Its components use Joinery, its tests use Harnessed, and its stories use Jig. It has integrations for switchyard, Millwork, Benchdog and Lattice.