MessagingClient
enables sending messages between participants and agents in a room, as well as handling streaming messages (MessageStreamWriter
and MessageStreamReader
).
Participant
. Each Participant
has a unique identifier and can be addressed individually for one-on-one interactions, or collectively for broadcasts. This single abstraction unifies how you approach messaging, so your app doesn’t need separate code paths for humans vs. agents.
MessagingClient
– A high-level client that:
createStream()
MessageStreamChunk
– Represents a single chunk in a stream, containing a header and optional binary data.MessageStreamWriter
– A writer for sending streaming data (chunks) to a remote participant.MessageStreamReader
– A reader that receives streaming data (chunks) from a remote participant.MessagingClient
for basic messaging and streaming use cases.
attachment
.
Parameters:
to
– The participant to receive the message.type
– A string that categorizes or labels the message.message
– A JSON-serializable object containing message data.attachment
– (Optional) A Uint8Array
of binary data to attach.type
– A string that categorizes or labels the message.message
– A JSON-serializable object containing message data.attachment
– (Optional) A Uint8Array
of binary data to attach.MessageStreamWriter
once the remote participant accepts the stream.
Parameters:
to
– The participant to receive the stream.header
– A JSON-serializable object describing the stream.Promise<MessageStreamWriter>
that resolves once the remote participant accepts the stream.
MessagingClient.createStream()
.
write(MessageStreamChunk)
close(): Promise<void>
MessagingClient
extends EventEmitter<RoomMessageEvent>
. It emits events whenever messages are received or streams are opened/closed. You can listen for the "message"
event or for custom events like "participant_added"
, "participant_removed"
, etc.:MessagingClient
automatically keeps track of participants joining or leaving when the messaging subsystem is enabled. You can access them via remoteParticipants
.
RoomClient
may throw an exception.createStream
, write
, etc.) may also fail if the remote participant rejects or if the connection is lost.MessagingClient
or by wrapping the provided stream objects (MessageStreamWriter
/ MessageStreamReader
).
MessagingClient
is designed to handle incremental data transfer, but network considerations remain important for efficient performance.