Closed Thintin914 closed 2 months ago
Ok I figured out I need to wrap the room_rx inside an async_std::task::block_on
loop like the example from basic_async_room
. And then I need to send the RoomEvent to main thread with work-stealing. Using std::thread::spawn
won't receive the RoomEvent. Kinda confusing behavior.
async fn event(mut room_rx: UnboundedReceiver<RoomEvent>, stop_room_receiver: Receiver<bool>, room_data_sender: Sender<livekit::RoomEvent>) {
async_std::task::block_on(async {
loop {
if let Ok(stop) = stop_room_receiver.try_recv() {
if stop {
drop(stop_room_receiver);
drop(room_data_sender);
println!("stop loop");
break;
}
}
if let Ok(room_event) = room_rx.try_recv() {
let _ = room_data_sender.send(room_event);
}
}
});
}
Hello, I'm experiencing something weird in my code.
In
fn new_room()
, it creates a new room and update the metadata totest1
after 8 seconds. Infn event()
, it successfully prints out the RoomMetadataChanged event.When I type something in my chat bar, it calls
fn send_message()
. It will update room metadata totest2
. It prints "update_room_metadata call succeeded". However, when I prints the room metadata after 2 seconds, it's still the old metadata. And RoomEvent infn event()
is not being received. The same situation goes forRoomService::send_data
as well, wheresend_data
fromfn new_room()
will be received byfn event()
butsend_data
fromfn send_message()
will not.But when I leave the room by calling
RoomService::remove_participant
and join the same room, the metadata is indeed changed totest2
. It seems like RoomEvent is not being received fromfn send_message()
.fn new_room()
fn event()
fn send_message()
I can provide full code if it's possible.