import { StreamVideoClient } from "@stream-io/video-react-sdk";
const client = StreamVideoClient.getOrCreateInstance({
apiKey,
tokenProvider,
user,
options: { rejectCallWhenBusy: true },
});
```ient?.setShouldRejectCallWhenBusy(true);
Reject call when busy
In this documentation article, we will explore how to setup automatic call rejection on callee side when callee is in another ringing call. Also we will show how this information can be presented on the caller side.
Reject call when busy
To enable this we need to configure the client with the option rejectCallWhenBusy
set to true
.
With this the call will be automatically rejected by the callee. The call rejected event will be attached with reason busy
..
In this case on the caller side we play busy tone sound by default. Additionally you can show visual info on the caller side that the callee is busy in another call.
This is one example how we can show some toast message from the call.rejected
event handler on our videoClient
:
import { useStreamVideoClient } from "@stream-io/video-react-sdk";
const videoClient = useStreamVideoClient();
useEffect(() => {
if (!videoClient) return;
return videoClient.on("call.rejected", async (event) => {
const isCallCreatedByMe =
event.call.created_by.id === _videoClient?.state.connectedUser?.id;
const isCalleeBusy = isCallCreatedByMe && event.reason === "busy";
if (isCalleeBusy) {
// add command to play an audio file from URI (busy tone file needs to be added in your project resources)
// e.g. https://github.com/GetStream/stream-video-js/blob/main/sample-apps/react/react-dogfood/lib/beeper.ts
beep("/beeps/busy.mp3");
alert("Call rejected because user is busy.");
}
});
}, [videoClient]);