Browse SDKs · uni-app / uni-app x
SDKsuni-appEnterprise

Handle call events

OpenIM uni-app / uni-app x SDK guide for Handle call events.

Copy

Keep Commercial call listeners in one call-state layer. Merge invitation lifecycle, participant connection, and stream changes into the same local state keyed by roomID. Every event delivers a raw JSON string; keep the callback short, validate JSON, and then map it to the application's call domain model.

EventPurpose
onReceiveNewInvitationA new call invitation arrived.
onInviteeAccepted, onInviteeRejectedThe current invitation was accepted or rejected.
onInvitationCancelled, onInvitationTimeoutThe invitation was cancelled or timed out.
onInviteeAcceptedByOtherDevice, onInviteeRejectedByOtherDeviceAnother device for the same account handled it.
onHangUpA participant ended the call.
onRoomParticipantConnected, onRoomParticipantDisconnectedRoom participant connection changed.
onStreamChangeParticipant media stream state changed.
import {
  off,
  onHangUp,
  onInvitationCancelled,
  onInvitationTimeout,
  onInviteeAccepted,
  onInviteeAcceptedByOtherDevice,
  onInviteeRejected,
  onInviteeRejectedByOtherDevice,
  onReceiveNewInvitation,
  onRoomParticipantConnected,
  onRoomParticipantDisconnected,
  onStreamChange,
  type OpenIMSDKEventSubscription,
} from '@/uni_modules/unix-openim-sdk'

function handleCallPayload(payload : string) {
  try {
    const value = JSON.parseObject<UTSJSONObject>(payload)
    if (value != null) routeValidatedCallEvent(value)
  } catch (_) {
    console.error('Invalid call event payload')
  }
}

const invitationSubscription = onReceiveNewInvitation(handleCallPayload)
const subscriptions : Array<OpenIMSDKEventSubscription> = [
  invitationSubscription,
  onInviteeAccepted(handleCallPayload),
  onInviteeAcceptedByOtherDevice(handleCallPayload),
  onInviteeRejected(handleCallPayload),
  onInviteeRejectedByOtherDevice(handleCallPayload),
  onInvitationCancelled(handleCallPayload),
  onInvitationTimeout(handleCallPayload),
  onHangUp(handleCallPayload),
  onRoomParticipantConnected(handleCallPayload),
  onRoomParticipantDisconnected(handleCallPayload),
  onStreamChange(handleCallPayload),
]

function removeCallListeners() {
  subscriptions.forEach((subscription) => off(subscription))
}

This page is the sole complete listener owner for these 11 events. Merge participant state using both room and user IDs; do not rely on event order, display names, or array positions. Deduplicate with the room ID, local session ID, and runtime generation so stale events cannot reopen UI. Call removeCallListeners() when the call state layer is destroyed, the user logs out, or the account changes.

HarmonyOS returns a platform-unsupported subscription for onStreamChange and does not fabricate a stream event. The other signaling events on this page are supported. Never log raw payloads or RTC tokens.