Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the activeParticipants event to the notification service RN+android #106

Merged
merged 2 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.dolby.sdk.comms.reactnative.eventemitters
import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.ReactApplicationContext
import com.voxeet.sdk.models.Participant
import com.voxeet.sdk.push.center.subscription.event.ActiveParticipantsEvent
import com.voxeet.sdk.push.center.subscription.event.ConferenceCreatedNotificationEvent
import com.voxeet.sdk.push.center.subscription.event.ConferenceEndedNotificationEvent
import com.voxeet.sdk.push.center.subscription.event.InvitationReceivedNotificationEvent
Expand Down Expand Up @@ -117,6 +118,26 @@ class RNNotificationEventEmitter(
.also { send(NotificationEvent.ParticipantLeft.withData(it)) }
}

/**
* Emitted when participant left conference.
*/
@Subscribe(threadMode = MAIN)
fun on(event: ActiveParticipantsEvent) {
Arguments.createMap()
.apply {
putString(KEY_CONFERENCE_ALIAS, event.conferenceAlias)
putString(KEY_CONFERENCE_ID, event.conferenceId)
putInt(KEY_PARTICIPANTS_COUNT, event.participantCount)
putArray(KEY_PARTICIPANT_LIST, Arguments.createArray().apply {
event.participants
.filterNotNull()
.map(participantMapper::toRN)
.forEach(::pushMap)
})
}
.also { send(NotificationEvent.ActiveParticipants.withData(it)) }
}

/**
* Notification events
*/
Expand All @@ -127,6 +148,7 @@ class RNNotificationEventEmitter(
object ConferenceStatus : RNEvent("EVENT_NOTIFICATION_CONFERENCE_STATUS")
object ParticipantJoined : RNEvent("EVENT_NOTIFICATION_PARTICIPANT_JOINED")
object ParticipantLeft : RNEvent("EVENT_NOTIFICATION_PARTICIPANT_LEFT")
object ActiveParticipants : RNEvent("EVENT_NOTIFICATION_ACTIVE_PARTICIPANTS")
}

/**
Expand All @@ -136,6 +158,7 @@ class RNNotificationEventEmitter(
private const val KEY_CONFERENCE_ALIAS = "conferenceAlias"
private const val KEY_CONFERENCE_ID = "conferenceId"
private const val KEY_PARTICIPANT = "participant"
private const val KEY_PARTICIPANTS_COUNT = "participantCount"
private const val KEY_PARTICIPANT_LIST = "participants"
private const val KEY_CONFERENCE_LIVE = "live"
}
Expand Down
21 changes: 21 additions & 0 deletions docs/classes/internal.NotificationService.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ The NotificationService allows inviting participants to a conference.
- [onConferenceEnded](internal.NotificationService.md#onconferenceended)
- [onParticipantJoined](internal.NotificationService.md#onparticipantjoined)
- [onParticipantLeft](internal.NotificationService.md#onparticipantleft)
- [onActiveParticipants](internal.NotificationService.md#onactiveparticipants)

## Constructors

Expand Down Expand Up @@ -221,3 +222,23 @@ Adds a listener to the participant left event.
[`UnsubscribeFunction`](../modules/internal.md#unsubscribefunction)

A function that unsubscribes from event listeners.

___

### onActiveParticipants

▸ **onActiveParticipants**(`handler`): [`UnsubscribeFunction`](../modules/internal.md#unsubscribefunction)

Adds a listener to the participant active event.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `handler` | (`data`: [`ActiveParticipantsEventType`](../interfaces/internal.ActiveParticipantsEventType.md)) => `void` | An event callback function. |

#### Returns

[`UnsubscribeFunction`](../modules/internal.md#unsubscribefunction)

A function that unsubscribes from event listeners.
44 changes: 44 additions & 0 deletions docs/interfaces/internal.ActiveParticipantsEventType.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Interface: ActiveParticipantsEventType

[internal](../modules/internal.md).ActiveParticipantsEventType

## Table of contents

### Properties

- [conferenceAlias](internal.ActiveParticipantsEventType.md#conferencealias)
- [conferenceId](internal.ActiveParticipantsEventType.md#conferenceid)
- [participantCount](internal.ActiveParticipantsEventType.md#participantcount)
- [participants](internal.ActiveParticipantsEventType.md#participants)

## Properties

### conferenceAlias

• **conferenceAlias**: `string`

The conference alias.

___

### conferenceId

• **conferenceId**: `string`

The conference ID.

___

### participantCount

• **participantCount**: `number`

The participant count.

___

### participants

• **participants**: [[`Participant`](internal.Participant.md)]

The list of active participants.
1 change: 1 addition & 0 deletions docs/modules/internal.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
- [ConferenceEndedEventType](../interfaces/internal.ConferenceEndedEventType.md)
- [ParticipantJoinedEventType](../interfaces/internal.ParticipantJoinedEventType.md)
- [ParticipantLeftEventType](../interfaces/internal.ParticipantLeftEventType.md)
- [ActiveParticipantsEventType](../interfaces/internal.ActiveParticipantsEventType.md)
- [Subscription](../interfaces/internal.Subscription.md)
- [RecordingStatusUpdatedEventType](../interfaces/internal.RecordingStatusUpdatedEventType.md)
- [Recording](../interfaces/internal.Recording.md)
Expand Down
2 changes: 2 additions & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Main from './Main';
import ConferenceStatusHandler from '@components/ConferenceStatusHandler';
import ParticipantJoinedHandler from '@components/ParticipantJoinedHandler';
import ParticipantLeftHandler from '@components/ParticipantLeftHandler';
import ActiveParticipantsHandler from '@components/ActiveParticipantsHandler';

export interface Props {}

Expand Down Expand Up @@ -47,6 +48,7 @@ export default class App extends Component<Props, State> {
<ConferenceEndedHandler />
<ParticipantJoinedHandler />
<ParticipantLeftHandler />
<ActiveParticipantsHandler />
</DolbyIOProvider>
</KeyboardAvoidingView>
</GestureHandlerRootView>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React, { useEffect } from 'react';

import CommsAPI from '@dolbyio/comms-sdk-react-native';

import type { ActiveParticipantsEventType } from '../../../../src/services/notification/events';

const ActiveParticipantsHandler: React.FC = () => {
const onActiveParticipants = (data: ActiveParticipantsEventType) => {
console.log(
'ACTIVE PARTICIPNATS EVENT DATA: \n',
JSON.stringify(data, null, 2)
);

};

useEffect(() => {
return CommsAPI.notification.onActiveParticipants(onActiveParticipants);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

return null;
};

export default ActiveParticipantsHandler;
1 change: 1 addition & 0 deletions example/src/components/ActiveParticipantsHandler/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './ActiveParticipantsHandler';
15 changes: 15 additions & 0 deletions src/services/notification/NotificationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type {
InvitationReceivedEventType,
ParticipantJoinedEventType,
ParticipantLeftEventType,
ActiveParticipantsEventType,
} from './events';
import type { Subscription } from './models';

Expand Down Expand Up @@ -147,6 +148,20 @@ export class NotificationService {
handler
);
}

/**
* Adds a listener to the participant active event.
* @param handler An event callback function.
* @returns A function that unsubscribes from event listeners.
*/
public onActiveParticipants(
handler: (data: ActiveParticipantsEventType) => void
): UnsubscribeFunction {
return this._nativeEvents.addListener(
NotificationServiceEventNames.ActiveParticipants,
handler
);
}
}

export default new NotificationService();
12 changes: 12 additions & 0 deletions src/services/notification/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,16 @@ describe('NotificationService', () => {
);
});
});

describe('onActiveParticipnats()', () => {
it('should invoke NativeEvents.addListener with ActiveParticipants event', () => {
NotificationService.onActiveParticipants(() => {});
expect(
NotificationService._nativeEvents.addListener
).toHaveBeenCalledWith(
NotificationServiceEventNames.ActiveParticipants,
expect.any(Function)
);
});
});
});
13 changes: 13 additions & 0 deletions src/services/notification/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export enum NotificationServiceEventNames {
ConferenceEnded = 'EVENT_NOTIFICATION_CONFERENCE_ENDED',
ParticipantJoined = 'EVENT_NOTIFICATION_PARTICIPANT_JOINED',
ParticipantLeft = 'EVENT_NOTIFICATION_PARTICIPANT_LEFT',
ActiveParticipants = 'EVENT_NOTIFICATION_ACTIVE_PARTICIPANTS',
}

/** The InvitationReceivedEventType interface gathers information about the received invitation. */
Expand Down Expand Up @@ -68,11 +69,23 @@ export interface ParticipantLeftEventType {
participant: Participant;
}

export interface ActiveParticipantsEventType {
/** The conference alias. */
conferenceAlias: string;
/** The conference ID. */
conferenceId: string;
/** The participant count. */
participantCount: number;
/** The list of active participants. */
participants: [Participant];
}

export interface NotificationServiceEventMap {
[NotificationServiceEventNames.InvitationReceived]: InvitationReceivedEventType;
[NotificationServiceEventNames.ConferenceStatus]: ConferenceStatusEventType;
[NotificationServiceEventNames.ConferenceCreated]: ConferenceCreatedEventType;
[NotificationServiceEventNames.ConferenceEnded]: ConferenceEndedEventType;
[NotificationServiceEventNames.ParticipantJoined]: ParticipantJoinedEventType;
[NotificationServiceEventNames.ParticipantLeft]: ParticipantLeftEventType;
[NotificationServiceEventNames.ActiveParticipants]: ActiveParticipantsEventType;
}