Skip to content

Commit

Permalink
notify parent object when child state mutates
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroshihorie committed Jul 8, 2023
1 parent cf01024 commit e4e3dd2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions Sources/LiveKit/Core/Room.swift
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ public class Room: NSObject, ObservableObject, Loggable {
}
}

// Notify Room when state mutates
Task.detached { @MainActor in
self.objectWillChange.send()
}
Expand Down
5 changes: 4 additions & 1 deletion Sources/LiveKit/Participant/Participant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,12 @@ public class Participant: NSObject, ObservableObject, Loggable {
}
}

// notify object change when any state updates
// Notify when state mutates
Task.detached { @MainActor in
// Notify Participant
self.objectWillChange.send()
// Notify Room
self.room.objectWillChange.send()
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions Sources/LiveKit/TrackPublications/TrackPublication.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,17 @@ public class TrackPublication: NSObject, ObservableObject, TrackDelegate, Loggab
}
}

// Notify when state mutates
Task.detached { @MainActor in
// Notify TrackPublication
self.objectWillChange.send()

if let participant = self.participant {
// Notify Participant
participant.objectWillChange.send()
// Notify Room
participant.room.objectWillChange.send()
}
}
}
}
Expand Down

0 comments on commit e4e3dd2

Please sign in to comment.