Skip to content

Commit

Permalink
feat(conference/native): created helper for handling notification/exa…
Browse files Browse the repository at this point in the history
…mple
  • Loading branch information
Calinteodor committed Dec 5, 2024
1 parent a81ff95 commit 88281ea
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
60 changes: 60 additions & 0 deletions react/features/conference/components/functions.native.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { IReduxState } from '../../app/types';

Check failure on line 1 in react/features/conference/components/functions.native.ts

View workflow job for this annotation

GitHub Actions / Lint

There should be at least one empty line between import groups

Check failure on line 1 in react/features/conference/components/functions.native.ts

View workflow job for this annotation

GitHub Actions / Lint

`../../app/types` import should occur after import of `../../app/logger`
import notifee, { AndroidImportance, AndroidVisibility, AuthorizationStatus } from '@notifee/react-native';

Check failure on line 2 in react/features/conference/components/functions.native.ts

View workflow job for this annotation

GitHub Actions / Lint

There should be at least one empty line between import groups
import logger from "../../app/logger";

Check failure on line 3 in react/features/conference/components/functions.native.ts

View workflow job for this annotation

GitHub Actions / Lint

Strings must use singlequote

export * from './functions.any';

Expand Down Expand Up @@ -30,3 +32,61 @@ export const isConnecting = (state: IReduxState) => {
connecting || (connection && (!membersOnly && (joining || (!conference && !leaving))))
);
};

export async function displayNotificationAsForegroundService() {

Check failure on line 36 in react/features/conference/components/functions.native.ts

View workflow job for this annotation

GitHub Actions / Lint

Missing JSDoc comment

// Foreground service needs to be registered first
notifee.registerForegroundService(() => {

Check failure on line 39 in react/features/conference/components/functions.native.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`
return new Promise(() => {
logger.warn('Foreground service running');
});
});

// Request permissions
const currentPermissions = await notifee.getNotificationSettings();

if (currentPermissions.authorizationStatus !== AuthorizationStatus.AUTHORIZED) {
await notifee.requestPermission();
}

// Create notification channel
const channelId = await notifee.createChannel({
id: 'ongoing-channel',
name: 'Ongoing channel',
visibility: AndroidVisibility.PUBLIC
});

// Display notification
await notifee.displayNotification({
title: '<p style="color: #4caf50;"><b>Ongoing conference</span></p></b></p> &#128576;',
subtitle: '&#129395;',
body:
'Meeting <p style="text-decoration: line-through">you are </p> participating <p style="color: #ffffff; background-color: #9c27b0"><i>is ongoing</i></p> &#127881;!',

Check failure on line 64 in react/features/conference/components/functions.native.ts

View workflow job for this annotation

GitHub Actions / Lint

This line has a length of 176. Maximum allowed is 120
android: {
asForegroundService: true,
autoCancel: false,
channelId,
importance: AndroidImportance.HIGH,
color: '#4caf50',
ongoing: true,
actions: [
{
title: '<b>Dance</b> &#128111;',
pressAction: { id: 'dance' },

Check failure on line 75 in react/features/conference/components/functions.native.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected trailing comma
},
{
title: '<p style="color: #f44336;"><b>Cry</b> &#128557;</p>',
pressAction: { id: 'cry' },

Check failure on line 79 in react/features/conference/components/functions.native.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected trailing comma
},

Check failure on line 80 in react/features/conference/components/functions.native.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected trailing comma
],
},
} as Notification);
}

export async function stopForegroundService() {
try {
await notifee.stopForegroundService();
} catch (err) {
console.log(err);
}
}
7 changes: 6 additions & 1 deletion react/features/conference/components/native/Conference.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import {
abstractMapStateToProps
} from '../AbstractConference';
import type { AbstractProps } from '../AbstractConference';
import { isConnecting } from '../functions.native';
import {displayNotificationAsForegroundService, isConnecting, stopForegroundService} from '../functions.native';

import AlwaysOnLabels from './AlwaysOnLabels';
import ExpandedLabelPopup from './ExpandedLabelPopup';
Expand All @@ -57,6 +57,7 @@ import TitleBar from './TitleBar';
import { EXPANDED_LABEL_TIMEOUT } from './constants';
import styles from './styles';


/**
* The type of the React {@code Component} props of {@link Conference}.
*/
Expand Down Expand Up @@ -212,6 +213,8 @@ class Conference extends AbstractConference<IProps, State> {

BackHandler.addEventListener('hardwareBackPress', this._onHardwareBackPress);

displayNotificationAsForegroundService();

if (_audioOnlyEnabled && _startCarMode) {
navigation.navigate(screen.conference.carmode);
}
Expand Down Expand Up @@ -254,6 +257,8 @@ class Conference extends AbstractConference<IProps, State> {
// Tear handling any hardware button presses for back navigation down.
BackHandler.removeEventListener('hardwareBackPress', this._onHardwareBackPress);

stopForegroundService();

clearTimeout(this._expandedLabelTimeout.current ?? 0);
}

Expand Down

0 comments on commit 88281ea

Please sign in to comment.