WebSocket server
WebSocket server.
Source code in pycrdt_websocket/websocket_server.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
|
started: Event
property
An async event that is set when the WebSocket server has started.
__init__(rooms_ready=True, auto_clean_rooms=True, log=None)
Initialize the object.
The WebsocketServer instance should preferably be used as an async context manager:
async with websocket_server:
...
task = asyncio.create_task(websocket_server.start())
await websocket_server.started.wait()
...
websocket_server.stop()
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rooms_ready |
bool
|
Whether rooms are ready to be synchronized when opened. |
True
|
auto_clean_rooms |
bool
|
Whether rooms should be deleted when no client is there anymore. |
True
|
log |
Logger | None
|
An optional logger. |
None
|
Source code in pycrdt_websocket/websocket_server.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
|
delete_room(*, name=None, room=None)
Delete a room.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str | None
|
The name of the room to delete (if |
None
|
room |
YRoom | None
|
The room to delete ( if |
None
|
Source code in pycrdt_websocket/websocket_server.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
|
get_room(name)
async
Get or create a room with the given name, and start it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
The room name. |
required |
Returns:
Type | Description |
---|---|
YRoom
|
The room with the given name, or a new one if no room with that name was found. |
Source code in pycrdt_websocket/websocket_server.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
|
get_room_name(room)
Get the name of a room.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
room |
YRoom
|
The room to get the name from. |
required |
Returns:
Type | Description |
---|---|
str
|
The room name. |
Source code in pycrdt_websocket/websocket_server.py
89 90 91 92 93 94 95 96 97 98 |
|
rename_room(to_name, *, from_name=None, from_room=None)
Rename a room.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
to_name |
str
|
The new name of the room. |
required |
from_name |
str | None
|
The previous name of the room (if |
None
|
from_room |
YRoom | None
|
The room to be renamed (if |
None
|
Source code in pycrdt_websocket/websocket_server.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
|
serve(websocket)
async
Serve a client through a WebSocket.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
websocket |
Websocket
|
The WebSocket through which to serve the client. |
required |
Source code in pycrdt_websocket/websocket_server.py
132 133 134 135 136 137 138 139 140 141 142 143 144 |
|
start(*, task_status=TASK_STATUS_IGNORED)
async
Start the WebSocket server.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task_status |
TaskStatus[None]
|
The status to set when the task has started. |
TASK_STATUS_IGNORED
|
Source code in pycrdt_websocket/websocket_server.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
|
start_room(room)
async
Start a room, if not already started.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
room |
YRoom
|
The room to start. |
required |
Source code in pycrdt_websocket/websocket_server.py
75 76 77 78 79 80 81 82 83 84 85 86 87 |
|
stop()
Stop the WebSocket server.
Source code in pycrdt_websocket/websocket_server.py
196 197 198 199 200 201 202 |
|