You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Agora React UIKit中添加用户加入时的自定义逻辑?

解决方案

Agora React UIKit 内置了对应回调函数可实现用户加入频道时的自定义逻辑,你只需在现有 callbacks 对象中添加 JoinChannelSuccess 回调即可——该回调会在本地用户成功加入频道时触发。

修改后的代码如下:

const rtcProps = {
    appId: appId,
    channel: streamId,
    token: null,
};

const callbacks = {
    EndCall: () => {
        router.replace("/");
    },
    // 新增用户成功加入频道的自定义逻辑
    JoinChannelSuccess: (channel, uid, elapsed) => {
        // 在此编写你的自定义逻辑,比如日志记录、状态更新、业务方法调用等
        console.log(`用户 ${uid} 成功加入频道 ${channel},耗时 ${elapsed}ms`);
        // yourCustomBusinessLogic();
    },
};

const rtmProps = {};

<AgoraUIKit rtcProps={rtcProps} callbacks={callbacks} rtmProps={rtmProps} />

如果需要监听其他用户加入频道的事件,可额外添加 UserJoined 回调:

const callbacks = {
    // ...已有的回调
    UserJoined: (uid) => {
        console.log(`用户 ${uid} 已加入频道`);
        // 其他用户加入时的自定义逻辑
    },
};

上述回调均为 Agora React UIKit 原生支持,无需直接调用底层 Web SDK 即可满足需求。

内容的提问来源于stack exchange,提问作者Aoun Shabbir

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 09:02:09