# 在线状态事件通知 (/zh-CN/realtime-media/rtm/build/state-and-attributes/presence-events) > For AI agents: see the complete documentation index at [llms.txt](/llms.txt). ## 添加事件监听 [#添加事件监听] <_PlatformTabsGroup> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="android" /> 接收 Presence 事件通知,你需要实现事件监听程序,详见[事件监听](/zh-CN/realtime-media/rtm/build/messaging/add-event-listener)。除此之外,你需要在订阅或加入频道时将 `withPresence` 参数设置成 `true`。`PresenceEvent` 数据结构包含以下属性: | 参数 | 描述 | | ----------- | ---- | `type` | Presence 事件类型。详见 [`RtmPresenceEventType`](/zh-CN/api-reference/rtm/android/enumv#presencetype)。 | | `channelType` | 频道类型,可能是 Message Channel 或 Stream Channel。 | | `channelName` | 事件发生的频道名称。 | | `publisher` | 触发此事件的用户 ID。 | | `stateItems` | 用户临时状态信息列表,`REMOTE_STATE_CHANGED` 事件发生时有效。 | | `interval` | Interval 模式下,当前频道在上一个周期内用户加入、离开、超时、状态变更等事件通知的聚合增量信息。 | | `snapshot` | 快照详情。用户首次加入或订阅频道触发了 `SNAPSHOT` 事件时有效。 | | `timestamp` | 事件触发时间戳。 | <_PlatformProcessedMarker close="true" /> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="ios" /> 接收 Presence 事件通知,你需要实现事件监听程序,详见[事件监听](/zh-CN/realtime-media/rtm/build/messaging/add-event-listener)。除此之外,在订阅或加入频道时还需将 `features` 参数设为 `AgoraRtmJoinChannelFeaturePresence` 或 `AgoraRtmSubscribeChannelFeaturePresence`。`AgoraRtmPresenceEvent` 数据结构包含以下属性: | 参数 | 描述 | | ----------- | ---- | `type` | Presence 事件类型。详见 [`AgoraRtmPresenceEventType`](/zh-CN/api-reference/rtm/ios/enumv#presencetype)。 | | `channelType` | 频道类型,可能是 Message Channel 或 Stream Channel。 | | `channelName` | 事件发生的频道名称。 | | `publisher` | 触发此事件的用户 ID。 | | `states` | 用户临时状态信息列表,`AgoraRtmPresenceEventTypeRemoteStateChanged` 事件发生时有效。 | | `interval` | Interval 模式下,当前频道在上一个周期内用户加入、离开、超时、状态变更等事件通知的聚合增量信息。 | | `snapshot` | 快照详情。用户首次加入或订阅频道触发了 `AgoraRtmPresenceEventTypeSnapshot` 事件时有效。 | | `timestamp` | 事件触发时间戳。 | <_PlatformProcessedMarker close="true" /> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="web" /> 接收 Presence 事件通知,你需要实现事件监听程序,详见[事件监听](/zh-CN/realtime-media/rtm/build/messaging/add-event-listener)。除此之外,你需要在订阅或加入频道时将 `withPresence` 参数设置成 `true`。`PresenceEvent` 数据结构包含以下属性: | 参数 | 描述 | | ----------- | -------------- | | `eventType` | Presence 事件类型。详见 [API 参考](/zh-CN/api-reference/rtm/web/enumv#presence-事件类型)。 | | `channelType` | 频道类型,可能是 Message Channel 或 Stream Channel。 | | `channelName` | 事件发生的频道名称。 | | `publisher` | 触发此事件的用户 ID。 | | `states` | 用户临时状态信息列表,`REMOTE_STATE_CHANGED` 事件发生时有效。 | | `interval` | Interval 模式下,当前频道在上一个周期内用户加入、离开、超时、状态变更等事件通知的聚合增量信息。 | | `snapshot` | 快照详情。用户首次加入或订阅频道触发了 `SNAPSHOT` 事件时有效。 | <_PlatformProcessedMarker close="true" /> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="harmonyos" /> 接收 Presence 事件通知,你需要实现事件监听程序,详见[事件监听](/zh-CN/realtime-media/rtm/build/messaging/add-event-listener)。除此之外,你需要在订阅或加入频道时将 `withPresence` 参数设置成 `true`。[`PresenceEvent`](/zh-CN/api-reference/rtm/harmonyos/configuration#presenceevent) 数据结构包含以下属性: <_PlatformProcessedMarker close="true" /> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="unity" /> 接收 Presence 事件通知,你需要实现事件监听程序,详见[事件监听](/zh-CN/realtime-media/rtm/build/messaging/add-event-listener)。除此之外,你需要在订阅或加入频道时将 `withPresence` 参数设置成 `true`。`PresenceEvent` 数据结构包含以下属性: | 参数 | 描述 | | ----------- | -------------- | | `type` | Presence 事件类型。详见 [`RTM_PRESENCE_EVENT_TYPE`](/zh-CN/api-reference/rtm/unity/enumv#presencetype)。 | | `channelType` | 频道类型,可能是 Message Channel 或 Stream Channel。 | | `channelName` | 事件发生的频道名称。 | | `publisher` | 触发此事件的用户 ID。 | | `stateItems` | 用户临时状态信息列表,`REMOTE_STATE_CHANGED` 事件发生时有效。 | | `interval` | Interval 模式下,当前频道在上一个周期内用户加入、离开、超时、状态变更等事件通知的聚合增量信息。 | | `snapshot` | 快照详情。用户首次加入或订阅频道触发了 `SNAPSHOT` 事件时有效。 | <_PlatformProcessedMarker close="true" /> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="flutter" /> 接收 Presence 事件通知,你需要实现事件监听程序,详见[事件监听](/zh-CN/realtime-media/rtm/build/messaging/add-event-listener)。除此之外,你需要在订阅或加入频道时将 `withPresence` 参数设置成 `true`。`PresenceEvent` 数据结构包含以下属性: | 参数 | 描述 | | ----------- | ---- | `type` | Presence 事件类型。详见 [`RtmPresenceEventType`](/zh-CN/api-reference/rtm/flutter/enumv#presencetype)。 | | `channelType` | 频道类型,可能是 Message Channel 或 Stream Channel。 | | `channelName` | 事件发生的频道名称。 | | `publisher` | 触发此事件的用户 ID。 | | `stateItems` | 用户临时状态信息列表,`remoteStateChanged` 事件发生时有效。 | | `interval` | Interval 模式下,当前频道在上一个周期内用户加入、离开、超时、状态变更等事件通知的聚合增量信息。 | | `snapshot` | 快照详情。用户首次加入或订阅频道触发了 `snapshot` 事件时有效。 | | `timestamp` | 事件触发时间戳。 | <_PlatformProcessedMarker close="true" /> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="cpp" /> 接收 Presence 事件通知,你需要实现事件监听程序,详见[事件监听](/zh-CN/realtime-media/rtm/build/messaging/add-event-listener)。除此之外,你需要在订阅或加入频道时将 `withPresence` 参数设置成 `true`。`PresenceEvent` 数据结构包含以下属性: | 参数 | 描述 | | ----------- | ---- | `type` | Presence 事件类型。详见 [`RTM_PRESENCE_EVENT_TYPE`](/zh-CN/api-reference/rtm/cpp/enumv#presencetype)。 | | `channelType` | 频道类型,可能是 Message Channel 或 Stream Channel。 | | `channelName` | 事件发生的频道名称。 | | `publisher` | 触发此事件的用户 ID。 | | `stateItems` | 用户临时状态信息列表,`RTM_PRESENCE_EVENT_TYPE_REMOTE_STATE_CHANGED` 事件发生时有效。 | | `interval` | Interval 模式下,当前频道在上一个周期内用户加入、离开、超时、状态变更等事件通知的聚合增量信息。 | | `snapshot` | 快照详情。用户首次加入或订阅频道触发了 `RTM_PRESENCE_EVENT_TYPE_SNAPSHOT` 事件时有效。 | | `timestamp` | 事件触发时间戳。 | <_PlatformProcessedMarker close="true" /> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="swift" /> 接收 Presence 事件通知,你需要实现事件监听程序,详见[事件监听](/zh-CN/realtime-media/rtm/build/messaging/add-event-listener)。除此之外,在订阅或加入频道时还需将 `features` 参数设为 `presence` 或 `presence`。`AgoraRtmPresenceEvent` 数据结构包含以下属性: | 参数 | 描述 | | ----------- | ---- | `type` | Presence 事件类型。详见 [`AgoraRtmPresenceEventType`](/zh-CN/api-reference/rtm/swift/enumv#presencetype)。 | | `channelType` | 频道类型,可能是 Message Channel 或 Stream Channel。 | | `channelName` | 事件发生的频道名称。 | | `publisher` | 触发此事件的用户 ID。 | | `states` | 用户临时状态信息列表,`remoteStateChanged` 事件发生时有效。 | | `interval` | Interval 模式下,当前频道在上一个周期内用户加入、离开、超时、状态变更等事件通知的聚合增量信息。 | | `snapshot` | 快照详情。用户首次加入或订阅频道触发了 `snapshot` 事件时有效。 | | `timestamp` | 事件触发时间戳。 | <_PlatformProcessedMarker close="true" /> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="mini-program" /> 接收 Presence 事件通知,你需要实现事件监听程序,详见[事件监听](/zh-CN/realtime-media/rtm/build/messaging/add-event-listener)。除此之外,你需要在订阅或加入频道时将 `withPresence` 参数设置成 `true`。`PresenceEvent` 数据结构包含以下属性: | 参数 | 描述 | | ----------- | -------------- | | `eventType` | Presence 事件类型。详见 [API 参考](/zh-CN/api-reference/rtm/web/enumv#presence-事件类型)。 | | `channelType` | 频道类型,可能是 Message Channel 或 Stream Channel。 | | `channelName` | 事件发生的频道名称。 | | `publisher` | 触发此事件的用户 ID。 | | `states` | 用户临时状态信息列表,`REMOTE_STATE_CHANGED` 事件发生时有效。 | | `interval` | Interval 模式下,当前频道在上一个周期内用户加入、离开、超时、状态变更等事件通知的聚合增量信息。 | | `snapshot` | 快照详情。用户首次加入或订阅频道触发了 `SNAPSHOT` 事件时有效。 | <_PlatformProcessedMarker close="true" /> ## 事件通知类型 [#事件通知类型] Presence 事件通知有七种类型,它们分别是: <_PlatformTabsGroup> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="android" /> | 枚举值 | 描述 | | ------- | ----------------- | | `SNAPSHOT` | `1`: 用户第一次订阅或加入频道时触发,本地用户会收到此类事件通知。 | | `INTERVAL` | `2`: 当频道内人数达到设定值后,频道内的事件通知将由实时通知转为定时通知。 | | `REMOTE_JOIN` | `3`: 当用户订阅或加入频道时触发,频道中的其他人会收到此类通知。 | | `REMOTE_LEAVE` | `4`: 当用户取消订阅或离开频道时触发,频道中的其他人会收到此类通知。 | | `REMOTE_TIMEOUT` | `5`: 当用户掉线超时时触发,频道中的其他人会收到此类通知。 | | `REMOTE_STATE_CHANGED` | `6`: 当用户临时状态数据发生变更时触发,频道中的其他人会收到此类通知。 | | `ERROR_OUT_OF_SERVICE` | `7`: 用户加入频道时未启用 Presence,本地用户会收到此类事件通知。 | <_PlatformProcessedMarker close="true" /> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="ios" /> | 枚举值 | 描述 | | ------- | ----------------- | | `AgoraRtmPresenceEventTypeSnapshot` | `1`: 用户第一次订阅或加入频道时触发,本地用户会收到此类事件通知。 | | `AgoraRtmPresenceEventTypeInterval` | `2`: 当频道内人数达到设定值后,频道内的事件通知将由实时通知转为定时通知。 | | `AgoraRtmPresenceEventTypeRemoteJoinChannel` | `3`: 当用户订阅或加入频道时触发,频道中的其他人会收到此类通知。 | | `AgoraRtmPresenceEventTypeRemoteLeaveChannel` | `4`: 当用户取消订阅或离开频道时触发,频道中的其他人会收到此类通知。 | | `AgoraRtmPresenceEventTypeRemoteConnectionTimeout` | `5`: 当用户掉线超时时触发,频道中的其他人会收到此类通知。 | | `AgoraRtmPresenceEventTypeRemoteStateChanged` | `6`: 当用户临时状态数据发生变更时触发,频道中的其他人会收到此类通知。 | | `AgoraRtmPresenceEventTypeErrorOutOfService` | `7`: 用户加入频道时未启用 Presence,本地用户会收到此类事件通知。 | <_PlatformProcessedMarker close="true" /> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="web" /> | 枚举值 | 描述 | | ------- | ----------------- | | `SNAPSHOT` | `1`: 用户第一次订阅或加入频道时触发,本地用户会收到此类事件通知。 | | `INTERVAL` | `2`: 当频道内人数达到设定值后,频道内的事件通知将由实时通知转为定时通知。 | | `REMOTE_JOIN` | `3`: 当用户订阅或加入频道时触发,频道中的其他人会收到此类通知。 | | `REMOTE_LEAVE` | `4`: 当用户取消订阅或离开频道时触发,频道中的其他人会收到此类通知。 | | `REMOTE_TIMEOUT` | `5`: 当用户掉线超时时触发,频道中的其他人会收到此类通知。 | | `REMOTE_STATE_CHANGED` | `6`: 当用户临时状态数据发生变更时触发,频道中的其他人会收到此类通知。 | | `ERROR_OUT_OF_SERVICE` | `7`: 用户加入频道时未启用 Presence,本地用户会收到此类事件通知。 | <_PlatformProcessedMarker close="true" /> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="harmonyos" /> <_PlatformProcessedMarker close="true" /> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="unity" /> | 枚举值 | 描述 | | ------- | ----------------- | | `SNAPSHOT` | `1`: 用户第一次订阅或加入频道时触发,本地用户会收到此类事件通知。 | | `INTERVAL` | `2`: 当频道内人数达到设定值后,频道内的事件通知将由实时通知转为定时通知。 | | `REMOTE_JOIN` | `3`: 当用户订阅或加入频道时触发,频道中的其他人会收到此类通知。 | | `REMOTE_LEAVE` | `4`: 当用户取消订阅或离开频道时触发,频道中的其他人会收到此类通知。 | | `REMOTE_TIMEOUT` | `5`: 当用户掉线超时时触发,频道中的其他人会收到此类通知。 | | `REMOTE_STATE_CHANGED` | `6`: 当用户临时状态数据发生变更时触发,频道中的其他人会收到此类通知。 | | `ERROR_OUT_OF_SERVICE` | `7`: 用户加入频道时未启用 Presence,本地用户会收到此类事件通知。 | <_PlatformProcessedMarker close="true" /> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="flutter" /> | 枚举值 | 描述 | | ------- | ----------------- | | `snapshot` | `1`: 用户第一次订阅或加入频道时触发,本地用户会收到此类事件通知。 | | `interval` | `2`: 当频道内人数达到设定值后,频道内的事件通知将由实时通知转为定时通知。 | | `remoteJoinChannel` | `3`: 当用户订阅或加入频道时触发,频道中的其他人会收到此类通知。 | | `remoteLeaveChannel` | `4`: 当用户取消订阅或离开频道时触发,频道中的其他人会收到此类通知。 | | `remoteTimeout` | `5`: 当用户掉线超时时触发,频道中的其他人会收到此类通知。 | | `remoteStateChanged` | `6`: 当用户临时状态数据发生变更时触发,频道中的其他人会收到此类通知。 | | `errorOutOfService` | `7`: 用户加入频道时未启用 Presence,本地用户会收到此类事件通知。 | <_PlatformProcessedMarker close="true" /> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="cpp" /> | 枚举值 | 描述 | | ------- | ----------------- | | `RTM_PRESENCE_EVENT_TYPE_SNAPSHOT` | `1`: 用户第一次订阅或加入频道时触发,本地用户会收到此类事件通知。 | | `RTM_PRESENCE_EVENT_TYPE_INTERVAL` | `2`: 当频道内人数达到设定值后,频道内的事件通知将由实时通知转为定时通知。 | | `RTM_PRESENCE_EVENT_TYPE_REMOTE_JOIN_CHANNEL` | `3`: 当用户订阅或加入频道时触发,频道中的其他人会收到此类通知。 | | `RTM_PRESENCE_EVENT_TYPE_REMOTE_LEAVE_CHANNEL` | `4`: 当用户取消订阅或离开频道时触发,频道中的其他人会收到此类通知。 | | `RTM_PRESENCE_EVENT_TYPE_REMOTE_TIMEOUT` | `5`: 当用户掉线超时时触发,频道中的其他人会收到此类通知。 | | `RTM_PRESENCE_EVENT_TYPE_REMOTE_STATE_CHANGED` | `6`: 当用户临时状态数据发生变更时触发,频道中的其他人会收到此类通知。 | | `RTM_PRESENCE_EVENT_TYPE_ERROR_OUT_OF_SERVICE` | `7`: 用户加入频道时未启用 Presence,本地用户会收到此类事件通知。 | <_PlatformProcessedMarker close="true" /> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="swift" /> | 枚举值 | 描述 | | ------- | ----------------- | | `snapshot` | `1`: 用户第一次订阅或加入频道时触发,本地用户会收到此类事件通知。 | | `interval` | `2`: 当频道内人数达到设定值后,频道内的事件通知将由实时通知转为定时通知。 | | `remoteJoinChannel` | `3`: 当用户订阅或加入频道时触发,频道中的其他人会收到此类通知。 | | `remoteLeaveChannel` | `4`: 当用户取消订阅或离开频道时触发,频道中的其他人会收到此类通知。 | | `remoteConnectionTimeout` | `5`: 当用户掉线超时时触发,频道中的其他人会收到此类通知。 | | `remoteStateChanged` | `6`: 当用户临时状态数据发生变更时触发,频道中的其他人会收到此类通知。 | | `errorOutOfService` | `7`: 用户加入频道时未启用 Presence,本地用户会收到此类事件通知。 | <_PlatformProcessedMarker close="true" /> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="mini-program" /> | 枚举值 | 描述 | | ------- | ----------------- | | `SNAPSHOT` | `1`: 用户第一次订阅或加入频道时触发,本地用户会收到此类事件通知。 | | `INTERVAL` | `2`: 当频道内人数达到设定值后,频道内的事件通知将由实时通知转为定时通知。 | | `REMOTE_JOIN` | `3`: 当用户订阅或加入频道时触发,频道中的其他人会收到此类通知。 | | `REMOTE_LEAVE` | `4`: 当用户取消订阅或离开频道时触发,频道中的其他人会收到此类通知。 | | `REMOTE_TIMEOUT` | `5`: 当用户掉线超时时触发,频道中的其他人会收到此类通知。 | | `REMOTE_STATE_CHANGED` | `6`: 当用户临时状态数据发生变更时触发,频道中的其他人会收到此类通知。 | | `ERROR_OUT_OF_SERVICE` | `7`: 用户加入频道时未启用 Presence,本地用户会收到此类事件通知。 | <_PlatformProcessedMarker close="true" /> ## 事件通知模式 [#事件通知模式] <_PlatformTabsGroup> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="android" /> Presence 事件通知模式是指在频道中如何将 Presence 事件通知到订阅用户。有两种模式:**实时通知模式(Announce)** 和 **定时通知模式(Interval)**。 用户可以在控制台的项目设置中通过**实时通知最大人数**大小来决定两种模式相互切换的条件。定时通知模式可防止频道内在线用户过多而导致的事件嘈杂。实时通知最大人数可以设置的范围为 [8,128],如果你的需求超出此范围,需要联系声网 RTM 团队(rtm-support@shengwang.cn)另行调整。 从 v2.3.0 起,RTM 在现有事件通知模式基础上增加大频道优化策略,默认阈值为 512 人: - 当频道在线人数不超过 512 人时,Presence 沿用现有事件通知行为。 - 当频道在线人数超过 512 人时,SDK 会自动采用大频道优化策略,无需应用开启、关闭或监听模式切换状态。 - 在大频道优化模式下,客户端持续同步的成员明细最多包含 512 名成员;其他成员的加入、离开、超时和状态变化主要合并为频道总人数变化。 - 应用可以通过既有的 `INTERVAL` 事件接收聚合后的成员变化,并通过 `interval.totalOccupancy` 获取频道总在线人数。 - 当频道人数回落后,SDK 会自动恢复原有成员同步方式,应用无需管理切换逻辑。 `interval.totalOccupancy` 表示当前频道的总在线人数。在大频道优化模式下,该值表示频道内所有在线用户的数量,不受最多同步 512 名用户明细的限制;但该值可能有短暂延迟。 <_PlatformProcessedMarker close="true" /> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="ios" /> Presence 事件通知模式是指在频道中如何将 Presence 事件通知到订阅用户。有两种模式:**实时通知模式(Announce)** 和 **定时通知模式(Interval)**。 用户可以在控制台的项目设置中通过**实时通知最大人数**大小来决定两种模式相互切换的条件。定时通知模式可防止频道内在线用户过多而导致的事件嘈杂。实时通知最大人数可以设置的范围为 [8,128],如果你的需求超出此范围,需要联系声网 RTM 团队(rtm-support@shengwang.cn)另行调整。 从 v2.3.0 起,RTM 在现有事件通知模式基础上增加大频道优化策略,默认阈值为 512 人: - 当频道在线人数不超过 512 人时,Presence 沿用现有事件通知行为。 - 当频道在线人数超过 512 人时,SDK 会自动采用大频道优化策略,无需应用开启、关闭或监听模式切换状态。 - 在大频道优化模式下,客户端持续同步的成员明细最多包含 512 名成员;其他成员的加入、离开、超时和状态变化主要合并为频道总人数变化。 - 应用可以通过既有的 `AgoraRtmPresenceEventTypeInterval` 事件接收聚合后的成员变化,并通过 `interval.totalOccupancy` 获取频道总在线人数。 - 当频道人数回落后,SDK 会自动恢复原有成员同步方式,应用无需管理切换逻辑。 `interval.totalOccupancy` 表示当前频道的总在线人数。在大频道优化模式下,该值表示频道内所有在线用户的数量,不受最多同步 512 名用户明细的限制;但该值可能有短暂延迟。 <_PlatformProcessedMarker close="true" /> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="web" /> Presence 事件通知模式是指在频道中如何将 Presence 事件通知到订阅用户。有两种模式:**实时通知模式(Announce)** 和 **定时通知模式(Interval)**。 用户可以在控制台的项目设置中通过**实时通知最大人数**大小来决定两种模式相互切换的条件。定时通知模式可防止频道内在线用户过多而导致的事件嘈杂。实时通知最大人数可以设置的范围为 [8,128],如果你的需求超出此范围,需要联系声网 RTM 团队(rtm-support@shengwang.cn)另行调整。 从 v2.3.0 起,RTM 在现有事件通知模式基础上增加大频道优化策略,默认阈值为 512 人: - 当频道在线人数不超过 512 人时,Presence 沿用现有事件通知行为。 - 当频道在线人数超过 512 人时,SDK 会自动采用大频道优化策略,无需应用开启、关闭或监听模式切换状态。 - 在大频道优化模式下,客户端持续同步的成员明细最多包含 512 名成员;其他成员的加入、离开、超时和状态变化主要合并为频道总人数变化。 - 应用可以通过既有的 `INTERVAL` 事件接收聚合后的成员变化,并通过 `interval.totalOccupancy` 获取频道总在线人数。 - 当频道人数回落后,SDK 会自动恢复原有成员同步方式,应用无需管理切换逻辑。 `interval.totalOccupancy` 表示当前频道的总在线人数。在大频道优化模式下,该值表示频道内所有在线用户的数量,不受最多同步 512 名用户明细的限制;但该值可能有短暂延迟。 <_PlatformProcessedMarker close="true" /> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="harmonyos" /> Presence 事件通知模式是指在频道中如何将 Presence 事件通知到订阅用户。有两种模式:**实时通知模式(Announce)** 和 **定时通知模式(Interval)**。 用户可以在控制台的项目设置中通过**实时通知最大人数**大小来决定两种模式相互切换的条件。定时通知模式可防止频道内在线用户过多而导致的事件嘈杂。实时通知最大人数可以设置的范围为 [8,128],如果你的需求超出此范围,需要联系声网 RTM 团队(rtm-support@shengwang.cn)另行调整。 从 v2.3.0 起,RTM 在现有事件通知模式基础上增加大频道优化策略,默认阈值为 512 人: - 当频道在线人数不超过 512 人时,Presence 沿用现有事件通知行为。 - 当频道在线人数超过 512 人时,SDK 会自动采用大频道优化策略,无需应用开启、关闭或监听模式切换状态。 - 在大频道优化模式下,客户端持续同步的成员明细最多包含 512 名成员;其他成员的加入、离开、超时和状态变化主要合并为频道总人数变化。 - 应用可以通过既有的 `INTERVAL` 事件接收聚合后的成员变化,并通过 `interval.totalOccupancy` 获取频道总在线人数。 - 当频道人数回落后,SDK 会自动恢复原有成员同步方式,应用无需管理切换逻辑。 `interval.totalOccupancy` 表示当前频道的总在线人数。在大频道优化模式下,该值表示频道内所有在线用户的数量,不受最多同步 512 名用户明细的限制;但该值可能有短暂延迟。 <_PlatformProcessedMarker close="true" /> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="unity" /> <_PlatformProcessedMarker close="true" /> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="flutter" /> <_PlatformProcessedMarker close="true" /> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="cpp" /> Presence 事件通知模式是指在频道中如何将 Presence 事件通知到订阅用户。有两种模式:**实时通知模式(Announce)** 和 **定时通知模式(Interval)**。 用户可以在控制台的项目设置中通过**实时通知最大人数**大小来决定两种模式相互切换的条件。定时通知模式可防止频道内在线用户过多而导致的事件嘈杂。实时通知最大人数可以设置的范围为 [8,128],如果你的需求超出此范围,需要联系声网 RTM 团队(rtm-support@shengwang.cn)另行调整。 从 v2.3.0 起,RTM 在现有事件通知模式基础上增加大频道优化策略,默认阈值为 512 人: - 当频道在线人数不超过 512 人时,Presence 沿用现有事件通知行为。 - 当频道在线人数超过 512 人时,SDK 会自动采用大频道优化策略,无需应用开启、关闭或监听模式切换状态。 - 在大频道优化模式下,客户端持续同步的成员明细最多包含 512 名成员;其他成员的加入、离开、超时和状态变化主要合并为频道总人数变化。 - 应用可以通过既有的 `RTM_PRESENCE_EVENT_TYPE_INTERVAL` 事件接收聚合后的成员变化,并通过 `interval.totalOccupancy` 获取频道总在线人数。 - 当频道人数回落后,SDK 会自动恢复原有成员同步方式,应用无需管理切换逻辑。 `interval.totalOccupancy` 表示当前频道的总在线人数。在大频道优化模式下,该值表示频道内所有在线用户的数量,不受最多同步 512 名用户明细的限制;但该值可能有短暂延迟。 <_PlatformProcessedMarker close="true" /> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="swift" /> Presence 事件通知模式是指在频道中如何将 Presence 事件通知到订阅用户。有两种模式:**实时通知模式(Announce)** 和 **定时通知模式(Interval)**。 用户可以在控制台的项目设置中通过**实时通知最大人数**大小来决定两种模式相互切换的条件。定时通知模式可防止频道内在线用户过多而导致的事件嘈杂。实时通知最大人数可以设置的范围为 [8,128],如果你的需求超出此范围,需要联系声网 RTM 团队(rtm-support@shengwang.cn)另行调整。 从 v2.3.0 起,RTM 在现有事件通知模式基础上增加大频道优化策略,默认阈值为 512 人: - 当频道在线人数不超过 512 人时,Presence 沿用现有事件通知行为。 - 当频道在线人数超过 512 人时,SDK 会自动采用大频道优化策略,无需应用开启、关闭或监听模式切换状态。 - 在大频道优化模式下,客户端持续同步的成员明细最多包含 512 名成员;其他成员的加入、离开、超时和状态变化主要合并为频道总人数变化。 - 应用可以通过既有的 `interval` 事件接收聚合后的成员变化,并通过 `interval.totalOccupancy` 获取频道总在线人数。 - 当频道人数回落后,SDK 会自动恢复原有成员同步方式,应用无需管理切换逻辑。 `interval.totalOccupancy` 表示当前频道的总在线人数。在大频道优化模式下,该值表示频道内所有在线用户的数量,不受最多同步 512 名用户明细的限制;但该值可能有短暂延迟。 <_PlatformProcessedMarker close="true" /> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="mini-program" /> Presence 事件通知模式是指在频道中如何将 Presence 事件通知到订阅用户。有两种模式:**实时通知模式(Announce)** 和 **定时通知模式(Interval)**。用户可以在控制台的项目设置中通过**实时通知最大人数**大小来决定两种模式相互切换的条件。定时通知模式可防止频道内在线用户过多而导致的事件嘈杂。实时通知最大人数可以设置的范围为 [8,128],如果你的需求超出此范围,需要联系声网 RTM 团队(rtm-support@shengwang.cn)另行调整。 <_PlatformProcessedMarker close="true" /> ### 实时通知模式 [#实时通知模式] <_PlatformTabsGroup> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="android" /> 如果频道中的在线人数小于实时通知最大人数参数设定的值(默认值为 50),则 Presence 事件通知处于实时通知模式。在此模式下,`REMOTE_JOIN`、`REMOTE_LEAVE`、`REMOTE_TIMEOUT`、`REMOTE_STATE_CHANGED` 事件在触发时会立即发送到客户端。 ```java tab="Join" { eventType: RtmPresenceEventType.REMOTE_JOIN; channelType: RtmChannelType.MESSAGE; channelName: "test_channel"; publisher: "publisher_name"; stateItems: {}; interval: { joinUserList:[], leaveUserList:[], timeoutUserList:[], userStateList:[], }; snapshot: { userStateList:[] }; timestamp: 1710487149497; } ``` ```java tab="Leave" { eventType: RtmPresenceEventType.REMOTE_LEAVE; channelType: RtmChannelType.MESSAGE; channelName: "test_channel"; publisher: "publisher_name"; stateItems: {}; interval: { joinUserList:[], leaveUserList:[], timeoutUserList:[], userStateList:[], }; snapshot: { userStateList:[] }; timestamp: 1710487149497; } ``` ```java tab="Timeout" { eventType: RtmPresenceEventType.REMOTE_TIMEOUT; channelType: RtmChannelType.MESSAGE; channelName: "test_channel"; publisher: "publisher_name"; stateItems: {}; interval: { joinUserList:[], leaveUserList:[], timeoutUserList:[], userStateList:[], }; snapshot: { userStateList:[] }; timestamp: 1710487149497; } ``` ```java tab="Snapshot" { eventType: RtmPresenceEventType.SNAPSHOT; channelType: RtmChannelType.MESSAGE; channelName: "test_channel"; publisher: ""; stateItems: {}; interval: { joinUserList:[], leaveUserList:[], timeoutUserList:[], userStateList:[], }; snapshot: { userStateList:[ { userId: "user_a", states: {} }, { userId: "user_b", states: { key: "key_1"; value: "value_1"; } }, { userId: "yourSelf", states: {} }, ] }; timestamp: 1710487149497; } ``` ```java tab="State Change" { eventType: RtmPresenceEventType.REMOTE_STATE_CHANGED; channelType: RtmChannelType.MESSAGE; channelName: "test_channel"; publisher: "publisher_name"; stateItems: { "key_1":"value_1"; }; interval: { joinUserList:[], leaveUserList:[], timeoutUserList:[], userStateList:[], }; snapshot: { userStateList:[] }; timestamp: 1710487149497; } ``` <_PlatformProcessedMarker close="true" /> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="ios" /> 如果频道中的在线人数小于实时通知最大人数参数设定的值(默认值为 50),则 Presence 事件通知处于实时通知模式。在此模式下,`AgoraRtmPresenceEventTypeRemoteJoinChannel`、`AgoraRtmPresenceEventTypeRemoteLeaveChannel`、`AgoraRtmPresenceEventTypeRemoteConnectionTimeout`、`AgoraRtmPresenceEventTypeRemoteStateChanged` 事件在触发时会立即发送到客户端。 ```objc tab="Join" { type: AgoraRtmPresenceEventTypeRemoteJoinChannel; channelType: AgoraRtmChannelTypeMessage; channelName: "test_channel"; publisher: "publisher_name"; states: []; interval: []; snapshot: []; timestamp: 1710487149497; } ``` ```objc tab="Leave" { eventType: AgoraRtmPresenceEventTypeRemoteLeaveChannel; channelType: AgoraRtmChannelTypeMessage; channelName: "test_channel"; publisher: "publisher_name"; stateChanged: []; interval: []; snapshot: []; timestamp: 1710487149497; } ``` ```objc tab="Timeout" { eventType: AgoraRtmPresenceEventTypeRemoteConnectionTimeout; channelType: AgoraRtmChannelTypeMessage; channelName: "test_channel"; publisher: "publisher_name"; stateChanged: []; interval: []; snapshot: []; timestamp: 1710487149497; } ``` ```objc tab="Snapshot" { eventType: AgoraRtmPresenceEventTypeSnapshot; channelType: AgoraRtmChannelTypeMessage; channelName: "test_channel"; publisher: ""; stateChanged: []; interval: []; snapshot: [ { userId: "user_a", states: {}}, { userId: "user_b", states: { key_1: "value_1" }}, { userId: "yourSelf", states: {}}, ]; timestamp: 1710487149497; } ``` ```objc tab="State Change" { eventType: AgoraRtmPresenceEventTypeRemoteStateChanged; channelType: AgoraRtmChannelTypeMessage; channelName: "test_channel"; publisher: "publisher_name"; states: { "key_1": "value_1", }; interval: []; snapshot: []; timestamp: 1710487149497; } ``` <_PlatformProcessedMarker close="true" /> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="web" /> 如果频道中的在线人数小于实时通知最大人数参数设定的值(默认值为 50),则 Presence 事件通知处于实时通知模式。在此模式下,`REMOTE_JOIN`、`REMOTE_LEAVE`、`REMOTE_TIMEOUT`、`REMOTE_STATE_CHANGED` 事件在触发时会立即发送到客户端。 ```javascript tab="Join" { eventType: "REMOTE_JOIN"; channelType: "MESSAGE"; channelName: "test_channel"; publisher: "publisher_name"; stateChanged: {}; interval: null; snapshot: null; } ``` ```javascript tab="Leave" { eventType: "REMOTE_LEAVE"; channelType: "MESSAGE"; channelName: "test_channel"; publisher: "publisher_name"; stateChanged: {}; interval: null; snapshot: null; } ``` ```javascript tab="Timeout" { eventType: "REMOTE_TIMEOUT"; channelType: "MESSAGE"; channelName: "test_channel"; publisher: "publisher_name"; stateChanged: {}; interval: null; snapshot: null; } ``` ```javascript tab="Snapshot" { eventType: "SNAPSHOT"; channelType: "MESSAGE"; channelName: "test_channel"; publisher: ""; stateChanged: {}; interval: null; snapshot: [ { userId: "user_a", states: {}, statesCount: 0 }, { userId: "user_b", states: { key_1: "value_1" }, statesCount: 1 }, { userId: "yourSelf", states: {}, statesCount: 0 }, ]; } ``` ```javascript tab="State Change" { eventType: "REMOTE_STATE_CHANGED"; channelType: "MESSAGE"; channelName: "test_channel"; publisher: "publisher_name"; stateChanged: { "key_1": "value_1", }; interval: null; snapshot: null; } ``` <_PlatformProcessedMarker close="true" /> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="harmonyos" /> 如果频道中的在线人数小于实时通知最大人数参数设定的值(默认值为 50),则 Presence 事件通知处于实时通知模式。在此模式下,`REMOTE_JOIN_CHANNEL`、`REMOTE_LEAVE_CHANNEL`、`REMOTE_TIMEOUT`、`REMOTE_STATE_CHANGED` 事件在触发时会立即发送到客户端。 ```typescript tab="Join" { eventType: RtmPresenceEventType.REMOTE_JOIN_CHANNEL, channelType: RtmChannelType.MESSAGE, channelName: "chat_room", publisher: "Tony", stateChanged: [], interval: null, snapshot: null, timestamp: 1710487149497 } ``` ```typescript tab="Leave" { eventType: RtmPresenceEventType.REMOTE_LEAVE_CHANNEL, channelType: RtmChannelType.MESSAGE, channelName: "chat_room", publisher: "Tony", stateChanged: [], interval: null, snapshot: null, timestamp: 1710487149497 } ``` ```typescript tab="Timeout" { eventType: RtmPresenceEventType.REMOTE_TIMEOUT, channelType: RtmChannelType.MESSAGE, channelName: "chat_room", publisher: "Tony", stateChanged: [], interval: null, snapshot: null, timestamp: 1710487149497 } ``` ```typescript tab="Snapshot" { eventType: RtmPresenceEventType.SNAPSHOT, channelType: RtmChannelType.MESSAGE, channelName: "chat_room", publisher: "", stateChanged: [], interval: null, snapshot: [ { userId: "user_a", states: [] }, { userId: "user_b", states: [{ key: "key_1", value: "value_1" }] }, { userId: "yourSelf", states: [] } ], timestamp: 1710487149497 } ``` ```typescript tab="State Change" { eventType: RtmPresenceEventType.REMOTE_STATE_CHANGED, channelType: RtmChannelType.MESSAGE, channelName: "chat_room", publisher: "Tony", stateChanged: [ { key: "key_1", value: "value_1" } ], interval: null, snapshot: null, timestamp: 1710487149497 } ``` <_PlatformProcessedMarker close="true" /> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="unity" /> 如果频道中的在线人数小于实时通知最大人数参数设定的值(默认值为 50),则 Presence 事件通知处于实时通知模式。在此模式下,`REMOTE_JOIN`、`REMOTE_LEAVE`、`REMOTE_TIMEOUT`、`REMOTE_STATE_CHANGED` 事件在触发时会立即发送到客户端。 ```csharp tab="Join" { "type" : RTM_PRESENCE_EVENT_TYPE.REMOTE_JOIN, "channelType" : RTM_CHANNEL_TYPE.MESSAGE, "channelName" : "Chat_room", "publisher" : "Tony", } ``` ```csharp tab="Leave" { "type" : RTM_PRESENCE_EVENT_TYPE.REMOTE_LEAVE, "channelType" : RTM_CHANNEL_TYPE.MESSAGE, "channelName" : "Chat_room", "publisher" : "Tony", } ``` ```csharp tab="Timeout" { "type" : RTM_PRESENCE_EVENT_TYPE.REMOTE_TIMEOUT, "channelType" : RTM_CHANNEL_TYPE.MESSAGE, "channelName" : "Chat_room", "publisher" : "Tony", } ``` ```csharp tab="State Change" { "type" : RTM_PRESENCE_EVENT_TYPE.REMOTE_STATE_CHANGED, "channelType" : RTM_CHANNEL_TYPE.MESSAGE, "channelName" : "Chat_room", "publisher" : "Tony", "stateItems" : [{"Mic":"False"},{"Position":" Beijing"}], "stateItemCount" : 2 } ``` <_PlatformProcessedMarker close="true" /> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="flutter" /> 如果频道中的在线人数小于实时通知最大人数参数设定的值(默认值为 50),则 Presence 事件通知处于实时通知模式。在此模式下,`remoteJoinChannel`、`remoteLeaveChannel`、`remoteTimeout`、`remoteStateChanged` 事件在触发时会立即发送到客户端。 ```dart tab="Join" { type: RtmPresenceEventType.remoteJoinChannel, channelType: RtmChannelType.message, channelName: 'chat_room', publisher: 'Tony', stateItems: [], interval: [], snapshot: [], timestamp: 1710487149497, } ``` ```dart tab="Leave" { type: RtmPresenceEventType.remoteLeaveChannel, channelType: RtmChannelType.message, channelName: 'chat_room', publisher: 'Tony', stateItems: [], interval: [], snapshot: [], timestamp: 1710487149497, } ``` ```dart tab="Timeout" { type: RtmPresenceEventType.remoteTimeout, channelType: RtmChannelType.message, channelName: 'chat_room', publisher: 'Tony', stateItems: [], interval: [], snapshot: [], timestamp: 1710487149497, } ``` ```dart tab="Snapshot" { type: RtmPresenceEventType.snapshot, channelType: RtmChannelType.message, channelName: 'chat_room', publisher: 'Tony', stateItems: [], interval: [], snapshot: {[ { userId: "user_a", states: []}, { userId: "user_b", states: [{ key: 'mic', value : 'on'}]}, { userId: "yourSelf", states: [{}]}, ]}, timestamp: 1710487149497 } ``` ```dart tab="State Change" { type: RtmPresenceEventType.remoteStateChanged, channelType: RtmChannelType.message, channelName: 'chat_room', publisher: 'Tony', stateItems: [{ key: 'mic', value : 'on'},{ key: 'mode', value : 'happy'}], interval: [], snapshot: [], timestamp: 1710487149497 } ``` <_PlatformProcessedMarker close="true" /> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="cpp" /> 如果频道中的在线人数小于实时通知最大人数参数设定的值(默认值为 50),则 Presence 事件通知处于实时通知模式。在此模式下,`RTM_PRESENCE_EVENT_TYPE_REMOTE_JOIN_CHANNEL`、`RTM_PRESENCE_EVENT_TYPE_REMOTE_LEAVE_CHANNEL`、`RTM_PRESENCE_EVENT_TYPE_REMOTE_TIMEOUT`、`RTM_PRESENCE_EVENT_TYPE_REMOTE_STATE_CHANGED` 事件在触发时会立即发送到客户端。 ```cpp tab="Join" { type: RTM_PRESENCE_EVENT_TYPE_REMOTE_JOIN_CHANNEL; channelType: RTM_CHANNEL_TYPE_MESSAGE; channelName: "test_channel"; publisher: "publisher_name"; states: []; interval: []; snapshot: []; timestamp: 1710487149497; } ``` ```cpp tab="Leave" { eventType: RTM_PRESENCE_EVENT_TYPE_REMOTE_LEAVE_CHANNEL; channelType: RTM_CHANNEL_TYPE_MESSAGE; channelName: "test_channel"; publisher: "publisher_name"; stateChanged: []; interval: []; snapshot: []; timestamp: 1710487149497; } ``` ```cpp tab="Timeout" { eventType: RTM_PRESENCE_EVENT_TYPE_REMOTE_TIMEOUT; channelType: RTM_CHANNEL_TYPE_MESSAGE; channelName: "test_channel"; publisher: "publisher_name"; stateChanged: []; interval: []; snapshot: []; timestamp: 1710487149497; } ``` ```cpp tab="Snapshot" { eventType: RTM_PRESENCE_EVENT_TYPE_SNAPSHOT; channelType: RTM_CHANNEL_TYPE_MESSAGE; channelName: "test_channel"; publisher: ""; stateChanged: []; interval: []; snapshot: [ { userId: "user_a", states: {}}, { userId: "user_b", states: { key_1: "value_1" }}, { userId: "yourSelf", states: {}}, ]; timestamp: 1710487149497; } ``` ```cpp tab="State Change" { eventType: RTM_PRESENCE_EVENT_TYPE_REMOTE_STATE_CHANGED; channelType: RTM_CHANNEL_TYPE_MESSAGE; channelName: "test_channel"; publisher: "publisher_name"; states: { "key_1": "value_1", }; interval: []; snapshot: []; timestamp: 1710487149497; } ``` <_PlatformProcessedMarker close="true" /> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="swift" /> 如果频道中的在线人数小于实时通知最大人数参数设定的值(默认值为 50),则 Presence 事件通知处于实时通知模式。在此模式下,`remoteJoinChannel`、`remoteLeaveChannel`、`remoteConnectionTimeout`、`remoteStateChanged` 事件在触发时会立即发送到客户端。 ```swift tab="Join" { type: .remoteJoinChannel; channelType: .message; channelName: "test_channel"; publisher: "publisher_name"; states: []; interval: []; snapshot: []; timestamp: 1710487149497; } ``` ```swift tab="Leave" { eventType: .remoteLeaveChannel; channelType: .message; channelName: "test_channel"; publisher: "publisher_name"; stateChanged: []; interval: []; snapshot: []; timestamp: 1710487149497; } ``` ```swift tab="Timeout" { eventType: .remoteConnectionTimeout; channelType: .message; channelName: "test_channel"; publisher: "publisher_name"; stateChanged: []; interval: []; snapshot: []; timestamp: 1710487149497; } ``` ```swift tab="Snapshot" { eventType: .snapshot; channelType: .message; channelName: "test_channel"; publisher: ""; stateChanged: []; interval: []; snapshot: [ { userId: "user_a", states: {}}, { userId: "user_b", states: { key_1: "value_1" }}, { userId: "yourSelf", states: {}}, ]; timestamp: 1710487149497; } ``` ```swift tab="State Change" { eventType: .remoteStateChanged; channelType: .message; channelName: "test_channel"; publisher: "publisher_name"; states: { "key_1": "value_1", }; interval: []; snapshot: []; timestamp: 1710487149497; } ``` <_PlatformProcessedMarker close="true" /> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="mini-program" /> 如果频道中的在线人数小于实时通知最大人数参数设定的值(默认值为 50),则 Presence 事件通知处于实时通知模式。在此模式下,`REMOTE_JOIN`、`REMOTE_LEAVE`、`REMOTE_TIMEOUT`、`REMOTE_STATE_CHANGED` 事件在触发时会立即发送到客户端。 ```javascript tab="Join" { eventType: "REMOTE_JOIN"; channelType: "MESSAGE"; channelName: "test_channel"; publisher: "publisher_name"; stateChanged: {}; interval: null; snapshot: null; } ``` ```javascript tab="Leave" { eventType: "REMOTE_LEAVE"; channelType: "MESSAGE"; channelName: "test_channel"; publisher: "publisher_name"; stateChanged: {}; interval: null; snapshot: null; } ``` ```javascript tab="Timeout" { eventType: "REMOTE_TIMEOUT"; channelType: "MESSAGE"; channelName: "test_channel"; publisher: "publisher_name"; stateChanged: {}; interval: null; snapshot: null; } ``` ```javascript tab="Snapshot" { eventType: "SNAPSHOT"; channelType: "MESSAGE"; channelName: "test_channel"; publisher: ""; stateChanged: {}; interval: null; snapshot: [ { userId: "user_a", states: {}, statesCount: 0 }, { userId: "user_b", states: { key_1: "value_1" }, statesCount: 1 }, { userId: "yourSelf", states: {}, statesCount: 0 }, ]; } ``` ```javascript tab="State Change" { eventType: "REMOTE_STATE_CHANGED"; channelType: "MESSAGE"; channelName: "test_channel"; publisher: "publisher_name"; stateChanged: { "key_1": "value_1", }; interval: null; snapshot: null; } ``` <_PlatformProcessedMarker close="true" /> ### 定时通知模式 [#定时通知模式] <_PlatformTabsGroup> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="android" /> 当频道中的在线人数超过实时通知最大人数的值时,频道会进入定时通知模式。在这种模式下,`REMOTE_JOIN`、`REMOTE_LEAVE`、`REMOTE_TIMEOUT`、`REMOTE_STATE_CHANGED` 事件会被 `INTERVAL` 事件代替,并以一定的时间间隔发送给频道中所有用户。 ```java { eventType : RtmPresenceEventType.INTERVAL, channelType : RtmChannelType.MESSAGE, channelName : "Chat_room", publisher : "", stateItems: {}, interval : { joinUserList : ["Tony","Lily"], leaveUserList : ["Jason"], timeoutUserList : ["Wang"], userStateList : [ { userId : "Harvard", states : [ { key: "Mic", value : "False" }, { key: "Position", value: " Beijing" } ], } ] } snapshot: { userStateList:[] }; timestamp: 1710487149497; } ``` <_PlatformProcessedMarker close="true" /> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="ios" /> 当频道中的在线人数超过实时通知最大人数的值时,频道会进入定时通知模式。在这种模式下,`AgoraRtmPresenceEventTypeRemoteJoinChannel`、`AgoraRtmPresenceEventTypeRemoteLeaveChannel`、`AgoraRtmPresenceEventTypeRemoteConnectionTimeout`、`AgoraRtmPresenceEventTypeRemoteStateChanged` 事件会被 `AgoraRtmPresenceEventTypeInterval` 事件代替,并以一定的时间间隔发送给频道中所有用户。 ```objc { "type" : AgoraRtmPresenceEventTypeInterval, "channelType" : AgoraRtmChannelTypeMessages, "channelName" : "Chat_room", "publisher" : "Tony", "interval" : { "remote_join" : ["Tony","Lily"], "remote_leave" : ["Jason"], "remote_timeout" : ["Wang"], "remote_state_change" : [ { "userId" : "Harvard", "states" : [{"Mic":"False"},{"Position":" Beijing"}], }, { "userId" : "Harvard", "states" : [{"Mic":"False"},{"Position":" Beijing"}], } ] } } ``` <_PlatformProcessedMarker close="true" /> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="web" /> 当频道中的在线人数超过实时通知最大人数的值时,频道会进入定时通知模式。在这种模式下,`REMOTE_JOIN`、`REMOTE_LEAVE`、`REMOTE_TIMEOUT`、`REMOTE_STATE_CHANGED` 事件会被 `INTERVAL` 事件代替,并以一定的时间间隔发送给频道中所有用户。 ```javascript interval: { join: { users: ["Tony", "Lily"], userCount: 2 }, leave: { users: ["Jason"], userCount: 1 }, timeout: { users: ["Wang"], userCount: 1 }, userStateList: [ { userId: "Harvard", states: { "Mic": "False", "Position": "Beijing" }, statesCount: 2, }, ], }, ``` <_PlatformProcessedMarker close="true" /> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="harmonyos" /> 当频道中的在线人数超过实时通知最大人数的值时,频道会进入定时通知模式。在这种模式下,`REMOTE_JOIN_CHANNEL`、`REMOTE_LEAVE_CHANNEL`、`REMOTE_TIMEOUT`、`REMOTE_STATE_CHANGED` 事件会被 `INTERVAL` 事件代替,并以一定的时间间隔发送给频道中所有用户。 ```typescript { eventType: RtmPresenceEventType.INTERVAL, channelType: RtmChannelType.MESSAGE, channelName: "chat_room", publisher: "", stateChanged: [], interval: { join: ["Tony", "Lily"], leave: ["Jason"], timeout: ["Wang"], userStateList: [ { userId: "Harvard", states: [ { key: "Mic", value: "False" }, { key: "Position", value: "Beijing" } ] }, { userId: "Alice", states: [ { key: "Mic", value: "True" }, { key: "Position", value: "Shanghai" } ] } ] }, snapshot: null, timestamp: 1710487149497 } ``` <_PlatformProcessedMarker close="true" /> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="unity" /> 当频道中的在线人数超过实时通知最大人数的值时,频道会进入定时通知模式。在这种模式下,`REMOTE_JOIN`、`REMOTE_LEAVE`、`REMOTE_TIMEOUT`、`REMOTE_STATE_CHANGED` 事件会被 `INTERVAL` 事件代替,并以一定的时间间隔发送给频道中所有用户。 ```csharp showLineNumbers { "type" : RTM_PRESENCE_EVENT_TYPE.INTERVAL, "channelType" : RTM_CHANNEL_TYPE.MESSAGE, "channelName" : "Chat_room", "publisher" : "Tony", "interval" : { "joinUserList" : ["Tony","Lily"], "leaveUserList" : ["Jason"], "timeoutUserList" : ["Wang"], "userStateList" : [ { "userId" : "Harvard", "states" : [{"Mic":"False"},{"Position":" Beijing"}], }, { "userId" : "Harvard", "states" : [{"Mic":"False"},{"Position":" Beijing"}], } ] } } ``` <_PlatformProcessedMarker close="true" /> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="flutter" /> 当频道中的在线人数超过实时通知最大人数的值时,频道会进入定时通知模式。在这种模式下,`remoteJoinChannel`、`remoteLeaveChannel`、`remoteTimeout`、`remoteStateChanged` 事件会被 `interval` 事件代替,并以一定的时间间隔发送给频道中所有用户。 ```dart { type : RtmPresenceEventType.interval, channelType : RtmChannelType.message,, channelName : 'chat_room', publisher : 'Tony', interval : { joinUserList : {users:['Tony','Lily']}, leaveUserList :{users:['Jason']}, timeoutUserList : {users:['Wang']}, userStateList : [ { userId : 'Harvard', states : [{ key: 'mic', value : 'on'},{ key: 'mode', value : 'happy'}], }, { userId : 'Harvard', states : [{ key: 'mic', value : 'off'},{ key: 'mode', value : 'sad'}], } ] } } ``` <_PlatformProcessedMarker close="true" /> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="cpp" /> 当频道中的在线人数超过实时通知最大人数的值时,频道会进入定时通知模式。在这种模式下,`RTM_PRESENCE_EVENT_TYPE_REMOTE_JOIN_CHANNEL`、`RTM_PRESENCE_EVENT_TYPE_REMOTE_LEAVE_CHANNEL`、`RTM_PRESENCE_EVENT_TYPE_REMOTE_TIMEOUT`、`RTM_PRESENCE_EVENT_TYPE_REMOTE_STATE_CHANGED` 事件会被 `RTM_PRESENCE_EVENT_TYPE_INTERVAL` 事件代替,并以一定的时间间隔发送给频道中所有用户。 ```cpp { "type" : RTM_PRESENCE_EVENT_TYPE_INTERVAL, "channelType" : RTM_CHANNEL_TYPE_MESSAGE, "channelName" : "Chat_room", "publisher" : "Tony", "interval" : { "remote_join" : ["Tony","Lily"], "remote_leave" : ["Jason"], "remote_timeout" : ["Wang"], "remote_state_change" : [ { "userId" : "Harvard", "states" : [{"Mic":"False"},{"Position":" Beijing"}], }, { "userId" : "Harvard", "states" : [{"Mic":"False"},{"Position":" Beijing"}], } ] }, snapshot: { userStateList:[] }, timestamp: 1710487149497, } ``` <_PlatformProcessedMarker close="true" /> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="swift" /> 当频道中的在线人数超过实时通知最大人数的值时,频道会进入定时通知模式。在这种模式下,`remoteJoinChannel`、`remoteLeaveChannel`、`remoteConnectionTimeout`、`remoteStateChanged` 事件会被 `interval` 事件代替,并以一定的时间间隔发送给频道中所有用户。 ```swift { "type" : AgoraRtmPresenceEventTypeInterval, "channelType" : AgoraRtmChannelTypeMessages, "channelName" : "Chat_room", "publisher" : "Tony", "interval" : { "remote_join" : ["Tony","Lily"], "remote_leave" : ["Jason"], "remote_timeout" : ["Wang"], "remote_state_change" : [ { "userId" : "Harvard", "states" : [{"Mic":"False"},{"Position":" Beijing"}], }, { "userId" : "Harvard", "states" : [{"Mic":"False"},{"Position":" Beijing"}], } ] } } ``` <_PlatformProcessedMarker close="true" /> <_PlatformProcessedMarker groupMode="structured" canonicalPlatform="web" platform="mini-program" /> 当频道中的在线人数超过实时通知最大人数的值时,频道会进入定时通知模式。在这种模式下,`REMOTE_JOIN`、`REMOTE_LEAVE`、`REMOTE_TIMEOUT`、`REMOTE_STATE_CHANGED` 事件会被 `INTERVAL` 事件代替,并以一定的时间间隔发送给频道中所有用户。 ```javascript interval: { join: { users: ["Tony", "Lily"], userCount: 2 }, leave: { users: ["Jason"], userCount: 1 }, timeout: { users: ["Wang"], userCount: 1 }, userStateList: [ { userId: "Harvard", states: { "Mic": "False", "Position": "Beijing" }, statesCount: 2, }, ], }, ``` <_PlatformProcessedMarker close="true" />