snapshot of https://github.com/ueberdosis/hocuspocus.git @ cf3cfa355b4d3bb61c6b6c80071f71783e32470e (2026-09-15)
Some checks failed
build / lint (22) (push) Failing after 17s
build / test (22) (push) Failing after 8s
build / lint (23) (push) Failing after 2s
build / build (22) (push) Has been skipped
build / build (23) (push) Has been skipped
build / test (23) (push) Failing after 4s
docsearch / docsearch (push) Failing after 1s
Some checks failed
build / lint (22) (push) Failing after 17s
build / test (22) (push) Failing after 8s
build / lint (23) (push) Failing after 2s
build / build (22) (push) Has been skipped
build / build (23) (push) Has been skipped
build / test (23) (push) Failing after 4s
docsearch / docsearch (push) Failing after 1s
This commit is contained in:
71
packages/provider/README.md
Normal file
71
packages/provider/README.md
Normal file
@@ -0,0 +1,71 @@
|
||||
# @hocuspocus/provider
|
||||
[](https://www.npmjs.com/package/@hocuspocus/provider)
|
||||
[](https://npmcharts.com/compare/tiptap?minimal=true)
|
||||
[](https://www.npmjs.com/package/@hocuspocus/provider)
|
||||
[](https://github.com/sponsors/ueberdosis)
|
||||
|
||||
The client-side provider for [Hocuspocus](https://github.com/ueberdosis/hocuspocus). Connects to a Hocuspocus server over WebSockets and syncs one or more [Y.js](https://github.com/yjs/yjs) documents — including awareness (presence), authentication, and stateless messaging.
|
||||
|
||||
> **Building a React app?** Use [`@hocuspocus/provider-react`](../provider-react) instead — it wraps the provider in components and hooks so React handles the lifecycle for you (including StrictMode double-mounts).
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
npm install @hocuspocus/provider yjs
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
import * as Y from "yjs"
|
||||
import { HocuspocusProvider } from "@hocuspocus/provider"
|
||||
|
||||
const ydoc = new Y.Doc()
|
||||
|
||||
const provider = new HocuspocusProvider({
|
||||
url: "ws://127.0.0.1:1234",
|
||||
name: "example-document",
|
||||
document: ydoc,
|
||||
})
|
||||
```
|
||||
|
||||
Changes to `ydoc` are now synced to every other client connected to the same `name`.
|
||||
|
||||
### Authenticating
|
||||
|
||||
Pass a `token` — it's forwarded to the server's `onAuthenticate` hook:
|
||||
|
||||
```js
|
||||
new HocuspocusProvider({
|
||||
url: "wss://collab.example.com",
|
||||
name: "example-document",
|
||||
document: ydoc,
|
||||
token: "super-secret-token",
|
||||
})
|
||||
```
|
||||
|
||||
### Sharing a socket across documents
|
||||
|
||||
Create a `HocuspocusProviderWebsocket` once, then reuse it for multiple documents:
|
||||
|
||||
```js
|
||||
import {
|
||||
HocuspocusProvider,
|
||||
HocuspocusProviderWebsocket,
|
||||
} from "@hocuspocus/provider"
|
||||
|
||||
const socket = new HocuspocusProviderWebsocket({ url: "ws://127.0.0.1:1234" })
|
||||
|
||||
const doc1 = new HocuspocusProvider({ websocketProvider: socket, name: "doc-1" })
|
||||
const doc2 = new HocuspocusProvider({ websocketProvider: socket, name: "doc-2" })
|
||||
```
|
||||
|
||||
Call `provider.destroy()` to disconnect a single document. Call `socket.destroy()` to tear down the shared connection.
|
||||
|
||||
## Documentation
|
||||
|
||||
Full configuration, events, and awareness reference: [tiptap.dev/docs/hocuspocus/provider](https://tiptap.dev/docs/hocuspocus/provider/overview).
|
||||
|
||||
## License
|
||||
|
||||
MIT — see [LICENSE.md](https://github.com/ueberdosis/hocuspocus/blob/main/LICENSE.md).
|
||||
Reference in New Issue
Block a user