Skip to content

Commit 8267489

Browse files
author
Daily Autobot
committed
Merge branch 'main' into daily-js-releases
2 parents 7b5c0e8 + 3a421e9 commit 8267489

File tree

5 files changed

+54
-24
lines changed

5 files changed

+54
-24
lines changed

android/src/main/java/com/daily/reactlibrary/DailyNativeUtils.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.facebook.react.bridge.ReactContextBaseJavaModule;
2121
import com.facebook.react.bridge.ReactMethod;
2222
import com.facebook.react.bridge.WritableMap;
23+
import com.facebook.react.modules.core.DeviceEventManagerModule;
2324
import com.facebook.react.modules.core.PermissionAwareActivity;
2425
import com.facebook.react.modules.core.PermissionListener;
2526

@@ -35,6 +36,7 @@ public class DailyNativeUtils extends ReactContextBaseJavaModule implements Perm
3536
private static int PERMISSION_REQUEST_CODE = 666;
3637

3738
private final ReactApplicationContext reactContext;
39+
private DeviceEventManagerModule.RCTDeviceEventEmitter eventEmitter;
3840
private Set<String> requestersKeepingDeviceAwake = new HashSet<>();
3941
private Set<String> requestersShowingOngoingMeetingNotification = new HashSet<>();
4042

@@ -57,14 +59,17 @@ public void onHostPause() {
5759

5860
@Override
5961
public void onHostDestroy() {
62+
eventEmitter.emit("EventOnHostDestroy", Arguments.createMap());
6063
DailyOngoingMeetingForegroundService.stop(reactContext);
61-
// This seems extreme, but the process won't otherwise immediately stop sending
62-
// audio and video
63-
Process.killProcess(Process.myPid());
6464
}
6565
});
6666
}
6767

68+
@Override
69+
public void initialize() {
70+
this.eventEmitter = reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class);
71+
}
72+
6873
@Override
6974
public String getName() {
7075
return "DailyNativeUtils";

ios/DailyNativeUtils.m

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// Event to JS layer
1212
static NSString *const EventSystemScreenCaptureStop = @"EventSystemScreenCaptureStop";
1313
static NSString *const EventSystemScreenCaptureStart = @"EventSystemScreenCaptureStart";
14+
static NSString *const EventOnHostDestroy = @"EventOnHostDestroy";
1415

1516
@interface DailyNativeUtils()
1617

@@ -53,10 +54,24 @@ - (instancetype)init
5354
selector:@selector(handleNotificationScreenCaptureExtensionStarted)
5455
name:NotificationScreenCaptureExtensionStarted
5556
object:nil];
57+
58+
[[NSNotificationCenter defaultCenter] addObserver:self
59+
selector:@selector(applicationWillTerminate)
60+
name:UIApplicationWillTerminateNotification
61+
object:nil];
5662
}
5763
return self;
5864
}
5965

66+
- (void)applicationWillTerminate {
67+
NSLog(@"App is about to terminate");
68+
BOOL isStillOnMeeting = _requestersKeepingDeviceAwake.count > 0;
69+
if (isStillOnMeeting) {
70+
[self sendEventWithName:EventOnHostDestroy body:nil];
71+
NSLog(@"Triggered the event EventOnHostDestroy");
72+
}
73+
}
74+
6075
+ (BOOL)requiresMainQueueSetup
6176
{
6277
return NO;
@@ -65,7 +80,7 @@ + (BOOL)requiresMainQueueSetup
6580

6681
- (NSArray<NSString *> *)supportedEvents
6782
{
68-
return @[EventSystemScreenCaptureStop, EventSystemScreenCaptureStart];
83+
return @[EventSystemScreenCaptureStop, EventSystemScreenCaptureStart, EventOnHostDestroy];
6984
}
7085

7186
#pragma mark Public

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@daily-co/react-native-daily-js",
33
"private": true,
44
"//": "^ COMMENT OUT 'private: true' BEFORE RUNNING NPM PUBLISH",
5-
"version": "0.60.0",
5+
"version": "0.61.0",
66
"description": "React Native library for making video calls using Daily",
77
"main": "dist/index.js",
88
"types": "dist/index.d.ts",
@@ -30,7 +30,7 @@
3030
"baseUrl": "https://github.com/daily-co/react-native-daily-js"
3131
},
3232
"dependencies": {
33-
"@daily-co/daily-js": "^0.62.0",
33+
"@daily-co/daily-js": "^0.63.0",
3434
"@types/react-native-background-timer": "^2.0.0",
3535
"base-64": "^1.0.0",
3636
"react-native-url-polyfill": "^1.1.2"

src/index.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,20 @@ const dailyNativeUtilsEventEmitter = new NativeEventEmitter(DailyNativeUtils);
2525
let hasAudioFocus: boolean;
2626
let appState: AppStateStatus;
2727
const audioFocusChangeListeners: Set<(hasFocus: boolean) => void> = new Set();
28-
const appActiveStateChangeListeners: Set<(isActive: boolean) => void> =
29-
new Set();
28+
29+
export type DailyAppStateEvent = 'active' | 'inactive' | 'destroyed';
30+
const appStateChangeListeners: Set<
31+
(appState: DailyAppStateEvent) => void
32+
> = new Set();
33+
3034
const systemScreenCaptureStopListeners: Set<() => void> = new Set();
3135
let systemScreenCaptureStartCallback: { (): void } | null;
3236

3337
function setupEventListeners() {
38+
dailyNativeUtilsEventEmitter.addListener('EventOnHostDestroy', () => {
39+
appStateChangeListeners.forEach((listener) => listener('destroyed'));
40+
});
41+
3442
// audio focus: used by daily-js to auto-mute mic, for instance
3543
if (Platform.OS === 'android') {
3644
hasAudioFocus = true; // safe assumption, hopefully
@@ -56,7 +64,9 @@ function setupEventListeners() {
5664
const wasActive = previousState === 'active';
5765
const isActive = appState === 'active';
5866
if (wasActive !== isActive) {
59-
appActiveStateChangeListeners.forEach((listener) => listener(isActive));
67+
appStateChangeListeners.forEach((listener) =>
68+
listener(isActive ? 'active' : 'inactive')
69+
);
6070
}
6171
});
6272

@@ -127,15 +137,15 @@ function setupGlobals(): void {
127137
removeAudioFocusChangeListener: (listener: (hasFocus: boolean) => void) => {
128138
audioFocusChangeListeners.delete(listener);
129139
},
130-
addAppActiveStateChangeListener: (
131-
listener: (isActive: boolean) => void
140+
addAppStateChangeListener: (
141+
listener: (appState: DailyAppStateEvent) => void
132142
) => {
133-
appActiveStateChangeListeners.add(listener);
143+
appStateChangeListeners.add(listener);
134144
},
135-
removeAppActiveStateChangeListener: (
136-
listener: (isActive: boolean) => void
145+
removeAppStateChangeListener: (
146+
listener: (appState: DailyAppStateEvent) => void
137147
) => {
138-
appActiveStateChangeListeners.delete(listener);
148+
appStateChangeListeners.delete(listener);
139149
},
140150
addSystemScreenCaptureStopListener: (listener: () => void) => {
141151
systemScreenCaptureStopListeners.add(listener);

0 commit comments

Comments
 (0)