Publishing Data
Send data to other participants using thepublish(data:options:) method:
Data Publish Options
Control delivery behavior usingDataPublishOptions:
reliable: Whentrue, uses TCP-like reliable delivery. Whenfalse, uses UDP-like lossy delivery for lower latencydestinationIdentities: Array of participant identities to receive the data. Empty array sends to all participantstopic: Optional string to categorize messages (useful for filtering on the receiving end)
Reliable vs. Lossy Delivery
- Reliable
- Lossy
Best for: Chat messages, file transfers, critical data
- Guarantees delivery and order
- Higher latency under poor network conditions
- Uses TCP-like transmission
Receiving Data
Implement theRoomDelegate protocol to receive data messages:
Filtering by Topic
Use topics to organize different types of data messages:Sending to Specific Participants
Send data to one or more specific participants:Size Limits
Each data payload must not exceed 15KB. For larger data:Setting Default Options
Set default data publish options when creating a room:Use Cases
Chat Messages
Real-time Cursor Position
Reactions
Error Handling
Handle errors when publishing data:See Also
- LocalParticipant.swift:117 (
publish(data:options:)) - Core/DataChannelPair.swift