Hi, I can send a text to lk room using this from m...
# ask-ai
g
Hi, I can send a text to lk room using this from my frontend
Copy code
await room.localParticipant.sendText(messageText, { topic: 'lk.chat' });
Is there any way doing same from backend, how to send text from my node server to lk room?
t
Thanks for reaching out, K. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — you’re asking how to send the same text message to a LiveKit room from your Node backend that you currently send from the frontend with
localParticipant.sendText(...)
. You can do that from the server using the LiveKit Server SDK’s
publishData
method — you do not need to join the room as a participant. Example (Node.js, server-sdk-js):
Copy code
import { RoomServiceClient } from 'livekit-server-sdk';

const roomService = new RoomServiceClient(
  process.env.LIVEKIT_URL,
  process.env.LIVEKIT_API_KEY,
  process.env.LIVEKIT_API_SECRET
);

// send text to room (room name or SID)
await roomService.publishData(
  'Hello from backend',
  { topic: 'lk.chat' },
  'your-room-name'
);
What the recipients do: • Participants receive it via the same data event they use client-side:
Copy code
room.on('dataReceived', (payload, participant, topic) => {
  if (topic === 'lk.chat') {
    console.log(payload.toString());
  }
});
If you want, tell me: • the package you’re using (npm package name or version), and • whether you prefer TypeScript or plain JS — I’ll give a copy-paste-ready snippet and any extra config details. Sources: LiveKit for Robotics | server-sdk-js | livekit/livekit_composite | DeepWiki