Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/break_arc_cycles.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
livekit: patch
livekit-ffi: patch
---

Break two arc cycles between RoomSession and itself and DataChannel and itself introduced via closures.
6 changes: 5 additions & 1 deletion livekit/src/room/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -759,10 +759,14 @@ impl Room {

e2ee_manager.on_state_changed({
let dispatcher = dispatcher.clone();
let inner = inner.clone();
let inner = Arc::downgrade(&inner);
move |participant_identity, state| {
// Forward e2ee events to the room
// (Ignore if the participant is not in the room anymore)
let Some(inner) = inner.upgrade() else {
// RoomSession is gone, nothing left to forward the events to.
return;
};

let participant = if participant_identity.as_str()
== inner.local_participant.identity().as_str()
Expand Down
7 changes: 2 additions & 5 deletions livekit/src/rtc_engine/rtc_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ pub enum RtcEvent {
},
DataChannelBufferedAmountChange {
sent: u64,
amount: u64,
kind: DataPacketKind,
},
}
Expand Down Expand Up @@ -166,16 +165,14 @@ fn on_message(emitter: RtcEmitter, kind: DataPacketKind) -> rtc::data_channel::O

fn on_buffered_amount_change(
emitter: RtcEmitter,
dc: DataChannel,
kind: DataPacketKind,
) -> rtc::data_channel::OnBufferedAmountChange {
Box::new(move |sent| {
let amount = dc.buffered_amount();
let _ = emitter.send(RtcEvent::DataChannelBufferedAmountChange { sent, amount, kind });
let _ = emitter.send(RtcEvent::DataChannelBufferedAmountChange { sent, kind });
})
}

pub fn forward_dc_events(dc: &mut DataChannel, kind: DataPacketKind, rtc_emitter: RtcEmitter) {
dc.on_message(Some(on_message(rtc_emitter.clone(), kind)));
dc.on_buffered_amount_change(Some(on_buffered_amount_change(rtc_emitter, dc.clone(), kind)));
dc.on_buffered_amount_change(Some(on_buffered_amount_change(rtc_emitter, kind)));
}
2 changes: 1 addition & 1 deletion livekit/src/rtc_engine/rtc_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1677,7 +1677,7 @@ impl SessionInner {
);
}
}
RtcEvent::DataChannelBufferedAmountChange { sent, amount: _, kind } => {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the only place I was able to see amount being used and it's being ignored, so I opted to remove amount instead of wiring it through from the data channel.

RtcEvent::DataChannelBufferedAmountChange { sent, kind } => {
let ev = DataChannelEvent {
kind,
detail: DataChannelEventDetail::BufferedAmountChange(sent),
Expand Down
Loading