big-school-62939
12/23/2025, 4:57 PMtall-airline-16756
12/23/2025, 4:57 PMtall-airline-16756
12/23/2025, 4:58 PMctx.room.local_participant.publish_data() to publish text. Use topic (e.g., "debug-log") so Unity can filter.
# Python (LiveKit agent)
from livekit.agents import JobContext
async def send_debug_log(ctx: JobContext, message: str):
await ctx.room.local_participant.publish_data(
payload=message, # text payload
topic="debug-log", # optional topic name
reliable=True, # reliable delivery for logs
)
# Example use inside an agent session
@server.rtc_session()
async def my_agent(ctx: JobContext):
await ctx.connect()
await send_debug_log(ctx, "Agent started and connected.")
# ...later...
await send_debug_log(ctx, "Processing audio chunk #5")
2) Unity C# — receive text messages
• Register a text stream handler for the same topic or subscribe to raw data events depending on SDK usage.
Option A — Text stream handler (topic-based):
using UnityEngine;
using LiveKit; // your Unity LiveKit SDK namespace
public class DebugLogReceiver : MonoBehaviour
{
Room room;
async void Start()
{
room = new Room();
await room.Connect("<wss://your-livekit-url>", "YOUR_TOKEN");
// Register handler for text messages on "debug-log"
room.RegisterTextStreamHandler("debug-log", OnDebugTextReceived, null);
}
void OnDebugTextReceived(TextStreamReader reader, string participantIdentity)
{
string message = reader.Read();
Debug.Log($"[DebugLog from {participantIdentity}]: {message}");
// Update UI or store message if desired
}
void OnDestroy()
{
if (room != null)
room.UnregisterTextStreamHandler("debug-log", OnDebugTextReceived, null);
}
}
Option B — Raw data channel event (if SDK exposes DataReceived):
room.DataReceived += (sender, e) =>
{
string msg = System.Text.Encoding.UTF8.GetString(e.Data);
Debug.Log($"[RawData from {e.Participant.Identity}]: {msg}");
};
Practical notes and tips
• Use the same topic string on both sides (e.g., "debug-log").
• Use reliable=True in Python to ensure delivery for debugging messages.
• If you’ll emit many messages, consider batching or switching to lossy mode for non-critical high-frequency logs to avoid bandwidth/backpressure issues.
• Clean up/unregister handlers when the Unity object is destroyed to avoid leaks.
• For WebGL builds confirm you are using the appropriate LiveKit Unity SDK build target.
If you want, tell me:
• which Unity LiveKit SDK/version you’re using (so I can tailor exact APIs), and
• whether you prefer topic-based text streams or raw data events — I’ll provide any small adjustments needed. Sources: Job lifecycle | LiveKit docs | Transcriber | LiveKit docs | client-sdk-unity-web | livekit/livekit_composite | DeepWiki | Text and transcriptions | LiveKit docs