Realtime
Realtime rooms — server-side emit and room management.
// access
client.realtimeRealtime rooms — server-side emit and room management.
Emitting broadcasts to every client currently joined to the room. Rooms are environment-scoped: a client joined with a key from another environment will never see your emit, which is the usual cause of "the message just doesn't arrive".
To receive events in Python (a worker that reacts to room traffic), use
nexus.RealtimeSocket — it needs python-socketio.
Realtime
classclient.realtime
Extends Resource.
emit()
methoddef emit(room, events=(), payload=None) -> Dict[str, Any]Emit one or more named events to a room.
client.realtime.emit("orders:42", "status", {"state": "shipped"})
client.realtime.emit("orders:42", ["status", "updated"], {"state": "shipped"})
client.realtime.emit(RoomMessage("orders:42", "status", {"state": "shipped"}))Returns the ack: {ok, room, related, events, recipients}.
Parameters
Prop
Type
Returns Dict[str, Any]
broadcast()
methoddef broadcast(messages) -> Dict[str, Any]Send to many rooms, each with its own events/payload, in one request.
Parameters
Prop
Type
Returns Dict[str, Any]
emit_to_rooms()
methoddef emit_to_rooms(rooms, events, payload=None) -> Dict[str, Any]The same event(s) and payload to several rooms, in one request.
Parameters
Prop
Type
Returns Dict[str, Any]
register_room()
methoddef register_room(name, type=None) -> Dict[str, Any]Create a room up front (they are also auto-created on join/emit).
Parameters
Prop
Type
Returns Dict[str, Any]
rooms()
methoddef rooms() -> List[Any]The environment's registered rooms.
Returns List[Any]
delete_room()
methoddef delete_room(room_id) -> NoneParameters
Prop
Type
link()
methoddef link(room_id, related_id) -> NoneLink two rooms so an emit to one also reaches the other.
Parameters
Prop
Type
unlink()
methoddef unlink(room_id, related_id) -> NoneParameters
Prop
Type
related()
methoddef related(name) -> AnyRooms linked to this one.
Parameters
Prop
Type
Returns Any
schema()
methoddef schema(room_id) -> Dict[str, Any]The room's JSON Schema, if one is set.
Parameters
Prop
Type
Returns Dict[str, Any]
set_schema()
methoddef set_schema(room_id, schema) -> Dict[str, Any]Attach a JSON Schema that payloads to this room must satisfy.
Parameters
Prop
Type
Returns Dict[str, Any]
enable_schema()
methoddef enable_schema(room_id, enabled=True) -> Dict[str, Any]Turn schema validation on or off.
Parameters
Prop
Type
Returns Dict[str, Any]
clear_schema()
methoddef clear_schema(room_id) -> NoneParameters
Prop
Type
