tencent cloud

文档反馈

Android&iOS&Flutter

最后更新时间:2024-05-24 18:35:12
    本文介绍 TUICallKit 组件通话状态回调的使用。

    通话状态监听

    如果您的业务需要监听通话的状态,例如通话开始、结束等通话过程中的事件,可以参考如下代码:
    Android(Kotlin)
    Android(Java)
    iOS(Swift)
    iOS(Objective-C)
    Flutter(Dart)
    import com.tencent.qcloud.tuikit.TUICommonDefine import com.tencent.qcloud.tuikit.tuicallengine.TUICallDefine import com.tencent.qcloud.tuikit.tuicallengine.TUICallEngine import com.tencent.qcloud.tuikit.tuicallengine.TUICallObserver
    
    private val observer: TUICallObserver = object : TUICallObserver() {
    override fun onCallBegin(roomId: TUICommonDefine.RoomId?, callMediaType: TUICallDefine.MediaType?, callRole: TUICallDefine.Role?) {
    }
    override fun onCallEnd(roomId: TUICommonDefine.RoomId?, callMediaType: TUICallDefine.MediaType?, callRole: TUICallDefine.Role?, totalTime: Long) {
    }
    override fun onUserNetworkQualityChanged(networkQualityList: MutableList<TUICommonDefine.NetworkQualityInfo>?) {
    }
    }
    private fun initData() {
    TUICallEngine.createInstance(context).addObserver(observer)
    }
    import com.tencent.qcloud.tuikit.TUICommonDefine; import com.tencent.qcloud.tuikit.tuicallengine.TUICallDefine; import com.tencent.qcloud.tuikit.tuicallengine.TUICallEngine; import com.tencent.qcloud.tuikit.tuicallengine.TUICallObserver;
    
    private TUICallObserver observer = new TUICallObserver() {
    @Override
    public void onCallBegin(TUICommonDefine.RoomId roomId, TUICallDefine.MediaType callMediaType, TUICallDefine.Role callRole) {
    }
    @Override
    public void onCallEnd(TUICommonDefine.RoomId roomId, TUICallDefine.MediaType callMediaType,TUICallDefine.Role callRole, long totalTime) {
    }
    @Override
    public void onUserNetworkQualityChanged(List<TUICommonDefine.NetworkQualityInfo> networkQualityList) {
    }
    };
    
    private void initData(){
    TUICallEngine.createInstance(context).addObserver(observer);
    }
    import TUICallEngine
    
    TUICallEngine.createInstance().addObserver(self)
    
    func onCallBegin(roomId: TUIRoomId, callMediaType: TUICallMediaType, callRole: TUICallRole) {
    
    }
    
    func onCallEnd(roomId: TUIRoomId, callMediaType: TUICallMediaType, callRole: TUICallRole, totalTime: Float) {
    
    }
    
    func onUserNetworkQualityChanged(networkQualityList: [TUINetworkQualityInfo]) {
    
    }
    #import <TUICallEngine/TUICallEngine.h>
    
    [[TUICallEngine createInstance] addObserver:self];
    
    - (void)onCallBegin:(TUIRoomId *)roomId callMediaType:(TUICallMediaType)callMediaType callRole:(TUICallRole)callRole {
    
    }
    
    - (void)onCallEnd:(TUIRoomId *)roomId callMediaType:(TUICallMediaType)callMediaType callRole:(TUICallRole)callRole totalTime:(float)totalTime {
    
    }
    
    - (void)onUserNetworkQualityChanged:(NSArray<TUINetworkQualityInfo *> *)networkQualityList {
    
    }
    import 'package:tencent_calls_engine/tencent_calls_engine.dart';
    
    TUICallObserver observer = TUICallObserver(
    onError: (int code, String message) {
    }, onCallBegin: (TUIRoomId roomId, TUICallMediaType callMediaType, TUICallRole callRole) {
    }, onCallEnd: (TUIRoomId roomId, TUICallMediaType callMediaType, TUICallRole callRole, double totalTime) {
    
    }, onUserNetworkQualityChanged: (List<TUINetworkQualityInfo> networkQualityList) {
    }, onCallReceived: (String callerId, List<String> calleeIdList, String groupId, TUICallMediaType callMediaType) {
    
    }
    ))
    
    void addObserver() {
    TUICallEngine.instance.addObserver(observer);
    }
    注意:
    在 Android 平台设置 TUICallObserver 监听回调,需保证回调所在类不会被清除,举例:不建议在 LoginActivity 中添加监听,LoginActivity 销毁的时候,回调也会被清除;建议在应用的 Application 中或者应用主界面进行监听。
    
    联系我们

    联系我们,为您的业务提供专属服务。

    技术支持

    如果你想寻求进一步的帮助,通过工单与我们进行联络。我们提供7x24的工单服务。

    7x24 电话支持