Compare commits
25 Commits
callkit-qu
...
rn068.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
00adc46c19 | ||
|
|
824dec5407 | ||
|
|
578e3325ee | ||
|
|
7e84c723b3 | ||
|
|
052101a6ad | ||
|
|
e98cc51f44 | ||
|
|
0773d0dd88 | ||
|
|
a6660c227f | ||
|
|
569bfe98ee | ||
|
|
abd7254b30 | ||
|
|
4a15d78dbd | ||
|
|
bc99e714f2 | ||
|
|
db694a4296 | ||
|
|
64fdaa8e79 | ||
|
|
064382ffc9 | ||
|
|
be6ef684c5 | ||
|
|
37590129c1 | ||
|
|
866b46fa7c | ||
|
|
4f3aff1296 | ||
|
|
b3988243c8 | ||
|
|
3f2ea291f3 | ||
|
|
06c88b4059 | ||
|
|
438f21e222 | ||
|
|
2960002bca | ||
|
|
e28b3ddeae |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -95,3 +95,4 @@ Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
/package-lock.json
|
||||
|
||||
10
README.md
10
README.md
@@ -1,20 +1,20 @@
|
||||
# bigbluebutton-mobile-sdk
|
||||
# bigbluebutton-mobile-tablet-sdk
|
||||
|
||||
This repository contains BigBlueButton react-native component, that's used in our [sample implementation](https://github.com/bigbluebutton/bigbluebutton-mobile).
|
||||
This repository contains BigBlueButton Mobile Tablet react-native component, that's used in our [sample implementation](https://github.com/bigbluebutton/bigbluebutton-mobile-tablet).
|
||||
|
||||

|
||||

|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
npm install bigbluebutton-mobile-sdk
|
||||
npm install bigbluebutton-mobile-tablet-sdk
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
import { BigBlueButtonMobile } from "bigbluebutton-mobile-sdk";
|
||||
import { BigBlueButtonMobile } from "bigbluebutton-mobile-tablet-sdk";
|
||||
|
||||
// ...
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
/* 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 */; };
|
||||
@@ -44,12 +45,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>"; };
|
||||
@@ -94,10 +95,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 */,
|
||||
@@ -261,6 +262,7 @@
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
792D8E8E283FBED3008471C5 /* main.jsbundle in Resources */,
|
||||
81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */,
|
||||
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */,
|
||||
);
|
||||
|
||||
@@ -67,6 +67,7 @@
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
disableMainThreadChecker = "YES"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
PODS:
|
||||
- bigbluebutton-mobile-sdk (0.1.11):
|
||||
- bigbluebutton-mobile-sdk (0.1.25):
|
||||
- bigbluebutton-mobile-sdk-common
|
||||
- React-Core
|
||||
- WebRTC-lib
|
||||
- bigbluebutton-mobile-sdk-broadcast-upload-extension (0.1.11):
|
||||
- bigbluebutton-mobile-sdk-broadcast-upload-extension (0.1.25):
|
||||
- bigbluebutton-mobile-sdk-common
|
||||
- WebRTC-lib
|
||||
- bigbluebutton-mobile-sdk-common (0.1.11):
|
||||
- bigbluebutton-mobile-sdk-common (0.1.25):
|
||||
- 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: ed5b306bc5161dcc35cf9e870d91ab12c64810b6
|
||||
bigbluebutton-mobile-sdk-broadcast-upload-extension: af7d83d6e0bd547876f25350b84bc94561ba14cf
|
||||
bigbluebutton-mobile-sdk-common: 4c14fa0c920d9cd7d57ab2d1aebb8c0ebb0065c4
|
||||
bigbluebutton-mobile-sdk: 242a4e5d15161c650434cc154e96c47c52ab5691
|
||||
bigbluebutton-mobile-sdk-broadcast-upload-extension: 62c3ef96b1aba16fc5f10021e000cc64209392b8
|
||||
bigbluebutton-mobile-sdk-common: fc8a8c0b1096b045b285497cc599d6ce67421fcb
|
||||
boost-for-react-native: 39c7adb57c4e60d6c5479dd8623128eb5b3f0f2c
|
||||
DoubleConversion: cde416483dac037923206447da6e1454df403714
|
||||
FBLazyVector: 3bb422f41b18121b71783a905c10e58606f7dc3e
|
||||
|
||||
4
example/ios/assets/app.json
Normal file
4
example/ios/assets/app.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"name": "BigbluebuttonMobileSdkExample",
|
||||
"displayName": "BigbluebuttonMobileSdk Example"
|
||||
}
|
||||
426
example/ios/main.jsbundle
Normal file
426
example/ios/main.jsbundle
Normal file
File diff suppressed because one or more lines are too long
@@ -12,10 +12,12 @@ 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 screenBroadcaster:ScreenBroadcaster?;
|
||||
private var onApplicationTerminatedObserver:NSKeyValueObservation?;
|
||||
private var onBroadcastStoppedObserver:NSKeyValueObservation?;
|
||||
private var screenBroadcaster:ScreenBroadcasterService?;
|
||||
|
||||
open func setAppGroupName(appGroupName:String) {
|
||||
logger.info("Received appGroupName: \(appGroupName)")
|
||||
@@ -34,11 +36,25 @@ open class BBBSampleHandler : RPBroadcastSampleHandler {
|
||||
logger.info("ReplayKit2 event - broadcastStarted - persisting information on UserDefaults")
|
||||
userDefaults.set(BBBSharedData.generatePayload(), forKey: BBBSharedData.SharedData.broadcastStarted)
|
||||
|
||||
self.screenBroadcaster = ScreenBroadcaster(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)
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
// 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 +72,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")
|
||||
|
||||
@@ -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 */
|
||||
@@ -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
|
||||
}
|
||||
@@ -6,11 +6,12 @@
|
||||
import os
|
||||
import bigbluebutton_mobile_sdk_common
|
||||
import WebRTC
|
||||
import UIKit
|
||||
|
||||
open class ScreenBroadcaster {
|
||||
open class ScreenBroadcasterService {
|
||||
// Logger (these messages are displayed in the console application)
|
||||
private var logger = os.Logger(subsystem: "BigBlueButtonMobileSDK", category: "ScreenBroadcaster")
|
||||
private var webRTCClient:WebRTCClient
|
||||
private var logger = os.Logger(subsystem: "BigBlueButtonMobileSDK", category: "ScreenBroadcasterService")
|
||||
private var webRTCClient:ScreenShareWebRTCClient
|
||||
private var appGroupName:String
|
||||
private let encoder = JSONEncoder()
|
||||
public var isConnected:Bool = false
|
||||
@@ -18,12 +19,14 @@ open class ScreenBroadcaster {
|
||||
init(appGroupName: String) {
|
||||
self.appGroupName = appGroupName
|
||||
|
||||
webRTCClient = WebRTCClient(iceServers: ["stun:stun.l.google.com:19302",
|
||||
webRTCClient = ScreenShareWebRTCClient(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? {
|
||||
@@ -60,6 +63,23 @@ open class ScreenBroadcaster {
|
||||
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)
|
||||
@@ -69,7 +89,7 @@ open class ScreenBroadcaster {
|
||||
webRTCClient.setRatio(originalWidth: rtcPixlBuffer.width, originalHeight: rtcPixlBuffer.height)
|
||||
}
|
||||
|
||||
let rtcVideoFrame = RTCVideoFrame(buffer: rtcPixlBuffer, rotation: ._0, timeStampNs: timeStampNs)
|
||||
let rtcVideoFrame = RTCVideoFrame(buffer: rtcPixlBuffer, rotation: rotationFrame, timeStampNs: timeStampNs)
|
||||
self.webRTCClient.push(videoFrame: rtcVideoFrame)
|
||||
self.logger.info("video pushed")
|
||||
}
|
||||
@@ -77,9 +97,9 @@ open class ScreenBroadcaster {
|
||||
|
||||
}
|
||||
|
||||
extension ScreenBroadcaster: WebRTCClientDelegate {
|
||||
extension ScreenBroadcasterService: ScreenShareWebRTCClientDelegate {
|
||||
|
||||
public func webRTCClient(_ client: WebRTCClient, didDiscoverLocalCandidate rtcIceCandidate: RTCIceCandidate) {
|
||||
public func webRTCClient(_ client: ScreenShareWebRTCClient, didDiscoverLocalCandidate rtcIceCandidate: RTCIceCandidate) {
|
||||
do {
|
||||
let iceCandidate = IceCandidate(from: rtcIceCandidate)
|
||||
let iceCandidateAsJsonData = try self.encoder.encode(iceCandidate)
|
||||
@@ -96,7 +116,7 @@ extension ScreenBroadcaster: WebRTCClientDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
public func webRTCClient(_ client: WebRTCClient, didChangeIceConnectionState state: RTCIceConnectionState) {
|
||||
public func webRTCClient(_ client: ScreenShareWebRTCClient, didChangeIceConnectionState state: RTCIceConnectionState) {
|
||||
switch state {
|
||||
case .connected:
|
||||
self.logger.info("didChangeConnectionState -> connected")
|
||||
@@ -115,7 +135,7 @@ extension ScreenBroadcaster: WebRTCClientDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
public func webRTCClient(_ client: WebRTCClient, didChangeIceGatheringState state: RTCIceGatheringState) {
|
||||
public func webRTCClient(_ client: ScreenShareWebRTCClient, didChangeIceGatheringState state: RTCIceGatheringState) {
|
||||
switch state {
|
||||
case .new:
|
||||
self.logger.info("didChangeGatheringState -> new")
|
||||
@@ -128,7 +148,7 @@ extension ScreenBroadcaster: WebRTCClientDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
public func webRTCClient(_ client: WebRTCClient, didChangeSignalingState state: RTCSignalingState) {
|
||||
public func webRTCClient(_ client: ScreenShareWebRTCClient, didChangeSignalingState state: RTCSignalingState) {
|
||||
var stateString = ""
|
||||
switch(state) {
|
||||
case .haveLocalOffer:
|
||||
@@ -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
|
||||
|
||||
304
ios-common/Classes/AudioWebRTCClient.swift
Normal file
304
ios-common/Classes/AudioWebRTCClient.swift
Normal file
@@ -0,0 +1,304 @@
|
||||
//
|
||||
// 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)")
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,10 @@ 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)
|
||||
|
||||
@@ -9,14 +9,14 @@ import Foundation
|
||||
import WebRTC
|
||||
import os
|
||||
|
||||
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)
|
||||
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)
|
||||
}
|
||||
|
||||
open class WebRTCClient: NSObject {
|
||||
open class ScreenShareWebRTCClient: 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 WebRTCClient: NSObject {
|
||||
return RTCPeerConnectionFactory(encoderFactory: videoEncoderFactory, decoderFactory: videoDecoderFactory)
|
||||
}()
|
||||
|
||||
public weak var delegate: WebRTCClientDelegate?
|
||||
public weak var delegate: ScreenShareWebRTCClientDelegate?
|
||||
private let peerConnection: RTCPeerConnection
|
||||
private let rtcAudioSession = RTCAudioSession.sharedInstance()
|
||||
private let audioQueue = DispatchQueue(label: "audio")
|
||||
private let mediaConstrains = [kRTCMediaConstraintsOfferToReceiveAudio: kRTCMediaConstraintsValueTrue,
|
||||
kRTCMediaConstraintsOfferToReceiveVideo: kRTCMediaConstraintsValueTrue]
|
||||
private let mediaConstrains = [kRTCMediaConstraintsOfferToReceiveAudio: kRTCMediaConstraintsValueFalse,
|
||||
kRTCMediaConstraintsOfferToReceiveVideo: kRTCMediaConstraintsValueFalse]
|
||||
private var videoSource: RTCVideoSource?
|
||||
private var videoCapturer: RTCVideoCapturer?
|
||||
private var localVideoTrack: RTCVideoTrack?
|
||||
@@ -60,7 +60,7 @@ open class WebRTCClient: NSObject {
|
||||
let constraints = RTCMediaConstraints(mandatoryConstraints: nil,
|
||||
optionalConstraints: ["DtlsSrtpKeyAgreement":kRTCMediaConstraintsValueTrue])
|
||||
|
||||
guard let peerConnection = WebRTCClient.factory.peerConnection(with: config, constraints: constraints, delegate: nil) else {
|
||||
guard let peerConnection = ScreenShareWebRTCClient.factory.peerConnection(with: config, constraints: constraints, delegate: nil) else {
|
||||
fatalError("Could not create new RTCPeerConnection")
|
||||
}
|
||||
|
||||
@@ -135,9 +135,9 @@ open class WebRTCClient: NSObject {
|
||||
}*/
|
||||
|
||||
private func createVideoTrack() -> RTCVideoTrack {
|
||||
videoSource = WebRTCClient.factory.videoSource(forScreenCast: true)
|
||||
videoSource = ScreenShareWebRTCClient.factory.videoSource(forScreenCast: true)
|
||||
videoCapturer = RTCVideoCapturer(delegate: videoSource!)
|
||||
let videoTrack = WebRTCClient.factory.videoTrack(with: videoSource!, trackId: "video0")
|
||||
let videoTrack = ScreenShareWebRTCClient.factory.videoTrack(with: videoSource!, trackId: "video0")
|
||||
videoTrack.isEnabled = true
|
||||
return videoTrack
|
||||
}
|
||||
@@ -157,7 +157,7 @@ open class WebRTCClient: NSObject {
|
||||
|
||||
// MARK: RTCPeerConnectionDelegate Methods
|
||||
|
||||
extension WebRTCClient: RTCPeerConnectionDelegate {
|
||||
extension ScreenShareWebRTCClient: RTCPeerConnectionDelegate {
|
||||
|
||||
public func peerConnection(_ peerConnection: RTCPeerConnection, didChange stateChanged: RTCSignalingState) {
|
||||
self.logger.info("peerConnection new signaling state: \(stateChanged.rawValue)")
|
||||
@@ -209,7 +209,7 @@ extension WebRTCClient: RTCPeerConnectionDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
extension WebRTCClient {
|
||||
extension ScreenShareWebRTCClient {
|
||||
private func setTrackEnabled<T: RTCMediaStreamTrack>(_ type: T.Type, isEnabled: Bool) {
|
||||
peerConnection.transceivers
|
||||
.compactMap { return $0.sender.track as? T }
|
||||
@@ -219,7 +219,7 @@ extension WebRTCClient {
|
||||
|
||||
// MARK: - Video control
|
||||
|
||||
extension WebRTCClient {
|
||||
extension ScreenShareWebRTCClient {
|
||||
func hideVideo() {
|
||||
self.setVideoEnabled(false)
|
||||
}
|
||||
@@ -233,7 +233,7 @@ extension WebRTCClient {
|
||||
|
||||
// MARK:- Audio control
|
||||
|
||||
extension WebRTCClient {
|
||||
extension ScreenShareWebRTCClient {
|
||||
func muteAudio() {
|
||||
self.setAudioEnabled(false)
|
||||
}
|
||||
@@ -284,7 +284,7 @@ extension WebRTCClient {
|
||||
}
|
||||
}
|
||||
|
||||
extension WebRTCClient: RTCDataChannelDelegate {
|
||||
extension ScreenShareWebRTCClient: RTCDataChannelDelegate {
|
||||
public func dataChannelDidChangeState(_ dataChannel: RTCDataChannel) {
|
||||
debugPrint("dataChannel did change state: \(dataChannel.readyState)")
|
||||
}
|
||||
@@ -10,6 +10,16 @@ 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) ?? ""
|
||||
|
||||
8
ios-common/Classes/WebRTCClientDelegate.swift
Normal file
8
ios-common/Classes/WebRTCClientDelegate.swift
Normal file
@@ -0,0 +1,8 @@
|
||||
//
|
||||
// WebRTCClientDelegate.swift
|
||||
// bigbluebutton-mobile-sdk
|
||||
//
|
||||
// Created by Tiago Daniel Jacobs on 20/04/22.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
@@ -8,6 +8,8 @@
|
||||
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)
|
||||
@@ -21,6 +23,7 @@ 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
|
||||
@@ -84,6 +87,19 @@ 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 {
|
||||
@@ -98,5 +114,16 @@ 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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
136
ios/NativeOnly/FullAudioService.swift
Normal file
136
ios/NativeOnly/FullAudioService.swift
Normal file
@@ -0,0 +1,136 @@
|
||||
//
|
||||
// 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")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
15
ios/ReactExported/FullAudioServiceManager.m
Normal file
15
ios/ReactExported/FullAudioServiceManager.m
Normal file
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// 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
|
||||
49
ios/ReactExported/FullAudioServiceManager.swift
Normal file
49
ios/ReactExported/FullAudioServiceManager.swift
Normal file
@@ -0,0 +1,49 @@
|
||||
//
|
||||
// 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)")
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,6 +23,8 @@ open class ReactNativeEventEmitter: RCTEventEmitter {
|
||||
case onScreenShareLocalIceCandidate = "onScreenShareLocalIceCandidate"
|
||||
case onScreenShareSignalingStateChange = "onScreenShareSignalingStateChange"
|
||||
case onAddScreenShareRemoteIceCandidateCompleted = "onAddScreenShareRemoteIceCandidateCompleted"
|
||||
case onFullAudioOfferCreated = "onFullAudioOfferCreated"
|
||||
case onSetFullAudioRemoteSDPCompleted = "onSetFullAudioRemoteSDPCompleted"
|
||||
}
|
||||
|
||||
override init() {
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#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)
|
||||
|
||||
@@ -16,34 +16,33 @@ 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)
|
||||
|
||||
Task.init {
|
||||
do{
|
||||
try audioSession.setCategory(AVAudioSession.Category.playback, options: [AVAudioSession.CategoryOptions.mixWithOthers])
|
||||
try audioSession.setPrefersNoInterruptionsFromSystemAlerts(true)
|
||||
try audioSession.setActive(true)
|
||||
|
||||
}catch{
|
||||
print(error)
|
||||
}
|
||||
let path = Bundle.main.path(forResource: "music2", ofType : "mp3")!
|
||||
let url = URL(fileURLWithPath : path)
|
||||
|
||||
print("audioUrl2 = \(url)")
|
||||
do {
|
||||
|
||||
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)
|
||||
}
|
||||
self.player = try AVAudioPlayer(contentsOf: url)
|
||||
self.player.play()
|
||||
self.playSoundInLoop()
|
||||
}
|
||||
|
||||
|
||||
catch {
|
||||
logger.error("Error to play audio = \(url)")
|
||||
}
|
||||
|
||||
// Request the system broadcast
|
||||
logger.info("initializeScreenShare - requesting broadcast")
|
||||
SystemBroadcastPicker.requestBroadcast()
|
||||
@@ -94,4 +93,23 @@ 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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
16
package.json
16
package.json
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"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).",
|
||||
"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).",
|
||||
"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-sdk",
|
||||
"repository": "https://github.com/bigbluebutton/bigbluebutton-mobile-tablet-sdk",
|
||||
"author": "BigBlueButton Inc <bigbluebutton@bigbluebutton.org> (https://bigbluebutton.org)",
|
||||
"license": "LGPL-3.0",
|
||||
"bugs": {
|
||||
"url": "https://github.com/bigbluebutton/bigbluebutton-mobile-sdk/issues"
|
||||
"url": "https://github.com/bigbluebutton/bigbluebutton-mobile-tablet-sdk/issues"
|
||||
},
|
||||
"homepage": "https://github.com/bigbluebutton/bigbluebutton-mobile-sdk#readme",
|
||||
"homepage": "https://github.com/bigbluebutton/bigbluebutton-mobile-tablet-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": "16.13.1",
|
||||
"react-native": "^0.67.2",
|
||||
"react": "17.0.2",
|
||||
"react-native": "0.68.1",
|
||||
"react-native-builder-bob": "^0.18.0",
|
||||
"release-it": "^14.2.2",
|
||||
"typescript": "^4.1.3"
|
||||
|
||||
13
src/events/onBroadcastFinished.tsx
Normal file
13
src/events/onBroadcastFinished.tsx
Normal file
@@ -0,0 +1,13 @@
|
||||
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();`
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
import type { MutableRefObject } from 'react';
|
||||
import type { EmitterSubscription } from 'react-native';
|
||||
import nativeEmitter from '../native-messaging/emitter';
|
||||
|
||||
export function setupListener(_webViewRef: MutableRefObject<any>) {
|
||||
export function setupListener(_webViewRef: MutableRefObject<any>):EmitterSubscription {
|
||||
// Resolve promise when SDP offer is available
|
||||
nativeEmitter.addListener(
|
||||
return nativeEmitter.addListener(
|
||||
'onScreenShareLocalIceCandidate',
|
||||
(jsonEncodedIceCandidate) => {
|
||||
let iceCandidate = JSON.parse(jsonEncodedIceCandidate);
|
||||
@@ -12,7 +13,7 @@ export function setupListener(_webViewRef: MutableRefObject<any>) {
|
||||
}
|
||||
const event = { candidate: iceCandidate };
|
||||
_webViewRef.current.injectJavaScript(
|
||||
`window.bbbMobileScreenShareIceCandidateCallback(${JSON.stringify(
|
||||
`window.bbbMobileScreenShareIceCandidateCallback && window.bbbMobileScreenShareIceCandidateCallback(${JSON.stringify(
|
||||
event
|
||||
)});`
|
||||
);
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import type { MutableRefObject } from 'react';
|
||||
import type { EmitterSubscription } from 'react-native';
|
||||
import nativeEmitter from '../native-messaging/emitter';
|
||||
|
||||
export function setupListener(_webViewRef: MutableRefObject<any>) {
|
||||
export function setupListener(_webViewRef: MutableRefObject<any>):EmitterSubscription {
|
||||
// Resolve promise when SDP offer is available
|
||||
nativeEmitter.addListener('onScreenShareSignalingStateChange', (newState) => {
|
||||
return nativeEmitter.addListener('onScreenShareSignalingStateChange', (newState) => {
|
||||
console.log(`Temos um novo state: ${newState}`);
|
||||
_webViewRef.current.injectJavaScript(
|
||||
`window.bbbMobileScreenShareSignalingStateChangeCallback(${JSON.stringify(
|
||||
`window.bbbMobileScreenShareSignalingStateChangeCallback && window.bbbMobileScreenShareSignalingStateChangeCallback(${JSON.stringify(
|
||||
newState
|
||||
)});`
|
||||
);
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { Platform, ViewStyle } from 'react-native';
|
||||
import { EmitterSubscription, 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;
|
||||
@@ -13,6 +14,10 @@ type BigbluebuttonMobileSdkProps = {
|
||||
onSuccess?: any;
|
||||
};
|
||||
|
||||
const data = {
|
||||
instances: 0
|
||||
}
|
||||
|
||||
const renderPlatformSpecificComponents = () =>
|
||||
Platform.select({
|
||||
ios: <BBBN_SystemBroadcastPicker />,
|
||||
@@ -26,10 +31,27 @@ export const BigBlueButtonMobile = ({
|
||||
onSuccess,
|
||||
}: BigbluebuttonMobileSdkProps) => {
|
||||
const webViewRef = useRef(null);
|
||||
const thisInstanceId = ++data.instances;
|
||||
|
||||
// console.log("XXX - ", thisInstanceId);
|
||||
|
||||
useEffect(() => {
|
||||
onScreenShareLocalIceCandidate.setupListener(webViewRef);
|
||||
onScreenShareSignalingStateChange.setupListener(webViewRef);
|
||||
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();
|
||||
} );
|
||||
}
|
||||
}, [webViewRef]);
|
||||
|
||||
return (
|
||||
@@ -41,9 +63,10 @@ export const BigBlueButtonMobile = ({
|
||||
source={{ uri: url }}
|
||||
style={{ ...style }}
|
||||
contentMode={'mobile'}
|
||||
onMessage={(msg) => handleWebviewMessage(webViewRef, msg)}
|
||||
onMessage={(msg) => handleWebviewMessage(thisInstanceId, 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') {
|
||||
|
||||
@@ -14,14 +14,14 @@ nativeEmitter.addListener('onAddScreenShareRemoteIceCandidateCompleted', () => {
|
||||
});
|
||||
|
||||
// Entry point of this method
|
||||
function addScreenShareRemoteIceCandidate(remoteCandidateJson: string) {
|
||||
function addScreenShareRemoteIceCandidate(instanceId: Number, remoteCandidateJson: string) {
|
||||
return new Promise((res, rej) => {
|
||||
// store the resolver for later call (when event is received)
|
||||
resolve = res;
|
||||
|
||||
try {
|
||||
console.log(
|
||||
`>nativeAddScreenShareRemoteIceCandidate ${remoteCandidateJson}`
|
||||
`[${instanceId}] - >nativeAddScreenShareRemoteIceCandidate ${remoteCandidateJson}`
|
||||
);
|
||||
// call native swift method that triggers the broadcast popup
|
||||
nativeAddScreenShareRemoteIceCandidate(remoteCandidateJson);
|
||||
|
||||
32
src/methods/createFullAudioOffer.tsx
Normal file
32
src/methods/createFullAudioOffer.tsx
Normal file
@@ -0,0 +1,32 @@
|
||||
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;
|
||||
@@ -14,13 +14,13 @@ nativeEmitter.addListener('onScreenShareOfferCreated', (sdp) => {
|
||||
});
|
||||
|
||||
// Entry point of this method
|
||||
function createScreenShareOffer() {
|
||||
function createScreenShareOffer(instanceId: Number) {
|
||||
return new Promise((res, rej) => {
|
||||
// store the resolver for later call (when event is received)
|
||||
resolve = res;
|
||||
|
||||
try {
|
||||
console.log(`>nativeCreateScreenShareOffer`);
|
||||
console.log(`[${instanceId}] - >nativeCreateScreenShareOffer`);
|
||||
// call native swift method that triggers the broadcast popup
|
||||
nativeCreateScreenShareOffer();
|
||||
} catch (e) {
|
||||
|
||||
@@ -19,14 +19,14 @@ nativeEmitter.addListener('onBroadcastStarted', () => {
|
||||
});
|
||||
|
||||
// Entry point of this method
|
||||
function initializeScreenShare() {
|
||||
function initializeScreenShare(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(`>nativeInitializeScreenShare`);
|
||||
console.log(`[${instanceId}] - >nativeInitializeScreenShare`);
|
||||
nativeInitializeScreenShare();
|
||||
} catch (e) {
|
||||
rej(`Call to nativeInitializeScreenShare failed zzy`);
|
||||
|
||||
32
src/methods/setFullAudioRemoteSDP.tsx
Normal file
32
src/methods/setFullAudioRemoteSDP.tsx
Normal file
@@ -0,0 +1,32 @@
|
||||
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;
|
||||
@@ -14,13 +14,13 @@ nativeEmitter.addListener('onSetScreenShareRemoteSDPCompleted', () => {
|
||||
});
|
||||
|
||||
// Entry point of this method
|
||||
function setScreenShareRemoteSDP(remoteSdp: string) {
|
||||
function setScreenShareRemoteSDP(instanceId: Number, remoteSdp: string) {
|
||||
return new Promise((res, rej) => {
|
||||
// store the resolver for later call (when event is received)
|
||||
resolve = res;
|
||||
|
||||
try {
|
||||
console.log(`>nativeSetScreenShareRemoteSDP ${remoteSdp}`);
|
||||
console.log(`[${instanceId}] - >nativeSetScreenShareRemoteSDP ${remoteSdp}`);
|
||||
// call native swift method that triggers the broadcast popup
|
||||
nativeSetScreenShareRemoteSDP(remoteSdp);
|
||||
} catch (e) {
|
||||
|
||||
32
src/methods/stopScreenShare.tsx
Normal file
32
src/methods/stopScreenShare.tsx
Normal file
@@ -0,0 +1,32 @@
|
||||
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;
|
||||
19
src/native-components/BBBN_FullAudioService.tsx
Normal file
19
src/native-components/BBBN_FullAudioService.tsx
Normal file
@@ -0,0 +1,19 @@
|
||||
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);
|
||||
// }
|
||||
@@ -17,3 +17,7 @@ export function setScreenShareRemoteSDP(remoteSDP: string) {
|
||||
export function addScreenShareRemoteIceCandidate(remoteCandidateJson: string) {
|
||||
ScreenShareService.addScreenShareRemoteIceCandidate(remoteCandidateJson);
|
||||
}
|
||||
|
||||
export function stopScreenShareBroadcastExtension() {
|
||||
ScreenShareService.stopScreenShareBroadcastExtension();
|
||||
}
|
||||
|
||||
@@ -3,16 +3,20 @@ 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(`Promise ${sequence} resolved!`, result);
|
||||
console.log(`[${instanceId}] - Promise ${sequence} resolved!`, result);
|
||||
webViewRef.current.injectJavaScript(
|
||||
`window.nativeMethodCallResult(${sequence}, true ${
|
||||
result ? ',' + JSON.stringify(result) : ''
|
||||
@@ -20,7 +24,7 @@ function observePromiseResult(
|
||||
);
|
||||
})
|
||||
.catch((exception: any) => {
|
||||
console.error(`Promise ${sequence} failed!`, exception);
|
||||
console.error(`[${instanceId}] - Promise ${sequence} failed!`, exception);
|
||||
webViewRef.current.injectJavaScript(
|
||||
`window.nativeMethodCallResult(${sequence}, false ${
|
||||
exception ? ',' + JSON.stringify(exception) : ''
|
||||
@@ -30,35 +34,48 @@ 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();
|
||||
promise = initializeScreenShare(instanceId);
|
||||
break;
|
||||
case 'createOffer':
|
||||
promise = createScreenShareOffer();
|
||||
case 'createFullAudioOffer':
|
||||
promise = createFullAudioOffer(instanceId);
|
||||
break;
|
||||
case 'setRemoteDescription':
|
||||
promise = setScreenShareRemoteSDP(data?.arguments[0].sdp);
|
||||
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);
|
||||
break;
|
||||
case 'addRemoteIceCandidate':
|
||||
promise = addScreenShareRemoteIceCandidate(
|
||||
instanceId,
|
||||
JSON.stringify(data?.arguments[0])
|
||||
);
|
||||
break;
|
||||
case 'stopScreenShare':
|
||||
promise = stopScreenShare(instanceId)
|
||||
break;
|
||||
default:
|
||||
throw `Unknown method ${data?.method}`;
|
||||
throw `[${instanceId}] - Unknown method ${data?.method}`;
|
||||
}
|
||||
observePromiseResult(webViewRef, data.sequence, promise);
|
||||
observePromiseResult(instanceId, webViewRef, data.sequence, promise);
|
||||
} else {
|
||||
console.log(`Ignoring unknown message: $stringData`);
|
||||
console.log(`[${instanceId}] - Ignoring unknown message: $stringData`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user