Implements the createOffer method

This commit is contained in:
Tiago Jacobs 2022-03-27 13:54:18 -03:00
parent 15ba546dfb
commit ce5b8e8979
7 changed files with 70 additions and 30 deletions

View File

@ -6,7 +6,7 @@
//
import ReplayKit
import bigbluebutton_mobile_sdk_common
import bigbluebutton_mobile_sdk_broadcast_upload_extension
class SampleHandler: BBBSampleHandler {
override func broadcastStarted(withSetupInfo setupInfo: [String : NSObject]?) {

View File

@ -362,8 +362,8 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
bigbluebutton-mobile-sdk: 3b5da479ad35ed28109cc74b1f8bf7c284e61bb0
bigbluebutton-mobile-sdk-broadcast-upload-extension: ab8f9cebcde6ac34d5643c27da289928f8225b78
bigbluebutton-mobile-sdk-common: 1da6689f4b52a15f0225f991d9e62158e654b941
bigbluebutton-mobile-sdk-broadcast-upload-extension: a7db971c25db05172529a414b1faf12e410f732a
bigbluebutton-mobile-sdk-common: a230c42cc0f816b44a060a829255fd3900e08e35
boost-for-react-native: 39c7adb57c4e60d6c5479dd8623128eb5b3f0f2c
DoubleConversion: cde416483dac037923206447da6e1454df403714
FBLazyVector: 3bb422f41b18121b71783a905c10e58606f7dc3e

View File

@ -13,6 +13,7 @@ open class BBBSampleHandler : RPBroadcastSampleHandler {
private var logger = os.Logger(subsystem: "BigBlueButtonMobileSDK", category: "BBBSampleHandler")
private var appGroupName:String = "";
private var observer:NSKeyValueObservation?;
private var screenBroadcaster:ScreenBroadcaster?;
open func setAppGroupName(appGroupName:String) {
logger.info("Received appGroupName: \(appGroupName)")
@ -31,15 +32,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()
// Listen for createOffer requests from the UI APP
logger.info("Configuring observer")
self.observer = userDefaults.observe(\.createScreenShareOffer, options: [.new]) { (defaults, change) in
self.logger.info("Observer detected a createScreenShareOffer request!")
BBBSharedData
.getUserDefaults(appGroupName: self.appGroupName)
.set(BBBSharedData.generatePayload(properties: [
"sdp": "this is SDP from extension"
]), forKey: BBBSharedData.SharedData.screenShareOfferCreated)
Task.init {
let optionalSdp = await self.screenBroadcaster?.createOffer()
if(optionalSdp != nil){
let sdp = optionalSdp!
self.logger.info("Got SDP back from screenBroadcaster: \(sdp)")
BBBSharedData
.getUserDefaults(appGroupName: self.appGroupName)
.set(BBBSharedData.generatePayload(properties: [
"sdp": sdp
]), forKey: BBBSharedData.SharedData.screenShareOfferCreated)
}
}
}
}

View File

@ -0,0 +1,32 @@
//
// ScreenBroadcaster.swift
//
// Created by Tiago Daniel Jacobs on 27/03/22.
//
import os
import bigbluebutton_mobile_sdk_common
open class ScreenBroadcaster {
// Logger (these messages are displayed in the console application)
private var logger = os.Logger(subsystem: "BigBlueButtonMobileSDK", category: "ScreenBroadcaster")
private var webRTCClient:WebRTCClient
init() {
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"])
}
public func createOffer() async -> String? {
do{
let rtcSessionDescription = try await self.webRTCClient.offer()
return rtcSessionDescription.sdp
} catch {
logger.error("Error on webRTCClient.offer")
return nil
}
}
}

View File

@ -13,7 +13,7 @@ Pod::Spec.new do |s|
s.platforms = { :ios => "14.7" }
s.source = { :git => "https://github.com/bigbluebutton/bigbluebutton-mobile-sdk.git", :tag => "#{s.version}" }
s.source_files = "ios/**/*.{h,m,mm,swift}"
s.source_files = "Classes/*.{h,m,mm,swift}"
s.dependency "WebRTC-lib"
s.dependency "bigbluebutton-mobile-sdk-common"

View File

@ -13,7 +13,7 @@ protocol WebRTCClientDelegate: AnyObject {
func webRTCClient(_ client: WebRTCClient, didChangeConnectionState state: RTCIceConnectionState)
}
final class WebRTCClient: NSObject {
open class WebRTCClient: NSObject {
// The `RTCPeerConnectionFactory` is in charge of creating new RTCPeerConnection instances.
// A new RTCPeerConnection should be created every new call, but the factory is shared.
@ -40,7 +40,7 @@ final class WebRTCClient: NSObject {
fatalError("WebRTCClient:init is unavailable")
}
required init(iceServers: [String]) {
public required init(iceServers: [String]) {
let config = RTCConfiguration()
config.iceServers = [RTCIceServer(urlStrings: iceServers)]
@ -69,14 +69,11 @@ final class WebRTCClient: NSObject {
// MARK: Signaling
func offer(completion: @escaping (_ sdp: RTCSessionDescription) -> Void) {
public func offer() async throws -> RTCSessionDescription {
let constrains = RTCMediaConstraints(mandatoryConstraints: self.mediaConstrains, optionalConstraints: nil)
self.peerConnection.offer(for: constrains) { (sdp, error) in
guard let sdp = sdp else { return }
self.peerConnection.setLocalDescription(sdp, completionHandler: { (error) in
completion(sdp)
})
}
let sdp = try await self.peerConnection.offer(for: constrains)
try await self.peerConnection.setLocalDescription(sdp)
return sdp
}
func set(remoteSdp: RTCSessionDescription, completion: @escaping (Error?) -> ()) {
@ -140,41 +137,41 @@ final class WebRTCClient: NSObject {
extension WebRTCClient: RTCPeerConnectionDelegate {
func peerConnection(_ peerConnection: RTCPeerConnection, didChange stateChanged: RTCSignalingState) {
public func peerConnection(_ peerConnection: RTCPeerConnection, didChange stateChanged: RTCSignalingState) {
debugPrint("peerConnection new signaling state: \(stateChanged)")
}
func peerConnection(_ peerConnection: RTCPeerConnection, didAdd stream: RTCMediaStream) {
public func peerConnection(_ peerConnection: RTCPeerConnection, didAdd stream: RTCMediaStream) {
debugPrint("peerConnection did add stream \(stream)")
}
func peerConnection(_ peerConnection: RTCPeerConnection, didRemove stream: RTCMediaStream) {
public func peerConnection(_ peerConnection: RTCPeerConnection, didRemove stream: RTCMediaStream) {
debugPrint("peerConnection did remove stream \(stream)")
}
func peerConnectionShouldNegotiate(_ peerConnection: RTCPeerConnection) {
public func peerConnectionShouldNegotiate(_ peerConnection: RTCPeerConnection) {
debugPrint("peerConnection should negotiate")
}
func peerConnection(_ peerConnection: RTCPeerConnection, didChange newState: RTCIceConnectionState) {
public func peerConnection(_ peerConnection: RTCPeerConnection, didChange newState: RTCIceConnectionState) {
debugPrint("peerConnection new connection state: \(newState)")
self.delegate?.webRTCClient(self, didChangeConnectionState: newState)
}
func peerConnection(_ peerConnection: RTCPeerConnection, didChange newState: RTCIceGatheringState) {
public func peerConnection(_ peerConnection: RTCPeerConnection, didChange newState: RTCIceGatheringState) {
debugPrint("peerConnection new gathering state: \(newState)")
}
func peerConnection(_ peerConnection: RTCPeerConnection, didGenerate candidate: RTCIceCandidate) {
public func peerConnection(_ peerConnection: RTCPeerConnection, didGenerate candidate: RTCIceCandidate) {
debugPrint("peerConnection discovered new candidate")
self.delegate?.webRTCClient(self, didDiscoverLocalCandidate: candidate)
}
func peerConnection(_ peerConnection: RTCPeerConnection, didRemove candidates: [RTCIceCandidate]) {
public func peerConnection(_ peerConnection: RTCPeerConnection, didRemove candidates: [RTCIceCandidate]) {
debugPrint("peerConnection did remove candidate(s)")
}
func peerConnection(_ peerConnection: RTCPeerConnection, didOpen dataChannel: RTCDataChannel) {
public func peerConnection(_ peerConnection: RTCPeerConnection, didOpen dataChannel: RTCDataChannel) {
debugPrint("peerConnection did open data channel")
}
}
@ -255,11 +252,11 @@ extension WebRTCClient {
}
extension WebRTCClient: RTCDataChannelDelegate {
func dataChannelDidChangeState(_ dataChannel: RTCDataChannel) {
public func dataChannelDidChangeState(_ dataChannel: RTCDataChannel) {
debugPrint("dataChannel did change state: \(dataChannel.readyState)")
}
func dataChannel(_ dataChannel: RTCDataChannel, didReceiveMessageWith buffer: RTCDataBuffer) {
public func dataChannel(_ dataChannel: RTCDataChannel, didReceiveMessageWith buffer: RTCDataBuffer) {
debugPrint("dataChannel did receive message with buffer: \(buffer)")
}
}

View File

@ -13,7 +13,7 @@ Pod::Spec.new do |s|
s.platforms = { :ios => "14.7" }
s.source = { :git => "https://github.com/bigbluebutton/bigbluebutton-mobile-sdk.git", :tag => "#{s.version}" }
s.source_files = "ios/**/*.{h,m,mm,swift}"
s.source_files = "Classes/*.{h,m,mm,swift}"
s.dependency "WebRTC-lib"
end