Ypy-websocket
Ypy-websocket 是一个用于 Ypy 的异步 WebSocket 连接器。
文档: https://hellowac.github.io/ypy-websocket-zh-cn
源代码: https://github.com/y-crdt/ypy-websocket
Ypy-websocket 是一个用于构建 WebSocket 服务器和客户端的 Python 库,能够连接并同步共享文档。它可用于创建协作式 Web 应用程序。
以下图表展示了典型的架构。目标是将文档共享给多个客户端。
每个客户端都有一个 YDoc 实例,代表其对文档的视图。共享文档还在服务器端的 room 中存在。从概念上讲,房间可以看作是客户端协作编辑文档的地方。客户端连接的 WebSocket 通过端点路径指向相应的房间。在下面的示例中,客户端 A 和 B 连接到路径为 room-1
的 WebSocket,因此这两个客户端都位于名为 room-1
的房间中。所有 YDoc
的同步逻辑由 WebsocketProvider 处理。
对共享文档的每次更新都可以使用 store 持久化到磁盘,存储可以是文件或数据库。
flowchart TD
classDef room1 fill:#f96
classDef room2 fill:#bbf
A[客户端 A<br>房间-1]:::room1 <-->|WebSocket<br>提供者| server(服务器 WebSocket)
B[客户端 B<br>房间-1]:::room1 <-->|WebSocket<br>提供者| server
C[客户端 C<br>房间-2]:::room2 <-->|WebSocket<br>提供者| server
D[客户端 D<br>房间-2]:::room2 <-->|WebSocket<br>提供者| server
server <--> room1((房间-1<br>客户端: A, B)):::room1
server <--> room2((房间-2<br>客户端: C, D)):::room2
A <-..-> room1
B <-..-> room1
C <-..-> room2
D <-..-> room2
room1 ---> store1[(存储)]
room2 ---> store2[(存储)]
Ypy-websocket is an async WebSocket connector for Ypy.
Documentation: https://davidbrochart.github.io/ypy-websocket
Source Code: https://github.com/y-crdt/ypy-websocket
Ypy-websocket is a Python library for building WebSocket servers and clients that connect and synchronize shared documents. It can be used to create collaborative web applications.
The following diagram illustrates a typical architecture. The goal is to share a document among several clients.
Each client has an instance of a YDoc, representing their view of a document. A shared document also lives in a room on the server side. Conceptually, a room can be seen as the place where clients collaborate on a document. The WebSocket to which a client connects points to the corresponding room through the endpoint path. In the example below, clients A and B connect to a WebSocket at path room-1
, and thus both clients find themselves in a room called room-1
. All the YDoc
synchronization logic is taken care of by the WebsocketProvider.
Each update to a shared document can be persisted to disk using a store, which can be a file or a database.
flowchart TD
classDef room1 fill:#f96
classDef room2 fill:#bbf
A[Client A<br>room-1]:::room1 <-->|WebSocket<br>Provider| server(WebSocket Server)
B[Client B<br>room-1]:::room1 <-->|WebSocket<br>Provider| server
C[Client C<br>room-2]:::room2 <-->|WebSocket<br>Provider| server
D[Client D<br>room-2]:::room2 <-->|WebSocket<br>Provider| server
server <--> room1((room-1<br>clients: A, B)):::room1
server <--> room2((room-2<br>clients: C, D)):::room2
A <-..-> room1
B <-..-> room1
C <-..-> room2
D <-..-> room2
room1 ---> store1[(Store)]
room2 ---> store2[(Store)]