client-sdk-swift
client-sdk-swift copied to clipboard
Stop Broadcast Extension by pressing indicator on native time doesn't make isScreenShareEnabled() to return false
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
- Start broadcast extension by calling setScreenShare(enabled: true)
- 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.
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)
Probably I can address fix for #444 with similar approach
@mokuzuu did u get this working? can u share your DarwinNotificationCenter class
@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)
}