/ SDKs / React Native
SDKs
Calls SDKs React Native v1
Calls SDKs React Native
Calls SDKs
React Native
Version 1

Add an event handler

Copy link

Add event handlers for the client app to react to events that occur for the 1-to-1 call. Event handlers can detect device-specific events and call-specific events.

To detect device-specific events, add the onRinging event handler by registering the SendbirdCalls.setListener() method. After you’ve added the event handler, an incoming call is handled as shown below.

SendbirdCalls.setListener({
  onRinging(callProps: DirectCallProperties){
    // Processing incoming call.
  }
});

To detect call-specific events, add the DirectCallListener event handler by using the DirectCall.addLitsener() method. To see a full list of call-related events, search DirectCallListener in the API Reference.

const unsubscribe = directCall.addListener({
 onEstablished: (call: DirectCallProperties) => {},

 onConnected: (call: DirectCallProperties) => {},

 onEnded: (call: DirectCallProperties) => {},

 onRemoteAudioSettingsChanged: (call: DirectCallProperties) => {},

 onRemoteVideoSettingsChanged: (call: DirectCallProperties) => {},

 // ...
});

unsubscribe();

When you want to remove listeners that are no longer in use, call unsubscribe() when you receive onEnded or when you perform cleanup for useEffect.