steep-balloon-41261
02/12/2025, 10:17 PMgray-monkey-83525
02/12/2025, 10:17 PMpublishData
method. On the server side, the agent can listen for this data packet and process the user's name accordingly.
Here's a basic example of how you might implement this:
Client Side (JavaScript):
await localParticipant.publishData(new TextEncoder().encode(JSON.stringify({
type: 'user_info',
name: 'UserName'
})), { reliable: true, topic: 'user_info' });
Server Side (Python):
@ctx.room.on("data_received")
def on_data_received(data: rtc.DataPacket):
if data.topic == "user_info":
user_info = json.loads(data.data.decode("utf-8"))
user_name = user_info.get('name')
# Process the user's name as needed
This approach ensures that the user's name is sent reliably to the server when the chat starts. Would you like more details on this implementation?
Sources:
- Example of Data Packet Handling 👍 0 button 👎 1 button 💡 Hint: Mention @millions-hair-24956 in the thread for followups.