From e4e3dd225b7e27653023b6d33f552f98f316eacb Mon Sep 17 00:00:00 2001 From: Hiroshi Horie <548776+hiroshihorie@users.noreply.github.com> Date: Sun, 9 Jul 2023 02:39:26 +0800 Subject: [PATCH] notify parent object when child state mutates --- Sources/LiveKit/Core/Room.swift | 1 + Sources/LiveKit/Participant/Participant.swift | 5 ++++- Sources/LiveKit/TrackPublications/TrackPublication.swift | 9 +++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Sources/LiveKit/Core/Room.swift b/Sources/LiveKit/Core/Room.swift index dd01e4d51..e4ccece45 100644 --- a/Sources/LiveKit/Core/Room.swift +++ b/Sources/LiveKit/Core/Room.swift @@ -185,6 +185,7 @@ public class Room: NSObject, ObservableObject, Loggable { } } + // Notify Room when state mutates Task.detached { @MainActor in self.objectWillChange.send() } diff --git a/Sources/LiveKit/Participant/Participant.swift b/Sources/LiveKit/Participant/Participant.swift index fde16b9a1..36f2c654d 100644 --- a/Sources/LiveKit/Participant/Participant.swift +++ b/Sources/LiveKit/Participant/Participant.swift @@ -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() } } } diff --git a/Sources/LiveKit/TrackPublications/TrackPublication.swift b/Sources/LiveKit/TrackPublications/TrackPublication.swift index ba666a71e..c4aa1fde7 100644 --- a/Sources/LiveKit/TrackPublications/TrackPublication.swift +++ b/Sources/LiveKit/TrackPublications/TrackPublication.swift @@ -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() + } } } }