Skip to content

Commit

Permalink
fix: allow specifying publish options in PN config (#1524)
Browse files Browse the repository at this point in the history
Follow-up to #1434. Allows specifying publish options for calls accepted
through Push Notifications config.
  • Loading branch information
oliverlaz authored Oct 17, 2024
1 parent 146a638 commit a2ae74e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
pushAcceptedIncomingCallCId$,
pushAndroidBackgroundDeliveredIncomingCallCId$,
pushRejectedIncomingCallCId$,
pushTappedIncomingCallCId$,
pushAndroidBackgroundDeliveredIncomingCallCId$,
} from '../../utils/push/rxSubjects';
import { useEffect } from 'react';
import { StreamVideoRN } from '../../utils';
Expand Down Expand Up @@ -91,7 +91,7 @@ const createCallSubscription = (
return behaviourSubjectWithCallCid
.pipe(filter(cidIsNotUndefined))
.subscribe(async (callCId) => {
await processCallFromPush(client, callCId, action);
await processCallFromPush(client, callCId, action, pushConfig);
if (action === 'accept') {
pushConfig.navigateAcceptCall();
} else if (action === 'pressed' || action === 'backgroundDelivered') {
Expand Down
8 changes: 7 additions & 1 deletion packages/react-native-sdk/src/utils/StreamVideoRN/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StreamVideoClient } from '@stream-io/video-client';
import { PublishOptions, StreamVideoClient } from '@stream-io/video-client';
import type { AndroidChannel } from '@notifee/react-native';

export type NonRingingPushEvent = 'call.live_started' | 'call.notification';
Expand All @@ -11,6 +11,12 @@ export type StreamVideoConfig = {
*/
push?: {
isExpo?: boolean;
/**
* The publish options to be used when joining a call from a push notification.
*
* @internal
*/
publishOptions?: PublishOptions;
ios: {
/**
* The name for the alias of push provider used for iOS
Expand Down
10 changes: 7 additions & 3 deletions packages/react-native-sdk/src/utils/push/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
Call,
getLogger,
RxUtils,
StreamVideoClient,
getLogger,
} from '@stream-io/video-client';
import type {
NonRingingPushEvent,
Expand Down Expand Up @@ -80,7 +80,7 @@ export const processCallFromPushInBackground = async (
logger('error', 'failed to create video client', e);
return;
}
await processCallFromPush(videoClient, call_cid, action);
await processCallFromPush(videoClient, call_cid, action, pushConfig);
};

/**
Expand All @@ -93,7 +93,8 @@ export const processCallFromPushInBackground = async (
export const processCallFromPush = async (
client: StreamVideoClient,
call_cid: string,
action: 'accept' | 'decline' | 'pressed' | 'backgroundDelivered'
action: 'accept' | 'decline' | 'pressed' | 'backgroundDelivered',
pushConfig: PushConfig
) => {
let callFromPush: Call;
try {
Expand All @@ -106,6 +107,9 @@ export const processCallFromPush = async (
// note: when action was pressed or delivered, we dont need to do anything as the only thing is to do is to get the call which adds it to the client
try {
if (action === 'accept') {
if (pushConfig.publishOptions) {
callFromPush.updatePublishOptions(pushConfig.publishOptions);
}
await callFromPush.join();
} else if (action === 'decline') {
await callFromPush.leave({ reject: true });
Expand Down

0 comments on commit a2ae74e

Please sign in to comment.