What is the criteria for publishData to work. I a...
# ask-ai
c
What is the criteria for publishData to work. I am sending data from fronted. To backend. Now to access that should we need the session to be started or is the room being available is good enough?
t
Thanks for reaching out, Ashish. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To use
publishData
in LiveKit, the following criteria must be met: • Room Connection: You must have an active connection to a LiveKit room. This is managed through the
LocalParticipant
instance, which becomes available after successfully joining a room. • Permissions: The participant must have the necessary permissions to publish data, which are configured in the room's access control settings. • Data Format: The data must be in a supported format, such as a
Uint8Array
or string, and must not exceed size limits (15KiB for reliable delivery, 1300 bytes for lossy delivery). • Delivery Options: You can specify reliable or lossy delivery and target specific participants using the
destinationIdentities
parameter. In summary, the room being available is not sufficient; you must also have an active session (i.e., be connected to the room) to use
publishData
. Sources: Data messages | LiveKit Docs | Sources/LiveKit/Participant/LocalParticipant.swift
c
Whats destination identities
t
Destination identities in LiveKit's
publishData
function let you send data directly to specific participants in a room. So instead of sharing your data with everyone, you can choose exactly who should get it by listing their identities in the
destinationIdentities
parameter. Here’s what you need to know: • If you provide
destinationIdentities
, only those participants will receive the data. • If you leave it empty, the data goes to everyone in the room by default. Here’s a quick example:
Copy code
// Send data to specific participants
room.localParticipant.publishData(data, {
  reliable: true,
  destinationIdentities: ['participant1', 'participant2']
});
This is super handy when you want to send direct messages or share data based on roles within the room.