diff --git a/example/ios/BigbluebuttonMobileSdkExample/AppDelegate.swift b/example/ios/BigbluebuttonMobileSdkExample/AppDelegate.swift index 9a4df38..5e5ec87 100644 --- a/example/ios/BigbluebuttonMobileSdkExample/AppDelegate.swift +++ b/example/ios/BigbluebuttonMobileSdkExample/AppDelegate.swift @@ -6,6 +6,7 @@ import UIKit import bigbluebutton_mobile_sdk +import bigbluebutton_mobile_sdk_common @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate, RCTBridgeDelegate { @@ -35,7 +36,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate, RCTBridgeDelegate { return true } - + + func applicationWillTerminate(_ application: UIApplication) { + BigBlueButtonSDK.onAppTerminated() + } + func sourceURL(for bridge: RCTBridge!) -> URL! { //#if DEBUG return RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index", fallbackResource:nil) diff --git a/ios-broadcast-upload-extension/Classes/BBBSampleHandler.swift b/ios-broadcast-upload-extension/Classes/BBBSampleHandler.swift index 310ce36..f674ebb 100644 --- a/ios-broadcast-upload-extension/Classes/BBBSampleHandler.swift +++ b/ios-broadcast-upload-extension/Classes/BBBSampleHandler.swift @@ -12,9 +12,10 @@ open class BBBSampleHandler : RPBroadcastSampleHandler { // Logger (these messages are displayed in the console application) private var logger = os.Logger(subsystem: "BigBlueButtonMobileSDK", category: "BBBSampleHandler") private var appGroupName:String = ""; - private var createOfferCallObserver:NSKeyValueObservation?; - private var setRemoteSDPCallObserver:NSKeyValueObservation?; + private var createScreenShareOfferObserver:NSKeyValueObservation?; + private var setScreenShareRemoteSDPOBserver:NSKeyValueObservation?; private var addScreenShareRemoteIceCandidateObserver:NSKeyValueObservation?; + private var onApplicationTerminatedObserver:NSKeyValueObservation?; private var screenBroadcaster:ScreenBroadcasterService?; open func setAppGroupName(appGroupName:String) { @@ -36,9 +37,16 @@ open class BBBSampleHandler : RPBroadcastSampleHandler { self.screenBroadcaster = ScreenBroadcasterService(appGroupName: appGroupName) + // Handle quit application to finish broadcast togheter + logger.info("Configuring observer for finishApplication") + self.onApplicationTerminatedObserver = userDefaults.observe(\.onApplicationTerminated, options: [.new]) { (defaults, change) in + self.logger.info("Observer detected a onQuitApplicationWithBroadcastActive request!") + finishBroadcastGracefully(self) + } + // Listen for createOffer requests from the UI APP logger.info("Configuring observer for createOffer") - self.createOfferCallObserver = userDefaults.observe(\.createScreenShareOffer, options: [.new]) { (defaults, change) in + self.createScreenShareOfferObserver = userDefaults.observe(\.createScreenShareOffer, options: [.new]) { (defaults, change) in self.logger.info("Observer detected a createScreenShareOffer request!") Task.init { @@ -56,7 +64,7 @@ open class BBBSampleHandler : RPBroadcastSampleHandler { } logger.info("Configuring observer for setRemoteSDP") - self.setRemoteSDPCallObserver = userDefaults.observe(\.setScreenShareRemoteSDP, options: [.new]) { (defaults, change) in + self.setScreenShareRemoteSDPOBserver = userDefaults.observe(\.setScreenShareRemoteSDP, options: [.new]) { (defaults, change) in let payload:String = (change.newValue!); // self.logger.info("Observer detected a setScreenShareRemoteSDP request with payload \(payload)") self.logger.info("Observer detected a setScreenShareRemoteSDP request") diff --git a/ios-broadcast-upload-extension/Classes/FinishBroadcastService.h b/ios-broadcast-upload-extension/Classes/FinishBroadcastService.h new file mode 100644 index 0000000..ec4a073 --- /dev/null +++ b/ios-broadcast-upload-extension/Classes/FinishBroadcastService.h @@ -0,0 +1,16 @@ +// +// SampleHandler.h +// BigBlueButton Broadcast +// +// Created by Gustavo Emanuel Farias Rosa on 09/05/22. +// + +#ifndef SampleHandler_h +#define SampleHandler_h + +#import +#import + +void finishBroadcastGracefully(RPBroadcastSampleHandler * _Nonnull broadcastSampleHandler); + +#endif /* SampleHandler_h */ diff --git a/ios-broadcast-upload-extension/Classes/FinishBroadcastService.m b/ios-broadcast-upload-extension/Classes/FinishBroadcastService.m new file mode 100644 index 0000000..daa375c --- /dev/null +++ b/ios-broadcast-upload-extension/Classes/FinishBroadcastService.m @@ -0,0 +1,17 @@ +// +// SampleHandler.m +// BigBlueButton Broadcast +// +// Created by Gustavo Emanuel Farias Rosa on 09/05/22. +// + +#import + +#import "FinishBroadcastService.h" + +void finishBroadcastGracefully(RPBroadcastSampleHandler * _Nonnull broadcastSampleHandler) { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wnonnull" + [broadcastSampleHandler finishBroadcastWithError:nil]; +#pragma clang diagnostic pop +} diff --git a/ios-broadcast-upload-extension/bigbluebutton-mobile-sdk-broadcast-upload-extension.podspec b/ios-broadcast-upload-extension/bigbluebutton-mobile-sdk-broadcast-upload-extension.podspec index 53e3b04..dd1dd90 100644 --- a/ios-broadcast-upload-extension/bigbluebutton-mobile-sdk-broadcast-upload-extension.podspec +++ b/ios-broadcast-upload-extension/bigbluebutton-mobile-sdk-broadcast-upload-extension.podspec @@ -14,7 +14,7 @@ Pod::Spec.new do |s| s.source = { :git => "https://github.com/bigbluebutton/bigbluebutton-mobile-sdk.git", :tag => "#{s.version}" } s.source_files = "Classes/*.{h,m,mm,swift}" - + s.public_header_files = ["Classes/*.h"] s.dependency "WebRTC-lib" s.dependency "bigbluebutton-mobile-sdk-common" end diff --git a/ios-common/Classes/BBBSharedData.swift b/ios-common/Classes/BBBSharedData.swift index 93a3ce5..4c03534 100644 --- a/ios-common/Classes/BBBSharedData.swift +++ b/ios-common/Classes/BBBSharedData.swift @@ -31,6 +31,7 @@ open class BBBSharedData { public static let onScreenShareLocalIceCandidate = "onScreenShareLocalIceCandidate" // Broadcaster -> UI APP public static let onScreenShareSignalingStateChange = "onScreenShareSignalingStateChange" // Broadcaster -> UI APP + public static let onApplicationTerminated = "onApplicationTerminated" // UI APP -> Broadcaster } diff --git a/ios-common/Classes/UserDefaults.swift b/ios-common/Classes/UserDefaults.swift index 3b63375..2363dd3 100644 --- a/ios-common/Classes/UserDefaults.swift +++ b/ios-common/Classes/UserDefaults.swift @@ -10,6 +10,11 @@ extension UserDefaults { return string(forKey: BBBSharedData.SharedData.broadcastStarted) ?? "" } + // UI APP -> Broadcaster + @objc open dynamic var onApplicationTerminated: String { + return string(forKey: BBBSharedData.SharedData.onApplicationTerminated) ?? "" + } + // Broadcaster -> UI APP @objc open dynamic var broadcastPaused: String { return string(forKey: BBBSharedData.SharedData.broadcastPaused) ?? "" diff --git a/ios/NativeOnly/BigBlueButtonSDK.swift b/ios/NativeOnly/BigBlueButtonSDK.swift index 31be332..b9743fa 100644 --- a/ios/NativeOnly/BigBlueButtonSDK.swift +++ b/ios/NativeOnly/BigBlueButtonSDK.swift @@ -105,5 +105,11 @@ open class BigBlueButtonSDK: NSObject { observer1?.invalidate() observer2?.invalidate() } + + public static func onAppTerminated(){ + BBBSharedData + .getUserDefaults(appGroupName: self.appGroupName) + .set(BBBSharedData.generatePayload(), forKey: BBBSharedData.SharedData.onApplicationTerminated) + } }