Skip to main content

Open channel events

Use OpenChannelHandler (Objective-C protocol name: NCOpenChannelHandler) to receive events from open channels. A single unified handler protocol covers all event types: enter/exit lifecycle, metadata changes, member changes, multi-device sync, and mute/ban notifications.

Register the handler via NCEngine with a unique identifier string. The identifier lets you add multiple independent listeners and remove them individually when no longer needed.

swift
import NexconnChatSDK
// Register
NCEngine.addOpenChannelHandler(identifier: "MY_OPEN_CHANNEL_HANDLER", handler: self)
// Remove
NCEngine.removeOpenChannelHandler(forIdentifier: "MY_OPEN_CHANNEL_HANDLER")

Enter and exit events

Adopt the NCOpenChannelHandler protocol and implement the callbacks you need. All methods are optional.

swift
import NexconnChatSDK
final class MyViewController: NSObject, OpenChannelHandler {
// Starting to enter the open channel
func onEntering(_ event: OpenChannelEnteringEvent) {
print("Entering channel: \(event.channelId)")
}

// Successfully entered the open channel
func onEntered(_ event: OpenChannelEnteredEvent) {
// event.response may be nil for legacy callbacks
print("Entered channel: \(event.channelId), members: \(event.response?.memberCount ?? 0)")
}

// Failed to enter the open channel
func onEnterFailed(_ event: OpenChannelEnterFailedEvent) {
print("Failed to enter channel \(event.channelId): \(event.error.localizedDescription)")
}

// Open channel was reset (SDK rejoined after a connection interruption)
func onReset(_ event: OpenChannelResetEvent) {
print("Channel reset: \(event.channelId)")
}

// Successfully exited the open channel
func onExited(_ event: OpenChannelExitedEvent) {
print("Exited channel: \(event.channelId)")
}

// Open channel was destroyed
func onChannelDestroyed(_ event: OpenChannelDestroyedEvent) {
if event.destroyType == .manual {
print("Channel \(event.channelId) was manually destroyed.")
} else {
print("Channel \(event.channelId) was recycled due to inactivity.")
}
}
}

NCOpenChannelEnterResponseInfo properties

When onEntered: fires, event.response provides the initial channel state:

PropertyTypeDescription
memberCountNSIntegerCurrent participant count
createTimeint64_tChannel creation timestamp (ms)
enterTimeint64_tTime the current user entered (ms)
isAllChannelMutedBOOLWhether global mute is enabled for the channel
isCurrentUserMutedBOOLWhether the current user is muted
isCurrentChannelMutedBOOLWhether the channel is muted for the current user
isCurrentChannelInAllowlistBOOLWhether the current user is in the allowlist

Metadata events

onMetadataSynced: fires once when you first enter a channel, after the channel's metadata has been pulled down. onMetadataChanged: fires whenever a key is updated or deleted while you are in the channel.

swift
import NexconnChatSDK
// Initial metadata sync completed on enter
func onMetadataSynced(_ event: OpenChannelMetadataSyncedEvent) {
print("Metadata synced for channel: \(event.channelId)")
}
// Metadata updated or deleted
func onMetadataChanged(_ event: OpenChannelMetadataChangedEvent) {
for change in event.changeInfo {
if change.operationType == .remove {
print("Key deleted in channel \(change.channelId): \(change.key)")
} else {
print("Key updated in channel \(change.channelId): \(change.key) = \(change.value ?? "")")
}
}
}

Member change events

Receive notifications when participants join or leave the channel. To enable this feature, turn on Enable auto messaging for participant events in the Nexconn Console under Chat > Chat settings > Open Channels.

info

When this service is enabled, join/leave events are delivered as messages, which increases total message volume.

swift
import NexconnChatSDK
func onMemberChanged(_ event: OpenChannelMemberChangedEvent) {
for action in event.actions {
if action.action == .enter {
print("Participant joined: \(action.userId)")
} else {
print("Participant left: \(action.userId)")
}
}
print("Current member count: \(event.memberCount)")
}

Multi-device sync events

When the current user joins or exits the same open channel on another device, onNotifyMultiLoginSync: fires on this device.

swift
import NexconnChatSDK
func onNotifyMultiLoginSync(_ event: OpenChannelNotifyMultiLoginSyncEvent) {
if event.info.status == .enter {
print("Joined channel \(event.info.channelId) on another device.")
} else {
print("Left channel \(event.info.channelId) on another device (reason: \(event.info.reason.rawValue)).")
}
}

Ban events

onMemberBanned: fires when users are banned from or unbanned in the channel via the Server API (with needNotify: true).

swift
import NexconnChatSDK
func onMemberBanned(_ event: OpenChannelMemberBannedEvent) {
let info = event.info
// info.channelId — channel ID
// info.banType — NCOpenChannelMemberBanType (.ban or .unban)
// info.userIds — affected user IDs
// info.durationTime — ban duration in minutes; 43200 = one month, -1 = permanent
// info.operateTime — operation timestamp (ms)
print("Ban event in channel \(info.channelId), type: \(info.banType.rawValue), users: \(info.userIds)")
}

Mute events

onMemberMuted: fires when users are muted or unmuted in the channel via the Server API (with needNotify: true).

swift
import NexconnChatSDK
func onMemberMuted(_ event: OpenChannelMemberMutedEvent) {
let info = event.info
// info.channelId — channel ID
// info.muteType — NCOpenChannelMemberMuteType (see table below)
// info.userIds — affected user IDs
// info.durationTime — mute duration in minutes; 43200 = one month, -1 = permanent
// info.operateTime — operation timestamp (ms)
print("Mute event in channel \(info.channelId), type: \(info.muteType.rawValue), users: \(info.userIds)")
}

NCOpenChannelMemberMuteType values

ValueDescription
NCOpenChannelMemberMuteTypeMuteUsersMute specific users
NCOpenChannelMemberMuteTypeUnmuteUsersUnmute specific users
NCOpenChannelMemberMuteTypeMuteAllEnable global mute for all users
NCOpenChannelMemberMuteTypeUnmuteAllDisable global mute for all users
NCOpenChannelMemberMuteTypeAddAllowlistAdd users to the mute allowlist
NCOpenChannelMemberMuteTypeRemoveAllowlistRemove users from the mute allowlist
NCOpenChannelMemberMuteTypeMuteGlobalApply global mute to specific users
NCOpenChannelMemberMuteTypeUnmuteGlobalRemove global mute from specific users

Callback reference

CallbackEvent typeTrigger
onEntering:NCOpenChannelEnteringEventStarting to enter the open channel
onEntered:NCOpenChannelEnteredEventSuccessfully entered; event.response contains initial channel state
onEnterFailed:NCOpenChannelEnterFailedEventFailed to enter; event.error contains the reason
onReset:NCOpenChannelResetEventChannel state was reset after a reconnection
onExited:NCOpenChannelExitedEventSuccessfully exited the channel
onChannelDestroyed:NCOpenChannelDestroyedEventChannel destroyed manually or recycled automatically
onMetadataSynced:NCOpenChannelMetadataSyncedEventInitial metadata pull completed on enter
onMetadataChanged:NCOpenChannelMetadataChangedEventOne or more metadata keys updated or deleted; use event.changeInfo to iterate
onMemberChanged:NCOpenChannelMemberChangedEventParticipant joined or left; use event.actions to iterate
onNotifyMultiLoginSync:NCOpenChannelNotifyMultiLoginSyncEventCurrent user joined or left this channel on another device
onMemberMuted:NCOpenChannelMemberMutedEventParticipants muted or unmuted via Server API
onMemberBanned:NCOpenChannelMemberBannedEventParticipants banned or unbanned via Server API