Skip to main content

Joining & Creating Calls

This guide shows how to create, join, leave, and end call rooms and ring calls.

Call room

Create and join a call

You create a call by specifying a call type and a call id.

const callType = 'default';
const callId = 'test-call';
await videoClient.call(callType, callId).join({ create: true });

The call type controls which features are enabled, and sets up permissions.

One of the flags you can provide there is create. Set this to true if you want to enable creating new calls. Set it to false if you only want to allow joining existing calls.

See all possible options at the Call creation options section

If you don't want to join a call, just create one, you can use the getOrCreate method:

const callType = 'default';
const callId = 'test-call';
await videoClient.call(callType, callId).getOrCreate();

See all possible options at the Call creation options section

Leave call

To leave a call, you can use the leave method:

call.leave();

End call

Ending a call requires a special permission. This action terminates the call for everyone.

call.endCall();

Only users with special permission can join an ended call.

Ring 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.

client.call('default', 'test-outgoing-call').getOrCreate({
ring: true,
data: {
members: [
{ user_id: 'myself' },
{ user_id: 'my friend' },
],
},
});

See all possible options at the Call creation options section

This step will start the signaling flow. The caller will automatically join the call once the first callee accepts the call. The calling will automatically stop if all callee rejects the call.

note

When ring is true, a push notification will be sent to the members, provided their app have the required setup. For more details around push notifications, please check this page.

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-native-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;
};

Canceling a call

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

call.leave();

Please note that calling call.leave() after joining the call won't stop the signaling flow.

Accepting a call

A callee can accept or reject an incoming call. To accept and join the call:

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.

Rejecting a call

A callee can accept or reject an incoming call. To reject the call:

call.leave({ reject: true });

Leave call

To leave a joined call, you can use the leave method:

call.leave();

End call

Ending a call requires a special permission. This action terminates the call for everyone.

call.endCall();

Call creation options

The following options are supported when creating a call:

OptionDescriptionDefault
membersA list of members to add to this call. You can specify the role and custom data on these members-
customAny custom data you want to store-
settingsYou can overwrite certain call settings for this specific call. This overwrites the call type standard settings-
startsAtWhen the call will start. Used for calls scheduled in the future, livestreams, audio rooms etc-
teamRestrict the access to this call to a specific team-
ringIf you want the call to ring for each memberfalse
notifyIf you want the call to notify each member by sending push notificationfalse

Did you find this page helpful?