Skip to content

Commit 6fc245f

Browse files
fix android observer initialization (#24)
* fix android observer initialization * lint fix
1 parent 948224c commit 6fc245f

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ public WebRTCModule(ReactApplicationContext reactContext) {
116116
getUserMediaImpl = new GetUserMediaImpl(this, reactContext);
117117
foregroundServiceController = new ForegroundServiceController(reactContext);
118118
audioOutputManager = new AudioOutputManager(this, reactContext);
119+
}
120+
121+
@Override
122+
public void initialize() {
123+
super.initialize();
119124
audioOutputManager.startObserving();
120125
}
121126

@@ -137,9 +142,11 @@ private PeerConnection getPeerConnection(int id) {
137142
}
138143

139144
void sendEvent(String eventName, @Nullable ReadableMap params) {
140-
getReactApplicationContext()
141-
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
142-
.emit(eventName, params);
145+
ReactApplicationContext ctx = getReactApplicationContext();
146+
if (!ctx.hasActiveReactInstance()) {
147+
return;
148+
}
149+
ctx.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(eventName, params);
143150
}
144151

145152
private PeerConnection.IceServer createIceServer(String url) {

0 commit comments

Comments
 (0)