文档

跨房间订阅功能

默认情况下,只有同房间的用户才能进行音视频流的通信,不同房间之间的信息是隔离的。您可以通过跨房间订阅功能来实现不同房间的通信,来满足业务的要求,例如直播连麦等业务场景。本文介绍跨房间订阅功能的实现原理和示例代码。

实现原理

为简化客户处理逻辑,跨频道订阅B房间B1主播时,如果B房间不存在或者B1不存在,A1会等待到B1直到App主动取消订阅。

image

示例代码

跨频道订阅音视频流

  • Android示例代码:

    /* 跨频道订阅B频道的B1的Camera流、音频流 */
    mAliRtcEngine.subscribeRemoteDestChannelStream("B","B1",AliRtcVideoTrack.AliRtcVideoTrackCamera,true,true);
  • iOS示例代码:

    /* 跨频道订阅B频道的B1的Camera流、音频流 */
    [self.engine subscribeRemoteDestChannelStream:@"B" uid:@"B1" track:AliRtcVideoTrackCamera subAudio:YES sub:YES];
  • Windows示例代码

    /* 跨频道订阅B频道的B1的Camera流、音频流 */
    mAliRtcEngine->SubscribeRemoteDestChannelStream("B","B1",AliEngineVideoTrackCamera,true,true);

取消跨频道订阅音视频流

  • Android示例代码:

    /* 取消跨频道订阅B频道的B1的Camera流、音频流 */
    mAliRtcEngine.subscribeRemoteDestChannelStream("B","B1",AliRtcVideoTrack.AliRtcVideoTrackNo,false,false);
  • iOS示例代码:

    /* 取消跨频道订阅B频道的B1的Camera流、音频流 */
    [self.engine subscribeRemoteDestChannelStream:@"B" uid:@"B1" track:AliRtcVideoTrackNo subAudio:NO sub:NO];
  • Windows示例代码

    /* 取消跨频道订阅B频道的B1的Camera流、音频流 */
    mAliRtcEngine->SubscribeRemoteDestChannelStream("B","B1",AliEngineVideoTrackCamera,false,false);