Skip to content

Commit

Permalink
create foreground notification channel once at startup
Browse files Browse the repository at this point in the history
  • Loading branch information
cpoile committed Oct 5, 2023
1 parent 2ecbdf5 commit f7c2b85
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
11 changes: 10 additions & 1 deletion app/products/calls/connection/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import InCallManager from 'react-native-incall-manager';
import {mediaDevices, MediaStream, MediaStreamTrack, RTCPeerConnection} from 'react-native-webrtc';

import {setPreferredAudioRoute, setSpeakerphoneOn} from '@calls/actions/calls';
import {foregroundServiceStart, foregroundServiceStop} from '@calls/connection/foreground_service';
import {
foregroundServiceStart,
foregroundServiceStop,
foregroundServiceSetup,
} from '@calls/connection/foreground_service';
import {processMeanOpinionScore, setAudioDeviceInfo} from '@calls/state';
import {AudioDevice, type AudioDeviceInfo, type AudioDeviceInfoRaw, type CallsConnection} from '@calls/types/calls';
import {getICEServersConfigs} from '@calls/utils';
Expand All @@ -27,6 +31,11 @@ const rtcMonitorInterval = 4000;

const InCallManagerEmitter = new NativeEventEmitter(NativeModules.InCallManager);

// Setup the foreground service channel
if (Platform.OS === 'android') {
foregroundServiceSetup();
}

export async function newConnection(
serverUrl: string,
channelID: string,
Expand Down
6 changes: 5 additions & 1 deletion app/products/calls/connection/foreground_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ const channelConfig = {
enableVibration: false,
};

// Note: multiple calls with same arguments are a noop.
export const foregroundServiceSetup = () => {
VIForegroundService.getInstance().createNotificationChannel(channelConfig);
};

export const foregroundServiceStart = async () => {
await VIForegroundService.getInstance().createNotificationChannel(channelConfig);
const notificationConfig = {
channelId: 'calls_channel',
id: 345678,
Expand Down

0 comments on commit f7c2b85

Please sign in to comment.