await client.call('default', 'test-outgoing-call').getOrCreate({
ring: true,
data: {
members: [
{ user_id: 'myself' },
{ user_id: 'my friend' },
],
},
});
Ringing calls
The Call
object provides several options to ring and notify users about a call.
Create call
To create a ring call, we need to set the ring
flag to true
and provide the list of members we want to call.
It is important to note that the caller should also be included in the list of members.
Call creation options
The following options are supported when creating a call:
Option | Description | Default |
---|---|---|
members | A list of members to add to this call. You can specify the role and custom data on these members | - |
custom | Any custom data you want to store | - |
settings | You can overwrite certain call settings for this specific call. This overwrites the call type standard settings | - |
startsAt | When the call will start. Used for calls scheduled in the future, livestreams, audio rooms etc | - |
team | Restrict the access to this call to a specific team | - |
ring | If you want the call to ring for each member | false |
notify | If you want the call to nofiy each member by sending push notification. | false |
This step will start the signaling flow. The caller will automatically join the call once the first callee accepts the call. The call will automatically stop if every callee rejects the call.
Watch for incoming and outgoing calls
The easiest way to watch for incoming and outgoing calls is to use the useCalls
hook.
import { useCalls, CallingState } from '@stream-io/video-react-sdk';
export const MyCallUI = () => {
const calls = useCalls();
// handle incoming ring calls
const incomingCalls = calls.filter(
(call) =>
call.isCreatedByMe === false &&
call.state.callingState === CallingState.RINGING,
);
const [incomingCall] = incomingCalls;
if (incomingCall) {
// render the incoming call UI
return <MyIncomingCallUI call={incomingCall} />;
}
// handle outgoing ring calls
const outgoingCalls = calls.filter(
(call) =>
call.isCreatedByMe === true &&
call.state.callingState === CallingState.RINGING,
);
const [outgoingCall] = outgoingCalls;
if (outgoingCall) {
// render the outgoing call UI
return <MyOutgoingCallUI call={outgoingCall} />;
}
return null;
};
You can also check the sample integration in the following CodeSandboxes:
Canceling an outgoing call
A caller can cancel an outgoing call until the first callee accepts the call. Canceling a call will stop the signaling flow.
await call.leave({ reject: true, reason: 'cancel' });
Please note that calling call.leave()
after joining the call won’t stop the signaling flow.
Rejecting an incoming call
A callee can accept or reject an incoming call. To reject the call:
await call.leave({ reject: true, reason: 'decline' });
Accepting a call
A callee can accept or reject an incoming call. To accept and join the call:
await call.join();
Please note that it’s possible to join multiple calls. If you only want to allow one active call, you must leave joined calls before accepting an incoming call.
Leave call
To leave a joined call, you can use the leave
method:
await call.leave();
End call
Ending a call requires a special permission. This action terminates the call for everyone.
await call.endCall();
Notifying
In some cases, you just want to notify users that you joined a call, instead of ringing.
To do this, you should use the notify
option:
await call.getOrCreate({ notify: true });
When notify is true, a regular push notification will be sent to all the members. This can be useful for livestreams apps or huddles.
Similarly to ringing, you can use the get method if you are sure that the call exists:
await call.get({ notify: true });