Skip to content
This repository has been archived by the owner on May 16, 2024. It is now read-only.

Commit

Permalink
Initialize audioOutputDevice manager using onCreate expo module metho…
Browse files Browse the repository at this point in the history
…d, remove initializeWebRTC function (#164)
  • Loading branch information
karkakol authored May 6, 2024
1 parent 1dae878 commit b2592bc
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ class MembraneWebRTC(val sendEvent: (name: String, data: Map<String, Any?>) -> U
var onTracksUpdateListeners: MutableList<OnTrackUpdateListener> = mutableListOf()
}

fun onDestroy() {
fun onModuleCreate(appContext: AppContext){
this.appContext = appContext
this.audioSwitchManager = AudioSwitchManager(appContext.reactContext!!)
}

fun onModuleDestroy() {
audioSwitchManager?.stop()
}

Expand All @@ -98,7 +103,7 @@ class MembraneWebRTC(val sendEvent: (name: String, data: Map<String, Any?>) -> U
}
}

private fun getSimulcastConfigFromOptions(simulcastConfigMap: com.reactnativemembrane.SimulcastConfig): SimulcastConfig {
private fun getSimulcastConfigFromOptions(simulcastConfigMap: org.membraneframework.reactnative.SimulcastConfig): SimulcastConfig {
val simulcastEnabled = simulcastConfigMap.enabled
val activeEncodings = simulcastConfigMap.activeEncodings.map { e -> e.toTrackEncoding() }
return SimulcastConfig(
Expand Down Expand Up @@ -137,7 +142,6 @@ class MembraneWebRTC(val sendEvent: (name: String, data: Map<String, Any?>) -> U
}

fun create() {
audioSwitchManager = AudioSwitchManager(appContext?.reactContext!!)
membraneRTC = MembraneRTC.create(
appContext = appContext?.reactContext!!, listener = this
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,19 @@ class MembraneWebRTCModule : Module() {
}

OnCreate {
membraneWebRTC.appContext = appContext
membraneWebRTC.onModuleCreate(appContext)
}

OnDestroy {
membraneWebRTC.onModuleDestroy()
}

OnActivityDestroys {
membraneWebRTC.disconnect()
}

OnActivityResult { _, result ->
membraneWebRTC.onActivityResult(result.requestCode, result.resultCode, result.data)
}

AsyncFunction("create") Coroutine ({ ->
Expand Down Expand Up @@ -272,17 +284,5 @@ class MembraneWebRTCModule : Module() {
AsyncFunction("getStatistics") { ->
membraneWebRTC.getStatistics()
}

OnActivityResult { _, result ->
membraneWebRTC.onActivityResult(result.requestCode, result.resultCode, result.data)
}

OnDestroy {
membraneWebRTC.onDestroy()
}

OnActivityDestroys {
membraneWebRTC.disconnect()
}
}
}
8 changes: 0 additions & 8 deletions src/common/webRTC.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import { LoggingSeverity, TrackEncoding } from '../MembraneWebRTC.types';
import MembraneWebRTCModule from '../MembraneWebRTCModule';

/**
* This function initialize necessary native objects to properly handle sound and video.
* Call it only once in your app before any other functionality, otherwise package will not work as intended.
*/
export async function initializeWebRTC() {
await MembraneWebRTCModule.create();
}

/**
* sets track encoding that server should send to the client library.
* The encoding will be sent whenever it is available. If chooses encoding is
Expand Down
11 changes: 3 additions & 8 deletions src/hooks/useWebRTC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@ import { ConnectionOptions, Metadata } from '../MembraneWebRTC.types';
import MembraneWebRTCModule from '../MembraneWebRTCModule';
import { ReceivableEvents, eventEmitter } from '../common/eventEmitter';

/**
* This function initialize necessary native objects to properly handle sound and video.
* Call it only once in your app before any other functionality, otherwise package will not work as intended.
*/
export async function initializeWebRTC() {
await MembraneWebRTCModule.create();
}

/**
* The hook used to manage a connection with membrane server.
* @returns An object with functions to manage membrane server connection and `error` if connection failed.
Expand Down Expand Up @@ -113,6 +105,9 @@ export function useWebRTC() {

socket.current = _socket;
webrtcChannel.current = _webrtcChannel;

await MembraneWebRTCModule.create();

await new Promise<void>((resolve, reject) => {
_webrtcChannel
.join()
Expand Down
1 change: 0 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export {
updateVideoTrackMetadata,
} from './common/metadata';
export {
initializeWebRTC,
changeWebRTCLoggingSeverity,
setTargetTrackEncoding,
} from './common/webRTC';
Expand Down

0 comments on commit b2592bc

Please sign in to comment.