Browse SDKs · React Native
SDKsReact NativeEnterprise

Handle call events

Listen for call events with OpenIM React Native SDK.

Copy

Call events report invitation status, participant status, and media-stream status. For invitation events, read room information from invitation in the callback parameter. Media-stream events provide roomID directly. To send and receive custom signals, see Send a custom signal.

Event parameters

EventCallback parameter typeCommon fields
OnReceiveNewInvitationOnReceiveNewInvitationPayloadinvitation, userID, participant, offlinePushInfo.
OnInviteeAcceptedOnInviteeAcceptedPayloadinvitation, userID, participant, opUserPlatformID.
OnInviteeRejectedOnInviteeRejectedPayloadinvitation, userID, participant, opUserPlatformID.
OnInvitationCancelledOnInvitationCancelledPayloadinvitation, userID, participant, offlinePushInfo.
OnInvitationTimeoutOnReceiveNewInvitationPayloadinvitation, userID, participant, offlinePushInfo.
OnInviteeAcceptedByOtherDeviceOnInviteeAcceptedPayloadinvitation, userID, participant, opUserPlatformID.
OnInviteeRejectedByOtherDeviceOnInviteeRejectedPayloadinvitation, userID, participant, opUserPlatformID.
OnHangUpOnHangUpPayloadinvitation, userID, offlinePushInfo.
OnRoomParticipantConnectedOnRoomParticipantConnectedPayloadinvitation, groupID, participant.
OnRoomParticipantDisconnectedOnRoomParticipantDisconnectedPayloadinvitation, groupID, participant.
OnStreamChangeOnStreamChangePayloadroomID, streamType, mute.

Use invitation.roomID or roomID to distinguish calls. Use participant.userInfo.userID to distinguish participants.

function handleReceiveNewInvitation(payload: OnReceiveNewInvitationPayload) {
  // ...
}

function handleInviteeAccepted(payload: OnInviteeAcceptedPayload) {
  // ...
}

function handleInviteeRejected(payload: OnInviteeRejectedPayload) {
  // ...
}

function handleInvitationCancelled(payload: OnInvitationCancelledPayload) {
  // ...
}

function handleInvitationTimeout(payload: OnReceiveNewInvitationPayload) {
  // ...
}

function handleInviteeAcceptedByOtherDevice(payload: OnInviteeAcceptedPayload) {
  // ...
}

function handleInviteeRejectedByOtherDevice(payload: OnInviteeRejectedPayload) {
  // ...
}

function handleHangUp(payload: OnHangUpPayload) {
  // ...
}

function handleRoomParticipantConnected(
  payload: OnRoomParticipantConnectedPayload,
) {
  // ...
}

function handleRoomParticipantDisconnected(
  payload: OnRoomParticipantDisconnectedPayload,
) {
  // ...
}

function handleStreamChange(payload: OnStreamChangePayload) {
  // ...
}

// Start listening
OpenIMSDK.on(OpenIMEvent.OnReceiveNewInvitation, handleReceiveNewInvitation);
OpenIMSDK.on(OpenIMEvent.OnInviteeAccepted, handleInviteeAccepted);
OpenIMSDK.on(OpenIMEvent.OnInviteeRejected, handleInviteeRejected);
OpenIMSDK.on(OpenIMEvent.OnInvitationCancelled, handleInvitationCancelled);
OpenIMSDK.on(OpenIMEvent.OnInvitationTimeout, handleInvitationTimeout);
OpenIMSDK.on(
  OpenIMEvent.OnInviteeAcceptedByOtherDevice,
  handleInviteeAcceptedByOtherDevice,
);
OpenIMSDK.on(
  OpenIMEvent.OnInviteeRejectedByOtherDevice,
  handleInviteeRejectedByOtherDevice,
);
OpenIMSDK.on(OpenIMEvent.OnHangUp, handleHangUp);
OpenIMSDK.on(
  OpenIMEvent.OnRoomParticipantConnected,
  handleRoomParticipantConnected,
);
OpenIMSDK.on(
  OpenIMEvent.OnRoomParticipantDisconnected,
  handleRoomParticipantDisconnected,
);
OpenIMSDK.on(OpenIMEvent.OnStreamChange, handleStreamChange);

// Stop listening
OpenIMSDK.off(OpenIMEvent.OnReceiveNewInvitation, handleReceiveNewInvitation);
OpenIMSDK.off(OpenIMEvent.OnInviteeAccepted, handleInviteeAccepted);
OpenIMSDK.off(OpenIMEvent.OnInviteeRejected, handleInviteeRejected);
OpenIMSDK.off(OpenIMEvent.OnInvitationCancelled, handleInvitationCancelled);
OpenIMSDK.off(OpenIMEvent.OnInvitationTimeout, handleInvitationTimeout);
OpenIMSDK.off(
  OpenIMEvent.OnInviteeAcceptedByOtherDevice,
  handleInviteeAcceptedByOtherDevice,
);
OpenIMSDK.off(
  OpenIMEvent.OnInviteeRejectedByOtherDevice,
  handleInviteeRejectedByOtherDevice,
);
OpenIMSDK.off(OpenIMEvent.OnHangUp, handleHangUp);
OpenIMSDK.off(
  OpenIMEvent.OnRoomParticipantConnected,
  handleRoomParticipantConnected,
);
OpenIMSDK.off(
  OpenIMEvent.OnRoomParticipantDisconnected,
  handleRoomParticipantDisconnected,
);
OpenIMSDK.off(OpenIMEvent.OnStreamChange, handleStreamChange);

Stop listening when the component is unmounted, the user signs out, or the account changes.