i am calling triggering the room_metadata_change e...
# ask-ai
b
i am calling triggering the room_metadata_change event, but it is always one event behind. why is that?
@ctx.room.on("room_metadata_changed")
def on_room_metadata_changed(metadata: str): try:
# if not metadata:
#     return
payload = json.loads(metadata)
print(payload)
if payload.get("type") == "say":
text = payload.get("text", "")
if text:
logger.info(f"Executing say command from metadata: '{text}'")
session.say(text)
except Exception as e:
logger.error(f"Error processing room metadata change: {e}", exc_info=True)
t
Thanks for reaching out, Hasan. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Could you please share a bit more about your setup? It would be really helpful to know: • Which LiveKit SDK you’re working with (like Python, JavaScript, etc.) • How you’re updating the room metadata (for example, through specific server API calls) • Whether you’re making quick, back-to-back updates to the metadata • What exactly you mean by the "one behind" behavior you’re seeing (such as getting old values or missing the latest update) Understanding these details will really help us get to the heart of the issue together. Sources: livekit-rtc/livekit/rtc/room.py | Room metadata | LiveKit Docs | pkg/rtc/room_test.go | livekit/src/room/mod.rs
b
i am using the node sdk through this call. By one behind i mean if i send the message "hello world" as my first message, the room_metadata_change does nothing. Then, once i send "hi world", the room_metadata_changes handles hello world. and so on.
async speak({ message, roomId, agentId, useSSE, jobId }: 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 {
// if (useSSE && jobId) {
//   this.logger.log('Implement Server Sent Event Here!');
_`// await this.redisService.publish(
init_avatar:${jobId}
, {`_
//     message,
//     jobId,
//     status: 'processing',
//     success: true,
//   });
//   return { success: true, message: 'Message sent through sse' };
// }
await roomService.updateRoomMetadata(roomId, payload);
return { success: true, message: 'sent text to livekit room via metadata update' };
} catch (e) {
`const msg = `Failed to send message ${message} to agent ${agentId} in room ${roomId}`;`
this.logger.log(msg);
return { success: false, message: msg };
}
}
t
Thank you so much for sharing these details! To help us get to the bottom of this together, could you please clarify a few things for me? • Which version of the LiveKit Node SDK are you currently using? • Are you sending multiple rapid calls to update the room metadata from your server? • Does this happen all the time, or only in certain situations, like during high-frequency updates? Understanding this will really help us figure out whether it’s a timing issue, a bug with the SDK version, or something else. Looking forward to your response! Sources: livekit/src/room/mod.rs | livekit-rtc/livekit/rtc/room.py | packages/livekit-rtc/src/proto/room_pb.ts | Room metadata | LiveKit Docs
b
latest version of livekit, just one call every 30 seconds give or take, happens evey time
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!