R sync server for Automerge CRDT documents. Implements the automerge-repo WebSocket protocol, enabling R to serve as a synchronization hub for Automerge clients in R, JavaScript, Rust, and other languages.
Features
- Full
automerge-repoprotocol compatibility (interoperates with sync.automerge.org) - Secure connections via TLS (wss://)
- Persistent document storage
- Ephemeral message broadcasting
- Client functions for fetching documents from remote servers
Installation
pak::pak("shikokuchuo/autosync")Server
Create a WebSocket sync server:
library(autosync)
server <- amsync_server(port = 3030)
server$start()
# Server runs non-blocking in the background
server$close()With TLS for secure connections:
cert <- nanonext::write_cert()
tls <- nanonext::tls_config(server = cert$server)
server <- amsync_server(port = 8080, tls = tls)
server$start()Authentication
Enable Google OAuth2 authentication to restrict access:
cert <- nanonext::write_cert()
tls <- nanonext::tls_config(server = cert$server)
server <- amsync_server(
port = 3030,
tls = tls, # TLS required when auth is enabled
auth = auth_config(allowed_domains = "posit.co")
)
server$start()Clients must provide an access token:
token <- amsync_auth() # Interactive OAuth flow
tlsclient <- nanonext::tls_config(client = cert$client)
doc <- amsync_fetch(
"wss://127.0.0.1:3030",
"doc-id",
access_token = token,
tls = tlsclient
)Document management
# Create a new document
doc_id <- create_document(server)
# List all documents
list_documents(server)
# Get a document
doc <- get_document(server, doc_id)Client
Fetch documents from any automerge-repo sync server:
# Fetch from public sync server
doc <- amsync_fetch("wss://sync.automerge.org", "your-document-id")
# Inspect document structure
str(doc)
# Or verbose fetch for debugging sync issues
doc <- amsync_fetch("wss://sync.automerge.org", "your-document-id", verbose = TRUE)Shiny Collaborative Editor
For a real-time collaborative text editor widget, see the autoedit package which provides a CodeMirror-based editor that connects to autosync servers.
Links
- automerge - R bindings for Automerge CRDT