Unable to Send Data to a Room
### Select which package(s) are affected
livekit-server-sdk
### Describe the bug
` async speak({ message, roomId, agentId }: ISpeak): Promise<TSpeak> {
const { LIVEKIT_URL, LIVEKIT_API_KEY, LIVEKIT_API_SECRET } = this.helperService.initENVs();
const roomService = new RoomServiceClient(LIVEKIT_URL, LIVEKIT_API_KEY, LIVEKIT_API_SECRET);
const payload = JSON.stringify({
type: 'say',
text: message,
timestamp: Date.now(),
});
try {
await roomService.updateRoomMetadata(roomId, payload);
// const participants = await roomService.listParticipants(roomId);
// const agentParticipant = participants.find(
// (p) => p.identity.includes('agent') || p.metadata?.includes('agent'),
// );
// if (!agentParticipant) {
// throw new Error('Agent participant not found in room');
// }
// await roomService.sendData(roomId, Buffer.from(payload, 'utf-8'), DataPacket_Kind.RELIABLE, {
// // destinationSids: [agentParticipant.sid],
// // destinationIdentities: [agentParticipant.identity],
// });
return { success: true, message: 'sent text to livekit room' };
} catch (e) {
const defaultMessage = `Failed to send message ${message} to agent ${agentId} in room ${roomId}`;
const msg =
e instanceof Error
? e.message
: `Unknown error occurred when attempting to send message ${message} to agent ${agentId} in room ${roomId}`;
this.logger.log(defaultMessage);
this.logger.log(msg);
return {
success: false,
message: msg,
};
}
}`
I have a function speak, where i send text to my livekit agent for it to speak. I have tried almost every possible way to get the sendData function to send data to my livekit room for processing, but my livekit room does not recieve the data. However updateRoomMetadata works perfectly, so I am currently using that as a fallback. however, updateRoomMetadata is increiblly slow for real-time responses, taking up to almost 30 seconds for my room to recieve the changes. i am trying to figure out why sendData does not work for me.
### Reproduction
` async speak({ message, roomId, agentId }: ISpeak): Promise<TSpeak> {
const { LIVEKIT_URL, LIVEKIT_API_KEY, LIVEKIT_API_SECRET } = this.helperService.initENVs();
const roomService = new RoomServiceClient(LIVEKIT_URL, LIVEKIT_API_KEY, LIVEKIT_API_SECRET);
const payload = JSON.stringify({
type: 'say',
text: message,
timestamp: Date.now(),
});
try {
await roomService.updateRoomMetadata(roomId, payload);
// const participants = await roomService.listParticipants(roomId);
// const agentParticipant = participants.find(
// (p) => p.identity.includes('agent') || p.metadata?.includes('agent'),
// );
// if (!agentParticipant) {
// throw new Error('Agent participant not found in room');
// }
// await roomService.sendData(roomId, Buffer.from(payload, 'utf-8'), DataPacket_Kind.RELIABLE, {
// // destinationSids: [agentParticipant.sid],
// // destinationIdentities: [agentParticipant.identity],
// });
return { success: true, message: 'sent text to livekit room' };
} catch (e) {
const defaultMessage = `Failed to send message ${message} to agent ${agentId} in room ${roomId}`;
const msg =
e instanceof Error
? e.message
: `Unknown error occurred when attempting to send message ${message} to agent ${agentId} in room ${roomId}`;
this.logger.log(defaultMessage);
this.logger.log(msg);
return {
success: false,
message: msg,
};
}
}`
### Logs
```shell
{"message": "received job request", "level": "INFO", "name": "livekit.agents", "job_id": "AJ_oU3eVb7SaZWU", "dispatch_id": "", "room_name": "8643943e-3d0c-4aeb-ad5c-b94831a30cca", "agent_name": "bithuman-agent", "resuming": false, "timestamp": "2025-10-17T16:40:26.727414+00:00"}
{"message": "initializing process", "level": "INFO", "name": "livekit.agents", "pid": 401, "timestamp": "2025-10-17T16:40:26.742234+00:00"}
{"message": "process initialized", "level": "INFO", "name": "livekit.agents", "pid": 401, "elapsed_time": 0.02, "timestamp": "2025-10-17T16:40:26.765978+00:00"}
{"message": "starting bithuman runtime", "level": "INFO", "name": "bithuman-livekit-agent", "pid": 353, "job_id": "AJ_oU3eVb7SaZWU", "timestamp": "2025-10-17T16:40:26.938035+00:00"}
{"message": "Data received handler registered", "level": "INFO", "name": "bithuman-livekit-agent", "pid": 353, "job_id": "AJ_oU3eVb7SaZWU", "timestamp": "2025-10-17T16:40:26.997314+00:00"}
{"message": "Room metadata changed: {'userId': 10}", "level": "INFO", "name": "bithuman-livekit-agent", "pid": 353, "job_id": "AJ_oU3eVb7SaZWU", "timestamp": "2025-10-17T16:40:43.066864+00:00"}
{"message": "Agent ready in room: 8643943e-3d0c-4aeb-ad5c-b94831a30cca", "level": "INFO", "name": "bithuman-livekit-agent", "pid": 353, "job_id": "AJ_oU3eVb7SaZWU", "timestamp": "2025-10-17T16:40:52.252552+00:00"}
{"message": "Room metadata changed: {'type': 'say', 'text': 'Hey everyone! It’s Your Favorite Streamer and we’re live! Super excited to hang out with you all today. Grab a snack, say hi in the chat, and let’s have a good time.', 'timestamp': 1760719243027}", "level": "INFO", "name": "bithuman-livekit-agent", "pid": 353, "job_id": "AJ_oU3eVb7SaZWU", "timestamp": "2025-10-17T16:41:52.162715+00:00"}
{"message": "Executing say command: 'Hey everyone! It’s Your Favorite Streamer and we’re live! Super excited to hang out with you all today. Grab a snack, say hi in the chat, and let’s have a good time.'", "level": "INFO", "name": "bithuman-livekit-agent", "pid": 353, "job_id": "AJ_oU3eVb7SaZWU", "timestamp": "2025-10-17T16:41:52.162810+00:00"}
{"message": "playback finished event received", "level": "INFO", "name": "livekit.agents", "caller_identity": "bithuman-avatar-agent", "pid": 353, "job_id": "AJ_oU3eVb7SaZWU", "timestamp": "2025-10-17T16:42:01.726453+00:00"}
{"message": "Room metadata changed: {'type': 'say', 'text': 'Hey, eliteman96! Good to see you in chat… How’s your day going? Got any fun plans or just hanging out with us tonight?', 'timestamp': 1760719311421}", "level": "INFO", "name": "bithuman-livekit-agent", "pid": 353, "job_id": "AJ_oU3eVb7SaZWU", "timestamp": "2025-10-17T16:42:03.581971+00:00"}
{"message": "Executing say command: 'Hey, eliteman96! Good to see you in chat… How’s your day going? Got any fun plans or just hanging out with us tonight?'", "level": "INFO", "name": "bithuman-livekit-agent", "pid": 353, "job_id": "AJ_oU3eVb7SaZWU", "timestamp": "2025-10-17T16:42:03.582069+00:00"}
{"message": "playback finished event received", "level": "INFO", "name": "livekit.agents", "caller_identity": "bithuman-avatar-agent", "pid": 353, "job_id": "AJ_oU3eVb7SaZWU", "timestamp": "2025-10-17T16:42:12.223601+00:00"}
{"message": "Room metadata changed: {'type': 'say', 'text': 'You know, I was thinking about how everyone always says breakfast is the most important meal of the day… but then so many people just grab coffee and skip it entirely! Do you all actually sit down for breakfast or just run out the door? Let’s hear your breakfast routines!', 'timestamp': 1760719323533}", "level": "INFO", "name": "bithuman-livekit-agent", "pid": 353, "job_id": "AJ_oU3eVb7SaZWU", "timestamp": "2025-10-17T16:42:38.902591+00:00"}
{"message": "Executing say command: 'You know, I was thinking about how everyone always says breakfast is the most important meal of the day… but then so many people just grab coffee and skip it entirely! Do you all actually sit down for breakfast or just run out the door? Let’s hear your breakfast routines!'", "level": "INFO", "name": "bithuman-livekit-agent", "pid": 353, "job_id": "AJ_oU3eVb7SaZWU", "timestamp": "2025-10-17T16:42:38.902689+00:00"}
{"message": "playback finished event received", "level": "INFO", "name": "livekit.agents", "caller_identity": "bithuman-avatar-agent", "pid": 353, "job_id": "AJ_oU3eVb7SaZWU", "timestamp": "2025-10-17T16:42:54.714525+00:00"}
{"message": "process exiting", "level": "INFO", "name": "livekit.agents", "reason": "", "pid": 353, "job_id": "AJ_oU3eVb7SaZWU", "timestamp": "2025-10-17T16:42:59.051012+00:00"}
{"message": "received job request", "level": "INFO", "name": "livekit.agents", "job_id": "AJ_sAEeyZPk8JA7", "dispatch_id": "", "room_name": "c3598190-f1c2-486e-8a1d-858129a09c77", "agent_name": "bithuman-agent", "resuming": false, "timestamp": "2025-10-17T16:57:13.805628+00:00"}
{"message": "initializing process", "level": "INFO", "name": "livekit.agents", "pid": 518, "timestamp": "2025-10-17T16:57:13.902792+00:00"}
{"message": "process initialized", "level": "INFO", "name": "livekit.agents", "pid": 518, "elapsed_time": 0.02, "timestamp": "2025-10-17T16:57:13.926340+00:00"}
{"message": "starting bithuman runtime", "level": "INFO", "name": "bithuman-livekit-agent", "pid": 401, "job_id": "AJ_sAEeyZPk8JA7", "timestamp": "2025-10-17T16:57:14.012820+00:00"}
{"message": "Data received handler registered", "level": "INFO", "name": "bithuman-livekit-agent", "pid": 401, "job_id": "AJ_sAEeyZPk8JA7", "timestamp": "2025-10-17T16:57:14.073184+00:00"}
{"message": "Agent ready in room: c3598190-f1c2-486e-8a1d-858129a09c77", "level": "INFO", "name": "bithuman-livekit-agent", "pid": 401, "job_id": "AJ_sAEeyZPk8JA7", "timestamp": "2025-10-17T16:57:44.653710+00:00"}
{"message": "process exiting", "level": "INFO", "name": "livekit.agents", "reason": "", "pid": 401, "job_id": "AJ_sAEeyZPk8JA7", "timestamp": "2025-10-17T16:59:27.922457+00:00"}
```
### System Info
```shell
System:
OS: macOS 15.3.1
CPU: (12) arm64 Apple M4 Pro
Memory: 145.44 MB / 24.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.19.0 - /Users/hasanslater/.nvm/versions/node/v22.19.0/bin/node
npm: 11.5.2 - /Users/hasanslater/mixio/node_modules/.bin/npm
```
### LiveKit server version
LiveKit cloud
### Severity
annoyance
### Additional Information
_No response_
0 条评论