Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update client documentation #91

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions docs/usage/client.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
A client connects their `YDoc` through a [WebsocketProvider](../reference/WebSocket_provider.md).
A client connects their `Doc` through a [WebsocketProvider](../reference/WebSocket_provider.md).

Here is a code example using the [websockets](https://websockets.readthedocs.io) library:
```py
import asyncio
import y_py as Y
from websockets import connect
from pycrdt import Doc, Map
from pycrdt_websocket import WebsocketProvider

async def client():
ydoc = Y.YDoc()
ydoc = Doc()
ymap = ydoc.get("map", type=Map)
async with (
connect("ws://localhost:1234/my-roomname") as websocket,
WebsocketProvider(ydoc, websocket),
):
# Changes to remote ydoc are applied to local ydoc.
# Changes to local ydoc are sent over the WebSocket and
# broadcast to all clients.
ymap = ydoc.get_map("map")
with ydoc.begin_transaction() as t:
ymap.set(t, "key", "value")
ymap["key"] = "value"

await asyncio.Future() # run forever

Expand Down
Loading