Skip to content

Commit 75a90e6

Browse files
authored
feat: make push notification listeners more flexible for easier debugging (#1542)
- [x] Removed notification listeners inside the SDK, but export them as utility functions - [x] Documentation guides how to add own listeners using the utility functions. This fixes #1447 - [x] Dogfood apps are updated - [x] Added doc on how to add incoming/outgoing call UIs on app root level - [x] throw error when deprecated navigation functions for ringing calls are used - [x] add section about how to add sound to ringing calls on foreground - [ ] make a 1.3 release
1 parent 49e2477 commit 75a90e6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1268
-824
lines changed

packages/react-native-sdk/docusaurus/docs/reactnative/04-ui-components/call/ringing-call-content.mdx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,21 @@ To use the `RingingCallContent` you can do the following:
4949

5050
```tsx {11}
5151
import {
52+
StreamCall,
5253
useCalls,
5354
RingingCallContent,
5455
} from '@stream-io/video-react-native-sdk';
5556

5657
const Call = () => {
57-
const calls = useCalls();
58+
// filter for ringing calls
59+
const calls = useCalls().filter(
60+
(c) => c.state.callingState === CallingState.RINGING,
61+
);
62+
const call = calls[0];
63+
if (!call) return null;
5864

5965
return (
60-
<StreamCall call={call[0]}>
66+
<StreamCall call={call}>
6167
<RingingCallContent />
6268
</StreamCall>
6369
);

packages/react-native-sdk/docusaurus/docs/reactnative/06-advanced/03-ringing.mdx

Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -44,50 +44,65 @@ The caller will automatically join the call once the first callee accepts the ca
4444
The call will automatically stop if every callee rejects the call.
4545

4646
:::note
47-
When ring is true, a push notification will be sent to the members, provided their app have the required setup.
47+
When ring is true, a **push notification** will be sent to the members, provided their app have the required setup.
4848
For more details around push notifications, please check [this page](../../advanced/push-notifications/overview).
4949
:::
5050

5151
## Watch for incoming and outgoing calls
5252

53-
The easiest way to watch for incoming and outgoing calls is to use the `useCalls` hook.
53+
The easiest way to watch for incoming and outgoing calls is to use the `useCalls` hook and the [`RingingCallContent`](../../ui-components/call/ringing-call-content) component.
5454

55-
```tsx
56-
import { useCalls, CallingState } from '@stream-io/video-react-native-sdk';
55+
**Important**: Make sure that the ringing calls are watched in the root component of your app. This makes sure that in whichever screen the user is in, or if the app was opened from a push notification it is shown. Below is an example of how to watch for ringing calls in the root component of your App.
5756

58-
export const MyCallUI = () => {
59-
const calls = useCalls();
57+
```ts
58+
import { SafeAreaView, StyleSheet } from 'react-native';
59+
import {
60+
StreamCall,
61+
StreamVideo,
62+
useCalls,
63+
RingingCallContent,
64+
StreamVideoClient,
65+
User,
66+
} from '@stream-io/video-react-native-sdk';
6067

61-
// handle incoming ring calls
62-
const incomingCalls = calls.filter(
63-
(call) =>
64-
call.isCreatedByMe === false &&
65-
call.state.callingState === CallingState.RINGING,
68+
const user: User = {
69+
id: 'sara',
70+
};
71+
const apiKey = '<STREAM-API-KEY>';
72+
const tokenProvider = () => Promise.resolve('<USER-TOKEN>');
73+
const client = StreamVideoClient.getOrCreateInstance({ apiKey, tokenProvider, user });
74+
75+
const RingingCalls = () => {
76+
// filter for ringing calls
77+
const calls = useCalls().filter(
78+
(c) => c.state.callingState === CallingState.RINGING,
6679
);
67-
68-
const [incomingCall] = incomingCalls;
69-
if (incomingCall) {
70-
// render the incoming call UI
71-
return <MyIncomingCallUI call={incomingCall} />;
72-
}
73-
74-
// handle outgoing ring calls
75-
const outgoingCalls = calls.filter(
76-
(call) =>
77-
call.isCreatedByMe === true &&
78-
call.state.callingState === CallingState.RINGING,
80+
const call = calls[0];
81+
if (!call) return null;
82+
83+
return (
84+
<StreamCall call={call}>
85+
<SafeAreaView style={StyleSheet.absoluteFill}>
86+
<RingingCallContent />
87+
</SafeAreaView>
88+
</StreamCall>
89+
);
90+
}
91+
92+
const App = () => {
93+
return (
94+
<StreamVideo client={client}>
95+
<MyApp />
96+
<RingingCalls />
97+
<StreamVideo>
7998
);
80-
81-
const [outgoingCall] = outgoingCalls;
82-
if (outgoingCall) {
83-
// render the outgoing call UI
84-
return <MyOutgoingCallUI call={outgoingCall} />;
85-
}
86-
87-
return null;
8899
};
100+
101+
export default App;
89102
```
90103

104+
In the above example, the component `RingingCalls` renders over the rest of the App whenever there is a incoming or outgoing call. Alternatively you can use a Modal view or Dialog to show there is a ringing call over the rest of your app.
105+
91106
## Canceling a call
92107

93108
A caller can cancel an outgoing call until the first callee accepts the call. Canceling a call will stop the signaling flow.

0 commit comments

Comments
 (0)