How would i update the room metadata and listen it...
# ask-ai
e
How would i update the room metadata and listen it on the client side ?
t
Thanks for reaching out, Aditya. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking how to update room metadata and have clients receive those updates. Here’s what you can do. Server — update the room metadata 1. Use the server API (requires a roomAdmin grant) to set metadata with UpdateRoomMetadata / updateRoomMetadata. 2. Examples: ◦ Node.js
Copy code
import { RoomServiceClient } from 'livekit-server-sdk';
   const roomService = new RoomServiceClient('host', 'api-key', 'api-secret');
   await roomService.updateRoomMetadata('my-room', 'new metadata');
• Python
Copy code
from livekit.api import UpdateRoomMetadataRequest
   await lkapi.room.update_room_metadata(UpdateRoomMetadataRequest(room='my-room', metadata='new metadata'))
• Go
Copy code
_, err := roomClient.UpdateRoomMetadata(ctx, &livekit.UpdateRoomMetadataRequest{
     Room: "my-room",
     Metadata: "new metadata",
   })
Client — listen for metadata changes • Subscribe to the RoomMetadataChanged event in your client SDK so all participants receive updates when metadata changes. ◦ JavaScript/TypeScript
Copy code
room.on(RoomEvent.RoomMetadataChanged, (newMetadata) => {
    console.log('Room metadata changed:', newMetadata);
  });
• Swift
Copy code
func room(_ room: Room, didUpdateMetadata newMetadata: String?) {
    print("Room metadata changed: \(newMetadata ?? "nil")")
  }
• Kotlin
Copy code
room.events.collect { event ->
    if (event is RoomEvent.RoomMetadataChanged) {
      println("Room metadata changed: ${event.metadata}")
    }
  }
• Flutter
Copy code
room.on<roommetadatachangedevent>((event) {
    print('Room metadata changed: ${event.metadata}');
  });
• Python
Copy code
@room.on("room_metadata_changed")
  def on_room_metadata_changed(metadata: str):
      print("Room metadata changed:", metadata)
Notes • Initial metadata can be set on room creation. • Metadata size limit: 64 KiB UTF-8 text. • All participants receive the RoomMetadataChanged event. Would you like the exact code for your server language or the client SDK you’re using? Sources: Room metadata | LiveKit docs | server-sdk-js | livekit/livekit_composite | DeepWiki | Participant attributes and metadata | LiveKit docs | Handling events | LiveKit docs | Managing participants | LiveKit docs