Skip to main content

Listen for open channel events

The open channel feature uses a single unified OpenChannelHandler interface for all event types: channel operation status (join, leave, destroy), multi-device sync, member mute/ban notifications, metadata changes, and member change events.

Register and remove the handler

Use NCEngine.addOpenChannelHandler() to register an OpenChannelHandler and NCEngine.removeOpenChannelHandler() to remove it.

kotlin
NCEngine.addOpenChannelHandler("OPEN_CHANNEL_HANDLER", object : OpenChannelHandler {

// ---- Channel operation events ----

override fun onEntering(event: OpenChannelEnteringEvent) {
// Current user is joining channel: event.channelId
}

override fun onEntered(event: OpenChannelEnteredEvent) {
// Current user successfully joined
// event.channelId, event.response (OpenChannelEnterResponseInfo, may be null)
}

override fun onEnterFailed(event: OpenChannelEnterFailedEvent) {
// Join failed: event.channelId, event.error
}

override fun onExited(event: OpenChannelExitedEvent) {
// Current user left: event.channelId
}

override fun onReset(event: OpenChannelResetEvent) {
// Channel reset (followed by onEntered): event.channelId
}

override fun onChannelDestroyed(event: OpenChannelDestroyedEvent) {
// Channel destroyed: event.channelId, event.type (OpenChannelDestroyType)
}

// ---- Event notifications ----

override fun onNotifyMultiLoginSync(event: OpenChannelNotifyMultiLoginSyncEvent) {
// Multi-device join/leave sync
// event.info.channelId, event.info.status, event.info.reason, event.info.timestamp, event.info.extra
}

override fun onParticipantBanned(event: OpenChannelParticipantBannedEvent) {
// Participant banned or unbanned: event.info (OpenChannelParticipantBannedInfo)
}

override fun onParticipantMuted(event: OpenChannelParticipantMutedEvent) {
// Participant muted or unmuted: event.info (OpenChannelParticipantMutedInfo)
}

// ---- Metadata events ----

override fun onMetadataSynced(event: OpenChannelMetadataSyncedEvent) {
// KV sync complete after joining: event.channelId
}

override fun onMetadataChanged(event: OpenChannelMetadataChangedEvent) {
// KV entries updated or deleted
for (change in event.changeInfo) {
if (change.isDelete) {
// Key deleted: change.key
} else {
// Key updated: change.key = change.value
}
}
}

// ---- Member change events ----

override fun onParticipantChanged(event: OpenChannelParticipantChangedEvent) {
val channelId = event.channelId
val participantCount = event.participantCount
for (action in event.actions) {
// action.userId, action.actionType (OpenChannelParticipantActionType)
}
}
})

// Remove the handler
NCEngine.removeOpenChannelHandler("OPEN_CHANNEL_HANDLER")

OpenChannelEnterResponseInfo properties

When onEntered fires, event.response provides the initial channel state (may be null for legacy callbacks):

PropertyTypeDescription
memberCountIntCurrent participant count
createTimeLongChannel creation timestamp (ms)
joinTimeLongTime the current user joined (ms)
isAllBannedBooleanWhether global mute is enabled for the channel
isCurrentUserBannedBooleanWhether the current user is globally muted
isCurrentChannelBannedBooleanWhether the current user is muted in this channel
isCurrentChannelInWhitelistBooleanWhether the current user is on the mute whitelist

Callback reference

Channel operation events

CallbackEvent typeTrigger
onEnteringOpenChannelEnteringEventJoining is in progress. event.channelId.
onEnteredOpenChannelEnteredEventSuccessfully joined. event.response contains initial channel state.
onEnterFailedOpenChannelEnterFailedEventJoin failed. event.error contains the reason.
onExitedOpenChannelExitedEventLeft voluntarily or kicked. event.channelId.
onResetOpenChannelResetEventChannel reset; onEntered follows immediately.
onChannelDestroyedOpenChannelDestroyedEventOnly fires if the user was online. event.type: MANUAL (Server API) or AUTO (inactive).

Event notifications

CallbackEvent typeTrigger
onNotifyMultiLoginSyncOpenChannelNotifyMultiLoginSyncEventCurrent user joined or left on another device. event.info.status: ENTER/EXIT. event.info.reason: exit reason when EXIT.
onParticipantBannedOpenChannelParticipantBannedEventParticipant banned or unbanned (when needNotify: true in Server API). event.info for details.
onParticipantMutedOpenChannelParticipantMutedEventParticipant muted or unmuted (when needNotify: true in Server API). event.info for details.

OpenChannelParticipantMutedInfo properties

PropertyTypeDescription
channelIdStringChannel ID
muteTypeOpenChannelParticipantMuteTypeMute operation type.
durationTimeLongMute duration in seconds. -1 means permanent.
operateTimeLongOperation timestamp (ms)
userIdListList<String>Affected user IDs

Metadata events

CallbackEvent typeTrigger
onMetadataSyncedOpenChannelMetadataSyncedEventTriggered once on join. event.channelId.
onMetadataChangedOpenChannelMetadataChangedEventKV entries set, updated, or deleted. Iterate event.changeInfo. Each item: channelId, key, value (null when deleted), isDelete.

Member change events

CallbackEvent typeTrigger
onParticipantChangedOpenChannelParticipantChangedEventParticipants joined or left. Event contains channelId, participantCount, and actions. Requires Member change monitoring enabled in the Console.

Multi-device login sync

When the same user is logged in on multiple devices, onNotifyMultiLoginSync fires on other devices when joining or leaving.

OpenChannelNotifyMultiLoginSyncEvent contains an info property with the following fields:

PropertyTypeDescription
channelIdStringOpen channel ID
statusOpenChannelSyncStatusEXIT(0): left. ENTER(1): joined.
reasonOpenChannelExitReason?Exit reason when status == EXIT: EXIT_VOLUNTARILY(1) or KICKED_OUT_BY_OTHER_DEVICE(2).
timestampLongTimestamp (ms)
extraString?Additional info