Skip to content

Commit

Permalink
Update client documentation (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart authored Dec 9, 2024
1 parent 4c5947a commit c4d6d06
Showing 1 changed file with 5 additions and 6 deletions.
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

0 comments on commit c4d6d06

Please sign in to comment.