mattermost-mobile-upstream/app/products/calls/calls_manager.ts
2026-06-04 06:54:40 +08:00

37 lines
1.1 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {AppState, Platform, type NativeEventSubscription} from 'react-native';
import {callsOnAppStateChange} from '@calls/state';
import {logDebug} from '@utils/log';
let appStateChangeListener: NativeEventSubscription | undefined;
let appStateBlurListener: NativeEventSubscription | undefined;
let appStateFocusListener: NativeEventSubscription | undefined;
const initialize = () => {
logDebug('CallsManager: Initializing');
if (Platform.OS === 'android') {
appStateBlurListener = AppState.addEventListener('blur', () => {
callsOnAppStateChange('inactive');
});
appStateFocusListener = AppState.addEventListener('focus', () => {
callsOnAppStateChange('active');
});
} else {
appStateChangeListener = AppState.addEventListener('change', callsOnAppStateChange);
}
};
const cleanup = () => {
appStateChangeListener?.remove();
appStateBlurListener?.remove();
appStateFocusListener?.remove();
};
export const CallsManager = {
initialize,
cleanup,
};