API
YRoom Consumer
Inherit from this for your own custom consumer implementation.
channels_yroom.consumer.YroomConsumer
Bases: AsyncWebsocketConsumer
connect()
async
Called when the websocket is handshaking as part of initial connection. Override and perform authentication here (see Channels documentation on AsyncWebsocketConsumer).
Call either await self.join_room()
to accept the connection (default implementation)
or await self.close()
to reject.
get_room_name()
Returns the name of the room group to join. This represents the room that the client is joining.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
room group name |
Export Ydoc data via YroomDocument
channels_yroom.proxy.YroomDocument
A proxy object for a Ydoc in the yroom process that allows to export all Ytypes.
__init__(room_name, channel_layer=None)
Instantiate a YroomDocument.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
room_name |
str
|
the room group name chosen by the consumer |
required |
channel_layer |
optional
|
A channel layer. Defaults to default channel layer. |
None
|
export_array(name)
async
Get an export of a Yarray as a Python list.
Raises DataUnavailable
if the array is not present in the Ydoc
or the room is not present and cannot be restored from storage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
name of the array |
required |
Returns:
Type | Description |
---|---|
List[Any]
|
List[Any]: A list representing the exported map |
export_map(name)
async
Get an export of a Ymap as a Python dictionary.
Raises DataUnavailable
if the map is not present in the Ydoc
or the room is not present and cannot be restored from storage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
name of the map |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: A dictionary representing the exported map |
export_text(name)
async
Get an export of a Ytext as a str.
Raises DataUnavailable
if the text is not present in the Ydoc
or the room is not present and cannot be restored from storage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
name of the xml text |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
A string serialization of the XML fragment |
export_xml_element(name)
async
Get an export of a YXmlElement as a str.
Raises DataUnavailable
if the XML element is not present in the Ydoc
or the room is not present and cannot be restored from storage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
name of the xml element |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
A string serialization of the XML element |
export_xml_fragment(name)
async
Get an export of a YXmlFragment as a str.
Raises DataUnavailable
if the XML fragment is not present in the Ydoc
or the room is not present and cannot be restored from storage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
name of the xml fragment |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
A string serialization of the XML fragment |
export_xml_text(name)
async
Get an export of a YXmlText as a str.
Raises DataUnavailable
if the XML text is not present in the Ydoc
or the room is not present and cannot be restored from storage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
name of the xml text |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
A string serialization of the XML text |