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

Commit b2592bc

Browse files
authored
Initialize audioOutputDevice manager using onCreate expo module method, remove initializeWebRTC function (#164)
1 parent 1dae878 commit b2592bc

File tree

5 files changed

+23
-33
lines changed

5 files changed

+23
-33
lines changed

android/src/main/java/org/membraneframework/reactnative/MembraneWebRTC.kt

+7-3
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,12 @@ class MembraneWebRTC(val sendEvent: (name: String, data: Map<String, Any?>) -> U
7979
var onTracksUpdateListeners: MutableList<OnTrackUpdateListener> = mutableListOf()
8080
}
8181

82-
fun onDestroy() {
82+
fun onModuleCreate(appContext: AppContext){
83+
this.appContext = appContext
84+
this.audioSwitchManager = AudioSwitchManager(appContext.reactContext!!)
85+
}
86+
87+
fun onModuleDestroy() {
8388
audioSwitchManager?.stop()
8489
}
8590

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

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

139144
fun create() {
140-
audioSwitchManager = AudioSwitchManager(appContext?.reactContext!!)
141145
membraneRTC = MembraneRTC.create(
142146
appContext = appContext?.reactContext!!, listener = this
143147
)

android/src/main/java/org/membraneframework/reactnative/MembraneWebRTCModule.kt

+13-13
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,19 @@ class MembraneWebRTCModule : Module() {
9191
}
9292

9393
OnCreate {
94-
membraneWebRTC.appContext = appContext
94+
membraneWebRTC.onModuleCreate(appContext)
95+
}
96+
97+
OnDestroy {
98+
membraneWebRTC.onModuleDestroy()
99+
}
100+
101+
OnActivityDestroys {
102+
membraneWebRTC.disconnect()
103+
}
104+
105+
OnActivityResult { _, result ->
106+
membraneWebRTC.onActivityResult(result.requestCode, result.resultCode, result.data)
95107
}
96108

97109
AsyncFunction("create") Coroutine ({ ->
@@ -272,17 +284,5 @@ class MembraneWebRTCModule : Module() {
272284
AsyncFunction("getStatistics") { ->
273285
membraneWebRTC.getStatistics()
274286
}
275-
276-
OnActivityResult { _, result ->
277-
membraneWebRTC.onActivityResult(result.requestCode, result.resultCode, result.data)
278-
}
279-
280-
OnDestroy {
281-
membraneWebRTC.onDestroy()
282-
}
283-
284-
OnActivityDestroys {
285-
membraneWebRTC.disconnect()
286-
}
287287
}
288288
}

src/common/webRTC.ts

-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
import { LoggingSeverity, TrackEncoding } from '../MembraneWebRTC.types';
22
import MembraneWebRTCModule from '../MembraneWebRTCModule';
33

4-
/**
5-
* This function initialize necessary native objects to properly handle sound and video.
6-
* Call it only once in your app before any other functionality, otherwise package will not work as intended.
7-
*/
8-
export async function initializeWebRTC() {
9-
await MembraneWebRTCModule.create();
10-
}
11-
124
/**
135
* sets track encoding that server should send to the client library.
146
* The encoding will be sent whenever it is available. If chooses encoding is

src/hooks/useWebRTC.ts

+3-8
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,6 @@ import { ConnectionOptions, Metadata } from '../MembraneWebRTC.types';
55
import MembraneWebRTCModule from '../MembraneWebRTCModule';
66
import { ReceivableEvents, eventEmitter } from '../common/eventEmitter';
77

8-
/**
9-
* This function initialize necessary native objects to properly handle sound and video.
10-
* Call it only once in your app before any other functionality, otherwise package will not work as intended.
11-
*/
12-
export async function initializeWebRTC() {
13-
await MembraneWebRTCModule.create();
14-
}
15-
168
/**
179
* The hook used to manage a connection with membrane server.
1810
* @returns An object with functions to manage membrane server connection and `error` if connection failed.
@@ -113,6 +105,9 @@ export function useWebRTC() {
113105

114106
socket.current = _socket;
115107
webrtcChannel.current = _webrtcChannel;
108+
109+
await MembraneWebRTCModule.create();
110+
116111
await new Promise<void>((resolve, reject) => {
117112
_webrtcChannel
118113
.join()

src/index.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export {
1313
updateVideoTrackMetadata,
1414
} from './common/metadata';
1515
export {
16-
initializeWebRTC,
1716
changeWebRTCLoggingSeverity,
1817
setTargetTrackEncoding,
1918
} from './common/webRTC';

0 commit comments

Comments
 (0)