client-sdk-swift icon indicating copy to clipboard operation
client-sdk-swift copied to clipboard

Stop Broadcast Extension by pressing indicator on native time doesn't make isScreenShareEnabled() to return false

Open mokuzuu opened this issue 1 year ago • 4 comments

Describe the bug Even after stopping screen share by pressing indicator on native time doesn't make isScreenShareEnabled() to return false.

SDK Version 2.0.12

iOS/macOS Version iOS 17.5.1

Xcode Version 15.4 Swift 5

Steps to Reproduce

  1. Start broadcast extension by calling setScreenShare(enabled: true)
  2. Stop screen share by pressing indicator on native time

Expected behavior Expect room.localParticipant.isScreenShareEnabled() to return false but true is returned.

Screenshots If applicable, add screenshots to help explain your problem.

Logs Please provide logs if you can.

mokuzuu avatar Jul 29 '24 05:07 mokuzuu

I think I could workaround this by listening to iOS_BroadcastStopped notification from CFNotificationCenter

(DarwinNotificationCenter is extended by following https://gist.github.com/tomlokhorst/7fe49a03b8bac960eeaf2b991faa3680 so that callback can use async)

   func performAsyncTask() async {
        do {
            try await room.localParticipant.setScreenShare(enabled: false)
        } catch {
            print("An error occurred while updating screen share")
        }
  }

 func notificationCallback() {
        DispatchQueue.global().async {
            Task {
                await performAsyncTask()
            }
        }
    }

DarwinNotificationCenter.shared.addObserver(name: "iOS_BroadcastStopped", callback: notificationCallback)

mokuzuu avatar Jul 30 '24 06:07 mokuzuu

Probably I can address fix for #444 with similar approach

mokuzuu avatar Jul 30 '24 06:07 mokuzuu

@mokuzuu did u get this working? can u share your DarwinNotificationCenter class

ashwin-nath-m avatar Aug 20 '24 09:08 ashwin-nath-m

@ashwin-nath-m I could workaround like this

 @State var darwinNotificationCenterObservation: DarwinNotificationObservation?

 // Define an async function to perform the async task
    func performAsyncTask() async {
        do {
            try await room.localParticipant.setScreenShare(enabled: false)
        } catch {
            print("An error occurred while updating screen share")
        }
    }
    
    // function that matches the C function pointer type
    func notificationCallback() {
        // Dispatch to handle async code
        DispatchQueue.global().async {
            Task {
                await performAsyncTask()
            }
        }
    }
    
    
    func setupNotifications() {
        // We need to store the value in variable/state to keep notification active.
        darwinNotificationCenterObservation = DarwinNotificationCenter.shared.addObserver(name: "iOS_BroadcastStopped", callback: notificationCallback)
    }

mokuzuu avatar Sep 02 '24 02:09 mokuzuu