Connects to an automerge-repo sync server and retrieves a document by ID. This is useful for debugging sync issues or fetching documents from remote servers like sync.automerge.org.
Arguments
- url
WebSocket URL of the sync server (e.g., "ws://localhost:3030/" or "wss://sync.automerge.org/"). Note: trailing slash may be required.
- doc_id
Document ID (base58check encoded string)
- timeout
Timeout in milliseconds for each receive operation. Default 5000.
- tls
(optional) for secure wss:// connections to servers with self-signed or custom CA certificates, a TLS configuration object created by
nanonext::tls_config().- verbose
Logical, print debug messages. Default FALSE.
Details
The function implements the automerge-repo sync protocol:
Connects via WebSocket
Sends join message with peer ID
Receives peer response from server
Sends sync request for the specified document
Receives and applies sync messages until complete
Sync is considered complete when no new messages arrive within the timeout after at least one sync round.
Examples
if (FALSE) { # interactive()
# Fetch from public sync server
doc <- amsync_fetch("wss://sync.automerge.org", "4F63WJPDzbHkkfKa66h1Qrr1sC5U")
# Fetch from local server with debug output
doc <- amsync_fetch("ws://localhost:3030", "myDocId", verbose = TRUE)
# Fetch from server with self-signed certificate
cert <- nanonext::write_cert()
tls <- nanonext::tls_config(client = cert$client)
doc <- amsync_fetch("wss://localhost:3030", "myDocId", tls = tls)
# Inspect the document
automerge::am_keys(doc)
}