Merge pull request #10 from gustavo-em/finish_broadcast_when_quit_application

Stop broadcast extension when app is closed
This commit is contained in:
Tiago Jacobs 2022-05-16 19:21:56 -03:00 committed by GitHub
commit 866b46fa7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 64 additions and 6 deletions

View File

@ -6,6 +6,7 @@
import UIKit import UIKit
import bigbluebutton_mobile_sdk import bigbluebutton_mobile_sdk
import bigbluebutton_mobile_sdk_common
@UIApplicationMain @UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, RCTBridgeDelegate { class AppDelegate: UIResponder, UIApplicationDelegate, RCTBridgeDelegate {
@ -36,6 +37,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate, RCTBridgeDelegate {
return true return true
} }
func applicationWillTerminate(_ application: UIApplication) {
BigBlueButtonSDK.onAppTerminated()
}
func sourceURL(for bridge: RCTBridge!) -> URL! { func sourceURL(for bridge: RCTBridge!) -> URL! {
//#if DEBUG //#if DEBUG
return RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index", fallbackResource:nil) return RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index", fallbackResource:nil)

View File

@ -12,9 +12,10 @@ open class BBBSampleHandler : RPBroadcastSampleHandler {
// Logger (these messages are displayed in the console application) // Logger (these messages are displayed in the console application)
private var logger = os.Logger(subsystem: "BigBlueButtonMobileSDK", category: "BBBSampleHandler") private var logger = os.Logger(subsystem: "BigBlueButtonMobileSDK", category: "BBBSampleHandler")
private var appGroupName:String = ""; private var appGroupName:String = "";
private var createOfferCallObserver:NSKeyValueObservation?; private var createScreenShareOfferObserver:NSKeyValueObservation?;
private var setRemoteSDPCallObserver:NSKeyValueObservation?; private var setScreenShareRemoteSDPOBserver:NSKeyValueObservation?;
private var addScreenShareRemoteIceCandidateObserver:NSKeyValueObservation?; private var addScreenShareRemoteIceCandidateObserver:NSKeyValueObservation?;
private var onApplicationTerminatedObserver:NSKeyValueObservation?;
private var screenBroadcaster:ScreenBroadcasterService?; private var screenBroadcaster:ScreenBroadcasterService?;
open func setAppGroupName(appGroupName:String) { open func setAppGroupName(appGroupName:String) {
@ -36,9 +37,16 @@ open class BBBSampleHandler : RPBroadcastSampleHandler {
self.screenBroadcaster = ScreenBroadcasterService(appGroupName: appGroupName) 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 // Listen for createOffer requests from the UI APP
logger.info("Configuring observer for createOffer") 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!") self.logger.info("Observer detected a createScreenShareOffer request!")
Task.init { Task.init {
@ -56,7 +64,7 @@ open class BBBSampleHandler : RPBroadcastSampleHandler {
} }
logger.info("Configuring observer for setRemoteSDP") 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!); let payload:String = (change.newValue!);
// self.logger.info("Observer detected a setScreenShareRemoteSDP request with payload \(payload)") // self.logger.info("Observer detected a setScreenShareRemoteSDP request with payload \(payload)")
self.logger.info("Observer detected a setScreenShareRemoteSDP request") self.logger.info("Observer detected a setScreenShareRemoteSDP request")

View File

@ -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 <ReplayKit/ReplayKit.h>
#import <Foundation/Foundation.h>
void finishBroadcastGracefully(RPBroadcastSampleHandler * _Nonnull broadcastSampleHandler);
#endif /* SampleHandler_h */

View File

@ -0,0 +1,17 @@
//
// SampleHandler.m
// BigBlueButton Broadcast
//
// Created by Gustavo Emanuel Farias Rosa on 09/05/22.
//
#import <Foundation/Foundation.h>
#import "FinishBroadcastService.h"
void finishBroadcastGracefully(RPBroadcastSampleHandler * _Nonnull broadcastSampleHandler) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wnonnull"
[broadcastSampleHandler finishBroadcastWithError:nil];
#pragma clang diagnostic pop
}

View File

@ -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 = { :git => "https://github.com/bigbluebutton/bigbluebutton-mobile-sdk.git", :tag => "#{s.version}" }
s.source_files = "Classes/*.{h,m,mm,swift}" s.source_files = "Classes/*.{h,m,mm,swift}"
s.public_header_files = ["Classes/*.h"]
s.dependency "WebRTC-lib" s.dependency "WebRTC-lib"
s.dependency "bigbluebutton-mobile-sdk-common" s.dependency "bigbluebutton-mobile-sdk-common"
end end

View File

@ -31,6 +31,7 @@ open class BBBSharedData {
public static let onScreenShareLocalIceCandidate = "onScreenShareLocalIceCandidate" // Broadcaster -> UI APP public static let onScreenShareLocalIceCandidate = "onScreenShareLocalIceCandidate" // Broadcaster -> UI APP
public static let onScreenShareSignalingStateChange = "onScreenShareSignalingStateChange" // Broadcaster -> UI APP public static let onScreenShareSignalingStateChange = "onScreenShareSignalingStateChange" // Broadcaster -> UI APP
public static let onApplicationTerminated = "onApplicationTerminated" // UI APP -> Broadcaster
} }

View File

@ -10,6 +10,11 @@ extension UserDefaults {
return string(forKey: BBBSharedData.SharedData.broadcastStarted) ?? "" return string(forKey: BBBSharedData.SharedData.broadcastStarted) ?? ""
} }
// UI APP -> Broadcaster
@objc open dynamic var onApplicationTerminated: String {
return string(forKey: BBBSharedData.SharedData.onApplicationTerminated) ?? ""
}
// Broadcaster -> UI APP // Broadcaster -> UI APP
@objc open dynamic var broadcastPaused: String { @objc open dynamic var broadcastPaused: String {
return string(forKey: BBBSharedData.SharedData.broadcastPaused) ?? "" return string(forKey: BBBSharedData.SharedData.broadcastPaused) ?? ""

View File

@ -106,4 +106,10 @@ open class BigBlueButtonSDK: NSObject {
observer2?.invalidate() observer2?.invalidate()
} }
public static func onAppTerminated(){
BBBSharedData
.getUserDefaults(appGroupName: self.appGroupName)
.set(BBBSharedData.generatePayload(), forKey: BBBSharedData.SharedData.onApplicationTerminated)
}
} }