1 Commits

Author SHA1 Message Date
Tiago Jacobs
7a5b3f8e86 Quick test for faking a call in callKit 2022-04-18 19:20:49 -03:00
45 changed files with 451 additions and 1939 deletions

1
.gitignore vendored
View File

@@ -95,4 +95,3 @@ Network Trash Folder
Temporary Items
.apdisk
/package-lock.json

View File

@@ -1,20 +1,20 @@
# bigbluebutton-mobile-tablet-sdk
# bigbluebutton-mobile-sdk
This repository contains BigBlueButton Mobile Tablet react-native component, that's used in our [sample implementation](https://github.com/bigbluebutton/bigbluebutton-mobile-tablet).
This repository contains BigBlueButton react-native component, that's used in our [sample implementation](https://github.com/bigbluebutton/bigbluebutton-mobile).
![version](https://img.shields.io/npm/v/bigbluebutton-mobile-tablet-sdk.svg)
![version](https://img.shields.io/npm/v/bigbluebutton-mobile-sdk.svg)
## Installation
```sh
npm install bigbluebutton-mobile-tablet-sdk
npm install bigbluebutton-mobile-sdk
```
## Usage
```js
import { BigBlueButtonMobile } from "bigbluebutton-mobile-tablet-sdk";
import { BigBlueButtonMobile } from "bigbluebutton-mobile-sdk";
// ...

View File

@@ -8,7 +8,6 @@
/* Begin PBXBuildFile section */
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; };
792D8E8E283FBED3008471C5 /* main.jsbundle in Resources */ = {isa = PBXBuildFile; fileRef = 792D8E8D283FBED3008471C5 /* main.jsbundle */; };
81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */; };
D4107C11428E565249543452 /* libPods-BigbluebuttonMobileSdkExample.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F8315799A5C1BF7D3955FE7A /* libPods-BigbluebuttonMobileSdkExample.a */; };
E34840357A40CF330A083CD4 /* libPods-BigBlueButtonMobileSdkBroadcastExample.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 2B60F7CB33D3D557C0DBFB9A /* libPods-BigBlueButtonMobileSdkBroadcastExample.a */; };
@@ -45,12 +44,12 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
008F07F21AC5B25A0029DE68 /* main.jsbundle */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = main.jsbundle; sourceTree = "<group>"; };
13B07F961A680F5B00A75B9A /* BigbluebuttonMobileSdkExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = BigbluebuttonMobileSdkExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
13B07FB51A68108700A75B9A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Images.xcassets; path = BigbluebuttonMobileSdkExample/Images.xcassets; sourceTree = "<group>"; };
13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = BigbluebuttonMobileSdkExample/Info.plist; sourceTree = "<group>"; };
2B60F7CB33D3D557C0DBFB9A /* libPods-BigBlueButtonMobileSdkBroadcastExample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-BigBlueButtonMobileSdkBroadcastExample.a"; sourceTree = BUILT_PRODUCTS_DIR; };
64F9B7FFD471972C20137BD6 /* Pods-BigBlueButtonMobileSdkBroadcastExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-BigBlueButtonMobileSdkBroadcastExample.debug.xcconfig"; path = "Target Support Files/Pods-BigBlueButtonMobileSdkBroadcastExample/Pods-BigBlueButtonMobileSdkBroadcastExample.debug.xcconfig"; sourceTree = "<group>"; };
792D8E8D283FBED3008471C5 /* main.jsbundle */ = {isa = PBXFileReference; lastKnownFileType = text; path = main.jsbundle; sourceTree = "<group>"; };
7EC638C00C2D62DDC1E73F8E /* Pods-BigbluebuttonMobileSdkExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-BigbluebuttonMobileSdkExample.debug.xcconfig"; path = "Target Support Files/Pods-BigbluebuttonMobileSdkExample/Pods-BigbluebuttonMobileSdkExample.debug.xcconfig"; sourceTree = "<group>"; };
81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = LaunchScreen.storyboard; path = BigbluebuttonMobileSdkExample/LaunchScreen.storyboard; sourceTree = "<group>"; };
B2C3B4EA07C7BC3E4B51B5D2 /* Pods-BigBlueButtonMobileSdkBroadcastExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-BigBlueButtonMobileSdkBroadcastExample.release.xcconfig"; path = "Target Support Files/Pods-BigBlueButtonMobileSdkBroadcastExample/Pods-BigBlueButtonMobileSdkBroadcastExample.release.xcconfig"; sourceTree = "<group>"; };
@@ -95,10 +94,10 @@
13B07FAE1A68108700A75B9A /* BigbluebuttonMobileSdkExample */ = {
isa = PBXGroup;
children = (
792D8E8D283FBED3008471C5 /* main.jsbundle */,
F1CF7F4527D1A4CB00E0C7F1 /* Constants.swift */,
F1CF7F4727D1AAAF00E0C7F1 /* AppDelegate.swift */,
F1D24A0C27D18E21003B294F /* BigbluebuttonMobileSdkExample.entitlements */,
008F07F21AC5B25A0029DE68 /* main.jsbundle */,
13B07FB51A68108700A75B9A /* Images.xcassets */,
13B07FB61A68108700A75B9A /* Info.plist */,
81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */,
@@ -262,7 +261,6 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
792D8E8E283FBED3008471C5 /* main.jsbundle in Resources */,
81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */,
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */,
);

View File

@@ -67,7 +67,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
disableMainThreadChecker = "YES"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"

View File

@@ -6,7 +6,6 @@
import UIKit
import bigbluebutton_mobile_sdk
import bigbluebutton_mobile_sdk_common
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, RCTBridgeDelegate {
@@ -36,11 +35,7 @@ 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)

View File

@@ -40,6 +40,7 @@
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
<string>voip</string>
</array>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>

View File

@@ -1,12 +1,12 @@
PODS:
- bigbluebutton-mobile-sdk (0.1.25):
- bigbluebutton-mobile-sdk (0.1.11):
- bigbluebutton-mobile-sdk-common
- React-Core
- WebRTC-lib
- bigbluebutton-mobile-sdk-broadcast-upload-extension (0.1.25):
- bigbluebutton-mobile-sdk-broadcast-upload-extension (0.1.11):
- bigbluebutton-mobile-sdk-common
- WebRTC-lib
- bigbluebutton-mobile-sdk-common (0.1.25):
- bigbluebutton-mobile-sdk-common (0.1.11):
- WebRTC-lib
- boost-for-react-native (1.63.0)
- DoubleConversion (1.1.6)
@@ -361,9 +361,9 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon/yoga"
SPEC CHECKSUMS:
bigbluebutton-mobile-sdk: 242a4e5d15161c650434cc154e96c47c52ab5691
bigbluebutton-mobile-sdk-broadcast-upload-extension: 62c3ef96b1aba16fc5f10021e000cc64209392b8
bigbluebutton-mobile-sdk-common: fc8a8c0b1096b045b285497cc599d6ce67421fcb
bigbluebutton-mobile-sdk: ed5b306bc5161dcc35cf9e870d91ab12c64810b6
bigbluebutton-mobile-sdk-broadcast-upload-extension: af7d83d6e0bd547876f25350b84bc94561ba14cf
bigbluebutton-mobile-sdk-common: 4c14fa0c920d9cd7d57ab2d1aebb8c0ebb0065c4
boost-for-react-native: 39c7adb57c4e60d6c5479dd8623128eb5b3f0f2c
DoubleConversion: cde416483dac037923206447da6e1454df403714
FBLazyVector: 3bb422f41b18121b71783a905c10e58606f7dc3e

View File

@@ -1,4 +0,0 @@
{
"name": "BigbluebuttonMobileSdkExample",
"displayName": "BigbluebuttonMobileSdk Example"
}

File diff suppressed because one or more lines are too long

View File

@@ -33,7 +33,7 @@ export default function App() {
<View style={styles.container}>
{loadComponent ? (
<BigBlueButtonMobile
url="https://mobile.bbb.imdt.dev"
url="https://demo-ios.bigbluebutton.org"
style={styles.bbb}
onError={(content: any) => handleOnError(content)}
onSuccess={() => console.log('URL Valid')}

View File

@@ -12,12 +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 createScreenShareOfferObserver:NSKeyValueObservation?;
private var setScreenShareRemoteSDPOBserver:NSKeyValueObservation?;
private var createOfferCallObserver:NSKeyValueObservation?;
private var setRemoteSDPCallObserver:NSKeyValueObservation?;
private var addScreenShareRemoteIceCandidateObserver:NSKeyValueObservation?;
private var onApplicationTerminatedObserver:NSKeyValueObservation?;
private var onBroadcastStoppedObserver:NSKeyValueObservation?;
private var screenBroadcaster:ScreenBroadcasterService?;
private var screenBroadcaster:ScreenBroadcaster?;
open func setAppGroupName(appGroupName:String) {
logger.info("Received appGroupName: \(appGroupName)")
@@ -36,25 +34,11 @@ open class BBBSampleHandler : RPBroadcastSampleHandler {
logger.info("ReplayKit2 event - broadcastStarted - persisting information on UserDefaults")
userDefaults.set(BBBSharedData.generatePayload(), forKey: BBBSharedData.SharedData.broadcastStarted)
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)
}
// Handle click in stop broadcast
logger.info("Configuring observer for stop broadcast")
self.onBroadcastStoppedObserver = userDefaults.observe(\.onBroadcastStopped, options: [.new]) { (defaults, change) in
self.logger.info("Observer detected a onBroadcastStopped request!")
finishBroadcastGracefully(self)
}
self.screenBroadcaster = ScreenBroadcaster(appGroupName: appGroupName)
// Listen for createOffer requests from the UI APP
logger.info("Configuring observer for createOffer")
self.createScreenShareOfferObserver = userDefaults.observe(\.createScreenShareOffer, options: [.new]) { (defaults, change) in
self.createOfferCallObserver = userDefaults.observe(\.createScreenShareOffer, options: [.new]) { (defaults, change) in
self.logger.info("Observer detected a createScreenShareOffer request!")
Task.init {
@@ -72,7 +56,7 @@ open class BBBSampleHandler : RPBroadcastSampleHandler {
}
logger.info("Configuring observer for setRemoteSDP")
self.setScreenShareRemoteSDPOBserver = userDefaults.observe(\.setScreenShareRemoteSDP, options: [.new]) { (defaults, change) in
self.setRemoteSDPCallObserver = 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")

View File

@@ -1,16 +0,0 @@
//
// 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

@@ -1,17 +0,0 @@
//
// 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

@@ -6,12 +6,11 @@
import os
import bigbluebutton_mobile_sdk_common
import WebRTC
import UIKit
open class ScreenBroadcasterService {
open class ScreenBroadcaster {
// Logger (these messages are displayed in the console application)
private var logger = os.Logger(subsystem: "BigBlueButtonMobileSDK", category: "ScreenBroadcasterService")
private var webRTCClient:ScreenShareWebRTCClient
private var logger = os.Logger(subsystem: "BigBlueButtonMobileSDK", category: "ScreenBroadcaster")
private var webRTCClient:WebRTCClient
private var appGroupName:String
private let encoder = JSONEncoder()
public var isConnected:Bool = false
@@ -19,14 +18,12 @@ open class ScreenBroadcasterService {
init(appGroupName: String) {
self.appGroupName = appGroupName
webRTCClient = ScreenShareWebRTCClient(iceServers: ["stun:stun.l.google.com:19302",
webRTCClient = WebRTCClient(iceServers: ["stun:stun.l.google.com:19302",
"stun:stun1.l.google.com:19302",
"stun:stun2.l.google.com:19302",
"stun:stun3.l.google.com:19302",
"stun:stun4.l.google.com:19302"])
webRTCClient.delegate = self
}
public func createOffer() async -> String? {
@@ -63,23 +60,6 @@ open class ScreenBroadcasterService {
if(!isConnected) {
self.logger.info("Ignoring pushVideoFrame - not connected")
} else {
var rotationFrame: RTCVideoRotation = ._0
var orientation = CGImagePropertyOrientation.up
if #available(iOS 11.0, *) {
if let orientationAttachment = CMGetAttachment(sampleBuffer, key: RPVideoSampleOrientationKey as CFString, attachmentModeOut: nil) as? NSNumber {
orientation = CGImagePropertyOrientation(rawValue: orientationAttachment.uint32Value) ?? .up
}
}
switch orientation.rawValue {
case UInt32(6):
rotationFrame = ._270
case UInt32(8):
rotationFrame = ._90
default:
rotationFrame = ._0
}
self.logger.info("pushing video")
let imageBuffer:CVImageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer)!
let timeStampNs: Int64 = Int64(CMTimeGetSeconds(CMSampleBufferGetPresentationTimeStamp(sampleBuffer)) * 1000000000)
@@ -89,7 +69,7 @@ open class ScreenBroadcasterService {
webRTCClient.setRatio(originalWidth: rtcPixlBuffer.width, originalHeight: rtcPixlBuffer.height)
}
let rtcVideoFrame = RTCVideoFrame(buffer: rtcPixlBuffer, rotation: rotationFrame, timeStampNs: timeStampNs)
let rtcVideoFrame = RTCVideoFrame(buffer: rtcPixlBuffer, rotation: ._0, timeStampNs: timeStampNs)
self.webRTCClient.push(videoFrame: rtcVideoFrame)
self.logger.info("video pushed")
}
@@ -97,9 +77,9 @@ open class ScreenBroadcasterService {
}
extension ScreenBroadcasterService: ScreenShareWebRTCClientDelegate {
extension ScreenBroadcaster: WebRTCClientDelegate {
public func webRTCClient(_ client: ScreenShareWebRTCClient, didDiscoverLocalCandidate rtcIceCandidate: RTCIceCandidate) {
public func webRTCClient(_ client: WebRTCClient, didDiscoverLocalCandidate rtcIceCandidate: RTCIceCandidate) {
do {
let iceCandidate = IceCandidate(from: rtcIceCandidate)
let iceCandidateAsJsonData = try self.encoder.encode(iceCandidate)
@@ -116,7 +96,7 @@ extension ScreenBroadcasterService: ScreenShareWebRTCClientDelegate {
}
}
public func webRTCClient(_ client: ScreenShareWebRTCClient, didChangeIceConnectionState state: RTCIceConnectionState) {
public func webRTCClient(_ client: WebRTCClient, didChangeIceConnectionState state: RTCIceConnectionState) {
switch state {
case .connected:
self.logger.info("didChangeConnectionState -> connected")
@@ -135,7 +115,7 @@ extension ScreenBroadcasterService: ScreenShareWebRTCClientDelegate {
}
}
public func webRTCClient(_ client: ScreenShareWebRTCClient, didChangeIceGatheringState state: RTCIceGatheringState) {
public func webRTCClient(_ client: WebRTCClient, didChangeIceGatheringState state: RTCIceGatheringState) {
switch state {
case .new:
self.logger.info("didChangeGatheringState -> new")
@@ -148,7 +128,7 @@ extension ScreenBroadcasterService: ScreenShareWebRTCClientDelegate {
}
}
public func webRTCClient(_ client: ScreenShareWebRTCClient, didChangeSignalingState state: RTCSignalingState) {
public func webRTCClient(_ client: WebRTCClient, didChangeSignalingState state: RTCSignalingState) {
var stateString = ""
switch(state) {
case .haveLocalOffer:

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_files = "Classes/*.{h,m,mm,swift}"
s.public_header_files = ["Classes/*.h"]
s.dependency "WebRTC-lib"
s.dependency "bigbluebutton-mobile-sdk-common"
end

View File

@@ -1,304 +0,0 @@
//
// AudioWebRTCClient.swift
//
// Created by Tiago Daniel Jacobs on 20/04/22.
import Foundation
import WebRTC
import os
public protocol AudioWebRTCClientDelegate: AnyObject {
func webRTCClient(_ client: AudioWebRTCClient, didDiscoverLocalCandidate candidate: RTCIceCandidate)
func webRTCClient(_ client: AudioWebRTCClient, didChangeIceConnectionState state: RTCIceConnectionState)
func webRTCClient(_ client: AudioWebRTCClient, didChangeIceGatheringState state: RTCIceGatheringState)
func webRTCClient(_ client: AudioWebRTCClient, didChangeSignalingState state: RTCSignalingState)
}
open class AudioWebRTCClient: NSObject {
private var logger = os.Logger(subsystem: "BigBlueButtonMobileSDK", category: "AudioWebRTCClient")
private var iceGatheringComplete:Bool = false
// The `RTCPeerConnectionFactory` is in charge of creating new RTCPeerConnection instances.
// A new RTCPeerConnection should be created every new call, but the factory is shared.
private static let factory: RTCPeerConnectionFactory = {
RTCInitializeSSL()
let videoEncoderFactory = RTCDefaultVideoEncoderFactory()
let videoDecoderFactory = RTCDefaultVideoDecoderFactory()
videoEncoderFactory.preferredCodec = RTCVideoCodecInfo(name: kRTCVideoCodecVp8Name)
return RTCPeerConnectionFactory(encoderFactory: videoEncoderFactory, decoderFactory: videoDecoderFactory)
}()
public weak var delegate: AudioWebRTCClientDelegate?
private let peerConnection: RTCPeerConnection
private let rtcAudioSession = RTCAudioSession.sharedInstance()
private let audioQueue = DispatchQueue(label: "audio")
private let mediaConstrains = [kRTCMediaConstraintsOfferToReceiveAudio: kRTCMediaConstraintsValueTrue,
kRTCMediaConstraintsOfferToReceiveVideo: kRTCMediaConstraintsValueFalse]
private var videoSource: RTCVideoSource?
private var videoCapturer: RTCVideoCapturer?
private var localVideoTrack: RTCVideoTrack?
private var isRatioDefined:Bool=false
private var isActiveObserver1:NSKeyValueObservation?
@available(*, unavailable)
override init() {
fatalError("WebRTCClient:init is unavailable")
}
public required init(iceServers: [String]) {
let config = RTCConfiguration()
config.iceServers = [RTCIceServer(urlStrings: iceServers)]
// Unified plan is more superior than planB
config.sdpSemantics = .unifiedPlan
// gatherContinually will let WebRTC to listen to any network changes and send any new candidates to the other client
// gatherOnce will get candidates only on beginning (this is how BBB expect to have it for now, so we use this one)
config.continualGatheringPolicy = .gatherOnce
// Define media constraints. DtlsSrtpKeyAgreement is required to be true to be able to connect with web browsers.
let constraints = RTCMediaConstraints(mandatoryConstraints: nil,
optionalConstraints: ["DtlsSrtpKeyAgreement":kRTCMediaConstraintsValueTrue])
guard let peerConnection = AudioWebRTCClient.factory.peerConnection(with: config, constraints: constraints, delegate: nil) else {
fatalError("Could not create new RTCPeerConnection")
}
self.peerConnection = peerConnection
super.init()
createMediaSenders()
configureAudioSession()
self.peerConnection.delegate = self
}
// MARK: Signaling
public func offer() async throws -> RTCSessionDescription {
let constrains = RTCMediaConstraints(mandatoryConstraints: self.mediaConstrains, optionalConstraints: nil)
let sdp = try await self.peerConnection.offer(for: constrains)
try await self.peerConnection.setLocalDescription(sdp)
return sdp
}
public func setRemoteSDP(remoteSDP: String) async throws {
let rtcSessionDescription = RTCSessionDescription(type: RTCSdpType.answer, sdp: remoteSDP)
try await self.peerConnection.setRemoteDescription(rtcSessionDescription)
}
// public func setRemoteCandidate(remoteIceCandidate: IceCandidate) async throws {
// let rtcRemoteCandidate = RTCIceCandidate(sdp: remoteIceCandidate.candidate, sdpMLineIndex: remoteIceCandidate.sdpMLineIndex, sdpMid: remoteIceCandidate.sdpMid)
// try await self.peerConnection.add(rtcRemoteCandidate)
// }
func set(remoteCandidate: RTCIceCandidate, completion: @escaping (Error?) -> ()) {
self.peerConnection.add(remoteCandidate, completionHandler: completion)
}
// MARK: Media
public func push(videoFrame: RTCVideoFrame) {
guard videoCapturer != nil, videoSource != nil else { return }
videoSource!.capturer(videoCapturer!, didCapture: videoFrame)
print("RTCVideoFrame pushed to server.")
}
private func configureAudioSession() {
self.rtcAudioSession.lockForConfiguration()
do {
try self.rtcAudioSession.setCategory(AVAudioSession.Category.playAndRecord.rawValue)
try self.rtcAudioSession.session.setCategory(AVAudioSession.Category.playAndRecord, options: [AVAudioSession.CategoryOptions.mixWithOthers])
try self.rtcAudioSession.setMode(AVAudioSession.Mode.voiceChat.rawValue)
} catch let error {
debugPrint("Error changing AVAudioSession category: \(error)")
}
self.rtcAudioSession.unlockForConfiguration()
self.isActiveObserver1 = self.rtcAudioSession.observe(\.isActive, options: [.new]) { (defaults, change) in
if(!self.rtcAudioSession.isActive) {
self.logger.info("isActive changed to false, restoring it");
self.restoreAudioSession()
}
}
}
private func createMediaSenders() {
let streamId = "stream"
// Audio
let audioTrack = self.createAudioTrack()
self.peerConnection.add(audioTrack, streamIds: [streamId])
}
private func createAudioTrack() -> RTCAudioTrack {
let audioConstrains = RTCMediaConstraints(mandatoryConstraints: nil, optionalConstraints: nil)
let audioSource = AudioWebRTCClient.factory.audioSource(with: audioConstrains)
let audioTrack = AudioWebRTCClient.factory.audioTrack(with: audioSource, trackId: "audio0")
return audioTrack
}
}
// MARK: RTCPeerConnectionDelegate Methods
extension AudioWebRTCClient: RTCPeerConnectionDelegate {
public func peerConnection(_ peerConnection: RTCPeerConnection, didChange stateChanged: RTCSignalingState) {
self.logger.info("peerConnection new signaling state: \(stateChanged.rawValue)")
self.delegate?.webRTCClient(self, didChangeSignalingState: stateChanged)
}
public func peerConnection(_ peerConnection: RTCPeerConnection, didAdd stream: RTCMediaStream) {
self.logger.info("peerConnection did add stream \(stream.streamId)")
}
public func peerConnection(_ peerConnection: RTCPeerConnection, didRemove stream: RTCMediaStream) {
self.logger.info("peerConnection did remove stream \(stream.streamId)")
}
public func peerConnectionShouldNegotiate(_ peerConnection: RTCPeerConnection) {
self.logger.info("peerConnection should negotiate")
}
public func peerConnection(_ peerConnection: RTCPeerConnection, didChange newState: RTCIceConnectionState) {
self.logger.info("peerConnection new connection state: \(newState.rawValue)")
self.delegate?.webRTCClient(self, didChangeIceConnectionState: newState)
}
public func peerConnection(_ peerConnection: RTCPeerConnection, didChange newState: RTCIceGatheringState) {
self.logger.info("peerConnection new gathering state: \(newState.rawValue)")
self.delegate?.webRTCClient(self, didChangeIceGatheringState: newState)
if(newState == .complete) {
self.logger.info("peerConnection new gathering state is COMPLETE")
self.iceGatheringComplete = true
} else if(newState == .gathering) {
self.logger.info("peerConnection new gathering state is GATHERING")
} else if(newState == .new) {
self.logger.info("peerConnection new gathering state is NEW")
}
}
public func isIceGatheringComplete() -> Bool {
return iceGatheringComplete;
}
public func peerConnection(_ peerConnection: RTCPeerConnection, didGenerate candidate: RTCIceCandidate) {
self.logger.info("peerConnection discovered new candidate")
self.delegate?.webRTCClient(self, didDiscoverLocalCandidate: candidate)
}
public func peerConnection(_ peerConnection: RTCPeerConnection, didRemove candidates: [RTCIceCandidate]) {
self.logger.info("peerConnection did remove candidate(s)")
}
public func peerConnection(_ peerConnection: RTCPeerConnection, didOpen dataChannel: RTCDataChannel) {
self.logger.info("peerConnection did open data channel")
}
}
extension AudioWebRTCClient {
private func setTrackEnabled<T: RTCMediaStreamTrack>(_ type: T.Type, isEnabled: Bool) {
peerConnection.transceivers
.compactMap { return $0.sender.track as? T }
.forEach { $0.isEnabled = isEnabled }
}
}
// MARK: - Video control
extension AudioWebRTCClient {
func hideVideo() {
self.setVideoEnabled(false)
}
func showVideo() {
self.setVideoEnabled(true)
}
private func setVideoEnabled(_ isEnabled: Bool) {
setTrackEnabled(RTCVideoTrack.self, isEnabled: isEnabled)
}
}
// MARK:- Audio control
extension AudioWebRTCClient {
func muteAudio() {
self.setAudioEnabled(false)
}
func unmuteAudio() {
self.setAudioEnabled(true)
}
// Fallback to the default playing device: headphones/bluetooth/ear speaker
func speakerOff() {
self.audioQueue.async { [weak self] in
guard let self = self else {
return
}
self.rtcAudioSession.lockForConfiguration()
do {
try self.rtcAudioSession.setCategory(AVAudioSession.Category.playAndRecord.rawValue)
try self.rtcAudioSession.setMode(AVAudioSession.Mode.voiceChat.rawValue)
try self.rtcAudioSession.overrideOutputAudioPort(.none)
} catch let error {
debugPrint("Error setting AVAudioSession category: \(error)")
}
self.rtcAudioSession.unlockForConfiguration()
}
}
// Force speaker
func speakerOn() {
self.audioQueue.async { [weak self] in
guard let self = self else {
return
}
self.rtcAudioSession.lockForConfiguration()
do {
try self.rtcAudioSession.setCategory(AVAudioSession.Category.playAndRecord.rawValue)
try self.rtcAudioSession.overrideOutputAudioPort(.speaker)
try self.rtcAudioSession.setActive(true)
} catch let error {
debugPrint("Couldn't force audio to speaker: \(error)")
}
self.rtcAudioSession.unlockForConfiguration()
}
}
public func restoreAudioSession() {
self.audioQueue.async { [weak self] in
guard let self = self else {
return
}
do {
self.rtcAudioSession.lockForConfiguration()
try RTCAudioSession.sharedInstance().setActive(true)
self.rtcAudioSession.unlockForConfiguration()
} catch let error {
debugPrint("Couldn't restore isActive: \(error)")
}
}
}
private func setAudioEnabled(_ isEnabled: Bool) {
setTrackEnabled(RTCAudioTrack.self, isEnabled: isEnabled)
}
}
extension AudioWebRTCClient: RTCDataChannelDelegate {
public func dataChannelDidChangeState(_ dataChannel: RTCDataChannel) {
debugPrint("dataChannel did change state: \(dataChannel.readyState)")
}
public func dataChannel(_ dataChannel: RTCDataChannel, didReceiveMessageWith buffer: RTCDataBuffer) {
debugPrint("dataChannel did receive message with buffer: \(buffer)")
}
}

View File

@@ -32,10 +32,6 @@ open class BBBSharedData {
public static let onScreenShareSignalingStateChange = "onScreenShareSignalingStateChange" // Broadcaster -> UI APP
public static let onApplicationTerminated = "onApplicationTerminated" // UI APP -> Broadcaster
public static let onBroadcastStopped = "onBroadcastStopped" // UI APP -> Broadcaster
}
// Get reference to userDefaults object (that's actually the object used to share information among UI APP and the BroadcastUploadExtension APP)

View File

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

View File

@@ -9,14 +9,14 @@ import Foundation
import WebRTC
import os
public protocol ScreenShareWebRTCClientDelegate: AnyObject {
func webRTCClient(_ client: ScreenShareWebRTCClient, didDiscoverLocalCandidate candidate: RTCIceCandidate)
func webRTCClient(_ client: ScreenShareWebRTCClient, didChangeIceConnectionState state: RTCIceConnectionState)
func webRTCClient(_ client: ScreenShareWebRTCClient, didChangeIceGatheringState state: RTCIceGatheringState)
func webRTCClient(_ client: ScreenShareWebRTCClient, didChangeSignalingState state: RTCSignalingState)
public protocol WebRTCClientDelegate: AnyObject {
func webRTCClient(_ client: WebRTCClient, didDiscoverLocalCandidate candidate: RTCIceCandidate)
func webRTCClient(_ client: WebRTCClient, didChangeIceConnectionState state: RTCIceConnectionState)
func webRTCClient(_ client: WebRTCClient, didChangeIceGatheringState state: RTCIceGatheringState)
func webRTCClient(_ client: WebRTCClient, didChangeSignalingState state: RTCSignalingState)
}
open class ScreenShareWebRTCClient: NSObject {
open class WebRTCClient: NSObject {
private var logger = os.Logger(subsystem: "BigBlueButtonMobileSDK", category: "WebRTCClient")
// The `RTCPeerConnectionFactory` is in charge of creating new RTCPeerConnection instances.
@@ -29,12 +29,12 @@ open class ScreenShareWebRTCClient: NSObject {
return RTCPeerConnectionFactory(encoderFactory: videoEncoderFactory, decoderFactory: videoDecoderFactory)
}()
public weak var delegate: ScreenShareWebRTCClientDelegate?
public weak var delegate: WebRTCClientDelegate?
private let peerConnection: RTCPeerConnection
private let rtcAudioSession = RTCAudioSession.sharedInstance()
private let audioQueue = DispatchQueue(label: "audio")
private let mediaConstrains = [kRTCMediaConstraintsOfferToReceiveAudio: kRTCMediaConstraintsValueFalse,
kRTCMediaConstraintsOfferToReceiveVideo: kRTCMediaConstraintsValueFalse]
private let mediaConstrains = [kRTCMediaConstraintsOfferToReceiveAudio: kRTCMediaConstraintsValueTrue,
kRTCMediaConstraintsOfferToReceiveVideo: kRTCMediaConstraintsValueTrue]
private var videoSource: RTCVideoSource?
private var videoCapturer: RTCVideoCapturer?
private var localVideoTrack: RTCVideoTrack?
@@ -60,7 +60,7 @@ open class ScreenShareWebRTCClient: NSObject {
let constraints = RTCMediaConstraints(mandatoryConstraints: nil,
optionalConstraints: ["DtlsSrtpKeyAgreement":kRTCMediaConstraintsValueTrue])
guard let peerConnection = ScreenShareWebRTCClient.factory.peerConnection(with: config, constraints: constraints, delegate: nil) else {
guard let peerConnection = WebRTCClient.factory.peerConnection(with: config, constraints: constraints, delegate: nil) else {
fatalError("Could not create new RTCPeerConnection")
}
@@ -135,9 +135,9 @@ open class ScreenShareWebRTCClient: NSObject {
}*/
private func createVideoTrack() -> RTCVideoTrack {
videoSource = ScreenShareWebRTCClient.factory.videoSource(forScreenCast: true)
videoSource = WebRTCClient.factory.videoSource(forScreenCast: true)
videoCapturer = RTCVideoCapturer(delegate: videoSource!)
let videoTrack = ScreenShareWebRTCClient.factory.videoTrack(with: videoSource!, trackId: "video0")
let videoTrack = WebRTCClient.factory.videoTrack(with: videoSource!, trackId: "video0")
videoTrack.isEnabled = true
return videoTrack
}
@@ -157,7 +157,7 @@ open class ScreenShareWebRTCClient: NSObject {
// MARK: RTCPeerConnectionDelegate Methods
extension ScreenShareWebRTCClient: RTCPeerConnectionDelegate {
extension WebRTCClient: RTCPeerConnectionDelegate {
public func peerConnection(_ peerConnection: RTCPeerConnection, didChange stateChanged: RTCSignalingState) {
self.logger.info("peerConnection new signaling state: \(stateChanged.rawValue)")
@@ -209,7 +209,7 @@ extension ScreenShareWebRTCClient: RTCPeerConnectionDelegate {
}
}
extension ScreenShareWebRTCClient {
extension WebRTCClient {
private func setTrackEnabled<T: RTCMediaStreamTrack>(_ type: T.Type, isEnabled: Bool) {
peerConnection.transceivers
.compactMap { return $0.sender.track as? T }
@@ -219,7 +219,7 @@ extension ScreenShareWebRTCClient {
// MARK: - Video control
extension ScreenShareWebRTCClient {
extension WebRTCClient {
func hideVideo() {
self.setVideoEnabled(false)
}
@@ -233,7 +233,7 @@ extension ScreenShareWebRTCClient {
// MARK:- Audio control
extension ScreenShareWebRTCClient {
extension WebRTCClient {
func muteAudio() {
self.setAudioEnabled(false)
}
@@ -284,7 +284,7 @@ extension ScreenShareWebRTCClient {
}
}
extension ScreenShareWebRTCClient: RTCDataChannelDelegate {
extension WebRTCClient: RTCDataChannelDelegate {
public func dataChannelDidChangeState(_ dataChannel: RTCDataChannel) {
debugPrint("dataChannel did change state: \(dataChannel.readyState)")
}

View File

@@ -1,8 +0,0 @@
//
// WebRTCClientDelegate.swift
// bigbluebutton-mobile-sdk
//
// Created by Tiago Daniel Jacobs on 20/04/22.
//
import Foundation

View File

@@ -8,8 +8,6 @@
import Foundation
import os
import bigbluebutton_mobile_sdk_common
import AVFAudio
import React
open class BigBlueButtonSDK: NSObject {
// Logger (these messages are displayed in the console application)
@@ -23,7 +21,6 @@ open class BigBlueButtonSDK: NSObject {
private static var observer4: NSKeyValueObservation?
private static var observer5: NSKeyValueObservation?
private static var observer6: NSKeyValueObservation?
private static var observer7: NSKeyValueObservation?
public static func initialize(broadcastExtensionBundleId:String, appGroupName:String) {
self.broadcastExtensionBundleId = broadcastExtensionBundleId
@@ -87,19 +84,6 @@ open class BigBlueButtonSDK: NSObject {
logger.info("Detected a change in userDefaults for key addScreenShareRemoteIceCandidateCompleted")
ReactNativeEventEmitter.emitter.sendEvent(withName: ReactNativeEventEmitter.EVENT.onAddScreenShareRemoteIceCandidateCompleted.rawValue, body: nil)
}
//addScreenShareRemoteIceCandidateCompleted
observer7 = userDefaults?.observe(\.broadcastFinished, options: [.new]) { (defaults, change) in
logger.info("Detected a change in userDefaults for key broadcastFinished")
ReactNativeEventEmitter.emitter.sendEvent(withName: ReactNativeEventEmitter.EVENT.onBroadcastFinished.rawValue, body: nil)
}
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playback, options: [AVAudioSession.CategoryOptions.mixWithOthers])
try AVAudioSession.sharedInstance().setPrefersNoInterruptionsFromSystemAlerts(true)
} catch let error {
logger.error("Error configuring audio session \(error.localizedDescription)")
}
}
public static func getBroadcastExtensionBundleId() -> String {
@@ -114,16 +98,5 @@ open class BigBlueButtonSDK: NSObject {
observer1?.invalidate()
observer2?.invalidate()
}
public static func onAppTerminated(){
logger.info("onAppTerminated called")
BBBSharedData
.getUserDefaults(appGroupName: self.appGroupName)
.set(BBBSharedData.generatePayload(), forKey: BBBSharedData.SharedData.onApplicationTerminated)
}
public static func handleDeepLink(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]){
RCTLinkingManager.application(app, open: url, options: options)
}
}

View File

@@ -1,136 +0,0 @@
//
// FullAudioService.swift
// bigbluebutton-mobile-sdk
//
// Created by Tiago Daniel Jacobs on 20/04/22.
//
import os
import bigbluebutton_mobile_sdk_common
import WebRTC
open class FullAudioService {
// Logger (these messages are displayed in the console application)
private var logger = os.Logger(subsystem: "BigBlueButtonMobileSDK", category: "FullAudioService")
private var webRTCClient:AudioWebRTCClient?
private let encoder = JSONEncoder()
public func createOffer() async -> String? {
do{
webRTCClient = AudioWebRTCClient(iceServers: ["stun:stun.l.google.com:19302",
"stun:stun1.l.google.com:19302",
"stun:stun2.l.google.com:19302",
"stun:stun3.l.google.com:19302",
"stun:stun4.l.google.com:19302"])
webRTCClient!.delegate = self
var createOfferIterations = 0
while(true) {
createOfferIterations += 1;
let rtcSessionDescription = try await self.webRTCClient!.offer()
// Immediately connect when ice gathering is complete or after 5 iterations (5 seconds)
if(webRTCClient!.isIceGatheringComplete()) {
logger.debug("Ice gathering complete!");
return rtcSessionDescription.sdp
} else if ( createOfferIterations > 5 ) {
logger.debug("Ice iterations exceeded, sending what we have");
return rtcSessionDescription.sdp
} else {
logger.debug("Ice gathering not yet complete, waiting 1s");
try await Task.sleep(nanoseconds: UInt64(1 * Double(NSEC_PER_SEC)))
}
}
} catch {
logger.error("Error on webRTCClient.offer")
return nil
}
}
public func setRemoteSDP(remoteSDP:String) async -> Bool {
do {
try await self.webRTCClient!.setRemoteSDP(remoteSDP: remoteSDP)
return true
}
catch {
return false
}
}
}
extension FullAudioService: AudioWebRTCClientDelegate {
public func webRTCClient(_ client: AudioWebRTCClient, didDiscoverLocalCandidate rtcIceCandidate: RTCIceCandidate) {
do {
let iceCandidate = IceCandidate(from: rtcIceCandidate)
let iceCandidateAsJsonData = try self.encoder.encode(iceCandidate)
let iceCandidateAsJsonString = String(decoding: iceCandidateAsJsonData, as: UTF8.self)
print("---- ICE CANDIDATE \(iceCandidateAsJsonString) ")
} catch {
self.logger.error("Error handling ICE candidate")
}
}
public func webRTCClient(_ client: AudioWebRTCClient, didChangeIceConnectionState state: RTCIceConnectionState) {
switch state {
case .connected:
self.logger.info("didChangeConnectionState -> connected")
case .completed:
self.logger.info("didChangeConnectionState -> completed")
case .disconnected:
self.logger.info("didChangeConnectionState -> disconnected")
case .failed:
self.logger.info("didChangeConnectionState -> failed")
case .closed:
self.logger.info("didChangeConnectionState -> closed")
case .new, .checking, .count:
break
@unknown default:
print("Unknown connection state.")
}
}
public func webRTCClient(_ client: AudioWebRTCClient, didChangeIceGatheringState state: RTCIceGatheringState) {
switch state {
case .new:
self.logger.info("didChangeGatheringState -> new")
case .gathering:
self.logger.info("didChangeGatheringState -> gathering")
case .complete:
self.logger.info("didChangeGatheringState -> complete")
@unknown default:
self.logger.error("Unknown gathering state: \(state.rawValue)")
}
}
public func webRTCClient(_ client: AudioWebRTCClient, didChangeSignalingState state: RTCSignalingState) {
var stateString = ""
switch(state) {
case .haveLocalOffer:
self.logger.info("peerConnection new signaling state -> haveLocalOffer")
stateString = "have-local-offer"
case .haveLocalPrAnswer:
self.logger.info("peerConnection new signaling state -> haveLocalPrAnswer")
stateString = "have-local-pranswer"
case .haveRemoteOffer:
self.logger.info("peerConnection new signaling state -> haveRemoteOffer")
stateString = "have-remote-offer"
case .haveRemotePrAnswer:
self.logger.info("peerConnection new signaling state -> haveRemotePrAnswer")
stateString = "have-remote-pranswer"
case .stable:
self.logger.info("peerConnection new signaling state -> stable")
stateString = "stable"
case .closed:
self.logger.info("peerConnection new signaling state -> closed")
stateString = "closed"
default:
self.logger.error("peerConnection new signaling state -> UNKNOWN")
}
}
}

View File

@@ -0,0 +1,35 @@
//
// CallKitDelegate.swift
// bigbluebutton-mobile-sdk
//
// Created by Tiago Daniel Jacobs on 18/04/22.
//
import Foundation
import CallKit
import os
class CallKitDelegate : NSObject {
private var logger = os.Logger(subsystem: "BigBlueButtonMobileSDK", category: "CallKitDelegate")
}
extension CallKitDelegate : CXProviderDelegate {
func providerDidReset(_ provider: CXProvider) {
logger.info("OI1")
}
func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {
action.fulfill()
}
func provider(_ provider: CXProvider, perform action: CXStartCallAction) {
action.fulfill()
}
func provider(_ provider: CXProvider, perform action: CXEndCallAction) {
action.fulfill()
}
}

View File

@@ -1,15 +0,0 @@
//
// FullAudioServiceManager.m
//
// Created by Tiago Daniel Jacobs on 20/04/22.
//
#import <Foundation/Foundation.h>
#import "React/RCTBridgeModule.h"
@interface RCT_EXTERN_REMAP_MODULE(BBBN_FullAudioService, FullAudioServiceManager, NSObject)
RCT_EXTERN_METHOD(createFullAudioOffer)
RCT_EXTERN_METHOD(setFullAudioRemoteSDP: (NSString *)remoteSDP)
RCT_EXTERN_METHOD(addFullAudioRemoteIceCandidate: (NSString *)remoteCandidate)
@end

View File

@@ -1,49 +0,0 @@
//
// FullAudioServiceManager.swift
//
// Created by Tiago Daniel Jacobs on 20/04/22.
//
import Foundation
import os
import bigbluebutton_mobile_sdk_common
import AVFAudio
@objc(FullAudioServiceManager)
class FullAudioServiceManager: NSObject {
// Logger (these messages are displayed in the console application)
private var logger = os.Logger(subsystem: "BigBlueButtonMobileSDK", category: "FullAudioServiceManager")
var audioSession = AVAudioSession.sharedInstance()
var player: AVAudioPlayer!
var fullAudioService: FullAudioService = FullAudioService( )
// React native exposed method (called when user click the button to share screen)
@objc func createFullAudioOffer() -> Void {
logger.info("createFullAudioOffer")
Task.init {
let optionalSdp = await self.fullAudioService.createOffer()
if(optionalSdp != nil){
let sdp = optionalSdp!
self.logger.info("Got SDP back from fullAudioService: \(sdp)")
ReactNativeEventEmitter.emitter.sendEvent(withName: ReactNativeEventEmitter.EVENT.onFullAudioOfferCreated.rawValue, body: sdp)
}
}
}
@objc func setFullAudioRemoteSDP(_ remoteSDP:String) -> Void {
logger.info("setFullAudioRemoteSDP call arrived on swift: \(remoteSDP)")
Task.init {
let setRemoteSDPAnswer = await self.fullAudioService.setRemoteSDP(remoteSDP: remoteSDP);
self.logger.info("Got \(setRemoteSDPAnswer) back from setRemoteSDP")
ReactNativeEventEmitter.emitter.sendEvent(withName: ReactNativeEventEmitter.EVENT.onSetFullAudioRemoteSDPCompleted.rawValue, body: nil)
}
}
@objc func addFullAudioRemoteIceCandidate(_ remoteCandidate:String) -> Void {
logger.info("!! NOT IMPLEMENTED !! addFullAudioRemoteIceCandidate call arrived on swift: \(remoteCandidate)")
}
}

View File

@@ -23,8 +23,6 @@ open class ReactNativeEventEmitter: RCTEventEmitter {
case onScreenShareLocalIceCandidate = "onScreenShareLocalIceCandidate"
case onScreenShareSignalingStateChange = "onScreenShareSignalingStateChange"
case onAddScreenShareRemoteIceCandidateCompleted = "onAddScreenShareRemoteIceCandidateCompleted"
case onFullAudioOfferCreated = "onFullAudioOfferCreated"
case onSetFullAudioRemoteSDPCompleted = "onSetFullAudioRemoteSDPCompleted"
}
override init() {

View File

@@ -9,7 +9,6 @@
#import "React/RCTBridgeModule.h"
@interface RCT_EXTERN_REMAP_MODULE(BBBN_ScreenShareService, ScreenShareServiceManager, NSObject)
RCT_EXTERN_METHOD(stopScreenShareBroadcastExtension)
RCT_EXTERN_METHOD(initializeScreenShare)
RCT_EXTERN_METHOD(createScreenShareOffer)
RCT_EXTERN_METHOD(setScreenShareRemoteSDP: (NSString *)remoteSDP)

View File

@@ -16,33 +16,35 @@ class ScreenShareServiceManager: NSObject {
var audioSession = AVAudioSession.sharedInstance()
var player: AVAudioPlayer!
@objc func stopScreenShareBroadcastExtension() -> Void {
BBBSharedData
.getUserDefaults(appGroupName: BigBlueButtonSDK.getAppGroupName())
.set(BBBSharedData.generatePayload(), forKey: BBBSharedData.SharedData.onBroadcastStopped)
}
// React native exposed method (called when user click the button to share screen)
@objc func initializeScreenShare() -> Void {
logger.info("initializeScreenShare")
self.activeAudioSession(bool: true)
let path = Bundle.main.path(forResource: "music2", ofType : "mp3")!
let url = URL(fileURLWithPath : path)
print("audioUrl2 = \(url)")
do {
Task.init {
do{
// try audioSession.setCategory(AVAudioSession.Category.playback, options: [AVAudioSession.CategoryOptions.mixWithOthers])
try audioSession.setCategory(AVAudioSession.Category.playAndRecord, options: [AVAudioSession.CategoryOptions.mixWithOthers])
try audioSession.setPrefersNoInterruptionsFromSystemAlerts(true)
try audioSession.setActive(true)
}catch{
print(error)
}
self.player = try AVAudioPlayer(contentsOf: url)
self.player.play()
self.playSoundInLoop()
let path = Bundle.main.path(forResource: "music2", ofType : "mp3")!
let url = URL(fileURLWithPath : path)
print("audioUrl2 = \(url)")
do {
player = try AVAudioPlayer(contentsOf: url)
player.play()
}
catch {
print (error)
}
}
catch {
logger.error("Error to play audio = \(url)")
}
// Request the system broadcast
logger.info("initializeScreenShare - requesting broadcast")
SystemBroadcastPicker.requestBroadcast()
@@ -93,23 +95,4 @@ class ScreenShareServiceManager: NSObject {
}
func activeAudioSession(bool BoolToActive: Bool){
do{
try audioSession.setActive(BoolToActive)
}catch{
logger.error("Error to change status of audioSession")
}
}
//This method prevents the sound that keeps the app active in the background
func playSoundInLoop(){
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 3000) {
self.logger.info("restarting music")
self.player.currentTime = 0.1;
self.playSoundInLoop()//recursive call
}
}
}

View File

@@ -6,6 +6,7 @@
import ReplayKit
import os
import CallKit
@objc(SystemBroadcastPickerManager)
class SystemBroadcastPickerManager: RCTViewManager {
@@ -18,10 +19,14 @@ class SystemBroadcastPicker : UIView {
// Logger (these messages are displayed in the console application)
private var logger = os.Logger(subsystem: "BigBlueButtonMobileSDK", category: "SystemBroadcastPicker")
private static var logger2 = os.Logger(subsystem: "BigBlueButtonMobileSDK", category: "SystemBroadcastPicker")
// Reference to the broadcast screen picker
private static var broadcastPicker: RPSystemBroadcastPickerView?
// Delegate for call kit methods
private static var callKitDelegate: CallKitDelegate = CallKitDelegate()
//initWithFrame to init view from code
override init(frame: CGRect) {
super.init(frame: frame)
@@ -55,13 +60,25 @@ class SystemBroadcastPicker : UIView {
*/
public static func requestBroadcast(/*data*/) {
// write the data that will be accessed from broadcast application
// DispatchQueue.main.async {
// for view in broadcastPicker?.subviews ?? [] {
// if let button = view as? UIButton {
// button.sendActions(for: .allEvents)
// }
// }
// }
self.logger2.info("AAAAAA!")
DispatchQueue.main.async {
for view in broadcastPicker?.subviews ?? [] {
if let button = view as? UIButton {
button.sendActions(for: .allEvents)
}
}
let provider = CXProvider(configuration: CXProviderConfiguration(localizedName: "My App"));
let controller = CXCallController();
provider.setDelegate(callKitDelegate, queue: nil)
let transaction = CXTransaction(action: CXStartCallAction(call: UUID(), handle: CXHandle(type: .generic, value: "Hey I am calling you!")))
controller.request(transaction, completion: { error in })
}
}
}

View File

@@ -1,7 +1,7 @@
{
"name": "bigbluebutton-mobile-tablet-sdk",
"version": "0.1.25",
"description": "This repository contains BigBlueButton react-native component, that's used in our [sample implementation](https://github.com/bigbluebutton/bigbluebutton-mobile-tablet).",
"name": "bigbluebutton-mobile-sdk",
"version": "0.1.15",
"description": "This repository contains BigBlueButton react-native component, that's used in our [sample implementation](https://github.com/bigbluebutton/bigbluebutton-mobile).",
"main": "lib/commonjs/index",
"module": "lib/module/index",
"types": "lib/typescript/index.d.ts",
@@ -38,13 +38,13 @@
"ios",
"android"
],
"repository": "https://github.com/bigbluebutton/bigbluebutton-mobile-tablet-sdk",
"repository": "https://github.com/bigbluebutton/bigbluebutton-mobile-sdk",
"author": "BigBlueButton Inc <bigbluebutton@bigbluebutton.org> (https://bigbluebutton.org)",
"license": "LGPL-3.0",
"bugs": {
"url": "https://github.com/bigbluebutton/bigbluebutton-mobile-tablet-sdk/issues"
"url": "https://github.com/bigbluebutton/bigbluebutton-mobile-sdk/issues"
},
"homepage": "https://github.com/bigbluebutton/bigbluebutton-mobile-tablet-sdk#readme",
"homepage": "https://github.com/bigbluebutton/bigbluebutton-mobile-sdk#readme",
"publishConfig": {
"registry": "https://registry.npmjs.org/"
},
@@ -63,8 +63,8 @@
"jest": "^26.0.1",
"pod-install": "^0.1.0",
"prettier": "^2.0.5",
"react": "17.0.2",
"react-native": "0.68.1",
"react": "16.13.1",
"react-native": "^0.67.2",
"react-native-builder-bob": "^0.18.0",
"release-it": "^14.2.2",
"typescript": "^4.1.3"

View File

@@ -1,13 +0,0 @@
import type { MutableRefObject } from 'react';
import type { EmitterSubscription } from 'react-native';
import nativeEmitter from '../native-messaging/emitter';
export function setupListener(_webViewRef: MutableRefObject<any>):EmitterSubscription {
// Resolve promise when SDP offer is available
return nativeEmitter.addListener('onBroadcastFinished', () => {
console.log(`Broadcast finished`);
_webViewRef.current.injectJavaScript(
`window.bbbMobileScreenShareBroadcastFinishedCallback && window.bbbMobileScreenShareBroadcastFinishedCallback();`
);
});
}

View File

@@ -1,10 +1,9 @@
import type { MutableRefObject } from 'react';
import type { EmitterSubscription } from 'react-native';
import nativeEmitter from '../native-messaging/emitter';
export function setupListener(_webViewRef: MutableRefObject<any>):EmitterSubscription {
export function setupListener(_webViewRef: MutableRefObject<any>) {
// Resolve promise when SDP offer is available
return nativeEmitter.addListener(
nativeEmitter.addListener(
'onScreenShareLocalIceCandidate',
(jsonEncodedIceCandidate) => {
let iceCandidate = JSON.parse(jsonEncodedIceCandidate);
@@ -13,7 +12,7 @@ export function setupListener(_webViewRef: MutableRefObject<any>):EmitterSubscri
}
const event = { candidate: iceCandidate };
_webViewRef.current.injectJavaScript(
`window.bbbMobileScreenShareIceCandidateCallback && window.bbbMobileScreenShareIceCandidateCallback(${JSON.stringify(
`window.bbbMobileScreenShareIceCandidateCallback(${JSON.stringify(
event
)});`
);

View File

@@ -1,13 +1,12 @@
import type { MutableRefObject } from 'react';
import type { EmitterSubscription } from 'react-native';
import nativeEmitter from '../native-messaging/emitter';
export function setupListener(_webViewRef: MutableRefObject<any>):EmitterSubscription {
export function setupListener(_webViewRef: MutableRefObject<any>) {
// Resolve promise when SDP offer is available
return nativeEmitter.addListener('onScreenShareSignalingStateChange', (newState) => {
nativeEmitter.addListener('onScreenShareSignalingStateChange', (newState) => {
console.log(`Temos um novo state: ${newState}`);
_webViewRef.current.injectJavaScript(
`window.bbbMobileScreenShareSignalingStateChangeCallback && window.bbbMobileScreenShareSignalingStateChangeCallback(${JSON.stringify(
`window.bbbMobileScreenShareSignalingStateChangeCallback(${JSON.stringify(
newState
)});`
);

View File

@@ -1,11 +1,10 @@
import { EmitterSubscription, Platform, ViewStyle } from 'react-native';
import { Platform, ViewStyle } from 'react-native';
import React, { useEffect, useRef } from 'react';
import BBBN_SystemBroadcastPicker from './native-components/BBBN_SystemBroadcastPicker';
import { WebView } from 'react-native-webview';
import { handleWebviewMessage } from './webview/message-handler';
import * as onScreenShareLocalIceCandidate from './events/onScreenShareLocalIceCandidate';
import * as onScreenShareSignalingStateChange from './events/onScreenShareSignalingStateChange';
import * as onBroadcastFinished from './events/onBroadcastFinished';
type BigbluebuttonMobileSdkProps = {
url: string;
@@ -14,10 +13,6 @@ type BigbluebuttonMobileSdkProps = {
onSuccess?: any;
};
const data = {
instances: 0
}
const renderPlatformSpecificComponents = () =>
Platform.select({
ios: <BBBN_SystemBroadcastPicker />,
@@ -31,27 +26,10 @@ export const BigBlueButtonMobile = ({
onSuccess,
}: BigbluebuttonMobileSdkProps) => {
const webViewRef = useRef(null);
const thisInstanceId = ++data.instances;
// console.log("XXX - ", thisInstanceId);
useEffect(() => {
const logPrefix = `[${thisInstanceId}] - ${url.substring(8, 16)}`;
console.log(`${logPrefix} - addingListeners`);
const listeners:EmitterSubscription[] = [];
listeners.push(onScreenShareLocalIceCandidate.setupListener(webViewRef));
listeners.push(onScreenShareSignalingStateChange.setupListener(webViewRef));
listeners.push(onBroadcastFinished.setupListener(webViewRef));
return () => {
console.log(`${logPrefix} - Removing listeners`);
listeners.forEach( (listener, index) => {
console.log(`${logPrefix} - Removing listener ${index}`);
listener.remove();
} );
}
onScreenShareLocalIceCandidate.setupListener(webViewRef);
onScreenShareSignalingStateChange.setupListener(webViewRef);
}, [webViewRef]);
return (
@@ -63,10 +41,9 @@ export const BigBlueButtonMobile = ({
source={{ uri: url }}
style={{ ...style }}
contentMode={'mobile'}
onMessage={(msg) => handleWebviewMessage(thisInstanceId, webViewRef, msg)}
onMessage={(msg) => handleWebviewMessage(webViewRef, msg)}
applicationNameForUserAgent="BBBMobile"
allowsInlineMediaPlayback={true}
mediaCapturePermissionGrantType={'grant'}
onLoadEnd={(content: any) => {
/*in case of success, the property code is not defined*/
if (typeof content.nativeEvent.code !== 'undefined') {

View File

@@ -14,14 +14,14 @@ nativeEmitter.addListener('onAddScreenShareRemoteIceCandidateCompleted', () => {
});
// Entry point of this method
function addScreenShareRemoteIceCandidate(instanceId: Number, remoteCandidateJson: string) {
function addScreenShareRemoteIceCandidate(remoteCandidateJson: string) {
return new Promise((res, rej) => {
// store the resolver for later call (when event is received)
resolve = res;
try {
console.log(
`[${instanceId}] - >nativeAddScreenShareRemoteIceCandidate ${remoteCandidateJson}`
`>nativeAddScreenShareRemoteIceCandidate ${remoteCandidateJson}`
);
// call native swift method that triggers the broadcast popup
nativeAddScreenShareRemoteIceCandidate(remoteCandidateJson);

View File

@@ -1,32 +0,0 @@
import { createFullAudioOffer as nativeCreateFullAudioOffer } from '../native-components/BBBN_FullAudioService';
import nativeEmitter from '../native-messaging/emitter';
// Reference to the resolver of last call
let resolve = (a: String) => {
console.log(
`default resolve function called, this should never happen: ${a}`
);
};
// Resolve promise when SDP offer is available
nativeEmitter.addListener('onFullAudioOfferCreated', (sdp) => {
resolve(sdp);
});
// Entry point of this method
function createFullAudioOffer(instanceId: Number) {
return new Promise((res, rej) => {
// store the resolver for later call (when event is received)
resolve = res;
try {
console.log(`[${instanceId}] - >nativeCreateFullAudioOffer`);
// call native swift method that triggers the broadcast popup
nativeCreateFullAudioOffer();
} catch (e) {
rej(`Call to nativeCreateFullAudioOffer failed`);
}
});
}
export default createFullAudioOffer;

View File

@@ -14,13 +14,13 @@ nativeEmitter.addListener('onScreenShareOfferCreated', (sdp) => {
});
// Entry point of this method
function createScreenShareOffer(instanceId: Number) {
function createScreenShareOffer() {
return new Promise((res, rej) => {
// store the resolver for later call (when event is received)
resolve = res;
try {
console.log(`[${instanceId}] - >nativeCreateScreenShareOffer`);
console.log(`>nativeCreateScreenShareOffer`);
// call native swift method that triggers the broadcast popup
nativeCreateScreenShareOffer();
} catch (e) {

View File

@@ -19,14 +19,14 @@ nativeEmitter.addListener('onBroadcastStarted', () => {
});
// Entry point of this method
function initializeScreenShare(instanceId: Number) {
function initializeScreenShare() {
return new Promise((res, rej) => {
// store the resolver for later call (when event is received)
resolve = res;
try {
// call native swift method that triggers the broadcast popup
console.log(`[${instanceId}] - >nativeInitializeScreenShare`);
console.log(`>nativeInitializeScreenShare`);
nativeInitializeScreenShare();
} catch (e) {
rej(`Call to nativeInitializeScreenShare failed zzy`);

View File

@@ -1,32 +0,0 @@
import { setFullAudioRemoteSDP as nativeSetFullAudioRemoteSDP } from '../native-components/BBBN_FullAudioService';
import nativeEmitter from '../native-messaging/emitter';
// Reference to the resolver of last call
let resolve = (value: unknown) => {
console.log(
`default resolve function called, this should never happen: ${value}`
);
};
// Resolve promise when SDP offer is available
nativeEmitter.addListener('onSetFullAudioRemoteSDPCompleted', () => {
resolve(undefined);
});
// Entry point of this method
function setFullAudioRemoteSDP(instanceId: Number, remoteSdp: string) {
return new Promise((res, rej) => {
// store the resolver for later call (when event is received)
resolve = res;
try {
console.log(`[${instanceId}] - >nativeSetFullAudioRemoteSDP ${remoteSdp}`);
// call native swift method that triggers the broadcast popup
nativeSetFullAudioRemoteSDP(remoteSdp);
} catch (e) {
rej(`Call to nativeSetFullAudioRemoteSDP failed`);
}
});
}
export default setFullAudioRemoteSDP;

View File

@@ -14,13 +14,13 @@ nativeEmitter.addListener('onSetScreenShareRemoteSDPCompleted', () => {
});
// Entry point of this method
function setScreenShareRemoteSDP(instanceId: Number, remoteSdp: string) {
function setScreenShareRemoteSDP(remoteSdp: string) {
return new Promise((res, rej) => {
// store the resolver for later call (when event is received)
resolve = res;
try {
console.log(`[${instanceId}] - >nativeSetScreenShareRemoteSDP ${remoteSdp}`);
console.log(`>nativeSetScreenShareRemoteSDP ${remoteSdp}`);
// call native swift method that triggers the broadcast popup
nativeSetScreenShareRemoteSDP(remoteSdp);
} catch (e) {

View File

@@ -1,32 +0,0 @@
import { stopScreenShareBroadcastExtension as nativeStopScreenShare } from '../native-components/BBBN_ScreenShareService';
import nativeEmitter from '../native-messaging/emitter';
// Reference to the resolver of last call
let resolve = (a: String | null) => {
console.log(
`default resolve function called, this should never happen: ${a}`
);
};
// Resolve promise when broadcast is started (this event means that user confirmed the screenshare)
nativeEmitter.addListener('onBroadcastFinished', () => {
resolve(null);
});
// Entry point of this method
function stopScreenShare(instanceId: Number) {
return new Promise((res, rej) => {
// store the resolver for later call (when event is received)
resolve = res;
try {
// call native swift method that triggers the broadcast popup
console.log(`[${instanceId}] - >stopScreenShare`);
nativeStopScreenShare();
} catch (e) {
rej(`Call to stopScreenShare failed zzy`);
}
});
}
export default stopScreenShare;

View File

@@ -1,19 +0,0 @@
import { NativeModules } from 'react-native';
const FullAudioService = NativeModules.BBBN_FullAudioService;
// export function initializeFullAudio() {
// FullAudioService.initializeFullAudio();
// }
export function createFullAudioOffer() {
FullAudioService.createFullAudioOffer();
}
export function setFullAudioRemoteSDP(remoteSDP: string) {
FullAudioService.setFullAudioRemoteSDP(remoteSDP);
}
// export function addFullAudioRemoteIceCandidate(remoteCandidateJson: string) {
// FullAudioService.addFullAudioRemoteIceCandidate(remoteCandidateJson);
// }

View File

@@ -17,7 +17,3 @@ export function setScreenShareRemoteSDP(remoteSDP: string) {
export function addScreenShareRemoteIceCandidate(remoteCandidateJson: string) {
ScreenShareService.addScreenShareRemoteIceCandidate(remoteCandidateJson);
}
export function stopScreenShareBroadcastExtension() {
ScreenShareService.stopScreenShareBroadcastExtension();
}

View File

@@ -3,20 +3,16 @@ import type { WebView, WebViewMessageEvent } from 'react-native-webview';
import initializeScreenShare from '../methods/initializeScreenShare';
import createScreenShareOffer from '../methods/createScreenShareOffer';
import setScreenShareRemoteSDP from '../methods/setScreenShareRemoteSDP';
import setFullAudioRemoteSDP from '../methods/setFullAudioRemoteSDP';
import addScreenShareRemoteIceCandidate from '../methods/addScreenShareRemoteIceCandidate';
import createFullAudioOffer from '../methods/createFullAudioOffer';
import stopScreenShare from '../methods/stopScreenShare';
function observePromiseResult(
instanceId: Number,
webViewRef: MutableRefObject<WebView>,
sequence: number,
prom: Promise<any>
) {
prom
.then((result: any) => {
console.log(`[${instanceId}] - Promise ${sequence} resolved!`, result);
console.log(`Promise ${sequence} resolved!`, result);
webViewRef.current.injectJavaScript(
`window.nativeMethodCallResult(${sequence}, true ${
result ? ',' + JSON.stringify(result) : ''
@@ -24,7 +20,7 @@ function observePromiseResult(
);
})
.catch((exception: any) => {
console.error(`[${instanceId}] - Promise ${sequence} failed!`, exception);
console.error(`Promise ${sequence} failed!`, exception);
webViewRef.current.injectJavaScript(
`window.nativeMethodCallResult(${sequence}, false ${
exception ? ',' + JSON.stringify(exception) : ''
@@ -34,48 +30,35 @@ function observePromiseResult(
}
export function handleWebviewMessage(
instanceId: Number,
webViewRef: MutableRefObject<any>,
event: WebViewMessageEvent
) {
const stringData = event?.nativeEvent?.data;
console.log("handleWebviewMessage - ", instanceId);
const data = JSON.parse(stringData);
if (data?.method && data?.sequence) {
let promise;
switch (data?.method) {
case 'initializeScreenShare':
promise = initializeScreenShare(instanceId);
promise = initializeScreenShare();
break;
case 'createFullAudioOffer':
promise = createFullAudioOffer(instanceId);
case 'createOffer':
promise = createScreenShareOffer();
break;
case 'createScreenShareOffer':
promise = createScreenShareOffer(instanceId);
break;
case 'setScreenShareRemoteSDP':
promise = setScreenShareRemoteSDP(instanceId, data?.arguments[0].sdp);
break;
case 'setFullAudioRemoteSDP':
promise = setFullAudioRemoteSDP(instanceId, data?.arguments[0].sdp);
case 'setRemoteDescription':
promise = setScreenShareRemoteSDP(data?.arguments[0].sdp);
break;
case 'addRemoteIceCandidate':
promise = addScreenShareRemoteIceCandidate(
instanceId,
JSON.stringify(data?.arguments[0])
);
break;
case 'stopScreenShare':
promise = stopScreenShare(instanceId)
break;
default:
throw `[${instanceId}] - Unknown method ${data?.method}`;
throw `Unknown method ${data?.method}`;
}
observePromiseResult(instanceId, webViewRef, data.sequence, promise);
observePromiseResult(webViewRef, data.sequence, promise);
} else {
console.log(`[${instanceId}] - Ignoring unknown message: $stringData`);
console.log(`Ignoring unknown message: $stringData`);
}
}

856
yarn.lock

File diff suppressed because it is too large Load Diff