全部产品
视频直播

观众加入连麦

更新时间:2017-09-06 11:46:48   分享:   

  1. 观众C向APP Server发出申请,要求加入连麦。

    (客户端代码:LiveRoomViewController.m文件中)

    1. NSArray* inviteeUids = [[NSArray alloc] initWithObjects:self.hostUid, nil];
    2. [SendMessageManager inviteVideoCall:self.roomId inviterUid:self.userUid inviteeUids:inviteeUids inviterType:1 block:^(NSError *error) {
    3. }];
  2. APP Server向主播和副麦A转发观众C的申请。

    (APP Server端代码:controller\videocallctrl.js文件中)

    1. inviteeUids.forEach((uid) => {
    2. if (uid) {
    3. let msg = util.createMqttMsg({
    4. inviterUid: inviterUid,
    5. inviterName: inviterInfo.name,
    6. inviterType: inviterType
    7. }, 1);
    8. mns.publish(liveRoomId, msg, 4, util.getUserTopicTag(liveRoomId, uid));
    9. }
    10. });
  3. 主播和副麦A向APP Server发送同意连麦的信号。

    (客户端代码:StartLiveViewController.mm文件中)

    1. - (void)onGetInviteMessage:(NSString *)inviterUid inviterName:(NSString*)inviterName inviterType:(int)inviterType
    2. {
    3. //status = 1,代表同意
    4. [SendMessageManager sendVideoCallFeedBack:inviterUid inviteeUid:self.uid status:1 inviterType:inviterType inviteeType:2 block:^(NSURL *mainPlayUrl, NSArray<NSURL *> *playUrls, NSArray<NSString *> *playUids, NSString *rtmpUrl, NSError *error) {
    5. }];
    6. }
  4. APP Server向观众C分配推流地址,并发送主播和副麦A的播放地址。

    (APP Server端代码:controller\videocallCtrl.js文件中)

    1. videoCall.store(mainRoomId, uid + "|" + roomId);
    2. videoCall.setMainBy(roomId, mainRoomId);
    3. response.success(res, {
    4. mainPlayUrl: address.getShortRtmpPlayUrl(mainRoomId),//主播播放地址
    5. playUrls: otherPlayUrls, //已经推流观众播放地址
    6. rtmpUrl: address.getRtmpUrl(roomId) //被同意连麦观众的推流地址
    7. });
  5. 观众C开始连麦(即结束播放混流地址,开始推流、开始播放主播和副麦A的播放地址)。

    (客户端代码:LiveRoomViewController.m文件中,调用SDK接口onlineChats)

    1. - (void)onGetInviteAgreeMessage:(NSString*)inviteeUid inviteeName:(NSString*)inviteeName inviteeRoomId:(NSString*)inviteeRoomId inviterRoomId:(NSString*)inviterRoomId mainPlayUrl:(NSURL*)mainPlayUrl rtmpUrl:(NSString*)rtmpUrl otherPlayUrls:(NSArray *)otherPlayUrls otherPlayUids:(NSArray *)otherPlayUids
    2. {
    3. [self createLiveCallWithPushUrl:rtmpUrl hostPlayUrl:mainPlayUrl otherPlayUrls:otherPlayUrls otherPlayUids:otherPlayUids];
    4. }
  6. APP Server收到AliLive给出的观众C推流成功的回调,将C的播放地址发送给主播和A、B、C。

    (APP Server端代码:controller\alinotify.js文件中)

    1. static publish(liveInfo) {
    2. let roomId = liveInfo.roomId;
    3. delayQueue.deQueue(roomId);
    4. let msg = util.createMqttMsg({
    5. uid: liveInfo.uid,
    6. roomId: roomId,
    7. name: liveInfo.name,
    8. playUrl: address.getShortRtmpPlayUrl(roomId)
    9. }, 9);
    10. co(function*() {
    11. //设置推流状态
    12. live.setStatus(roomId, 1);
    13. let mainRoomId = yield videoCall.getMainBy(roomId);
    14. //发送推流通知
    15. mns.publish(mainRoomId ? mainRoomId : roomId, msg, 5);
    16. if (mainRoomId) {
    17. //如果是连麦观众加入混流
    18. yield videoCall.addToMix(mainRoomId, roomId, liveInfo.uid, liveInfo.name);
    19. }
    20. }).catch((err) => {
    21. console.log(err);
    22. });
    23. }
  7. 主播增加与C的连麦(即播放C的播放地址)。

    (客户端代码:StartLiveViewController.mm文件中,调用SDK接口addChats)

    1. - (void)onGetStartLiveMessage:(NSString *)roomId uid:(NSString *)uid name:(NSString *)name playUrl:(NSString *)playUrl
    2. {
    3. ......
    4. }
  8. 副麦A增加与C的连麦(即播放C的播放地址)。

    (客户端代码:LiveRoomViewController.m文件中,调用SDK接口addChats)

    1. - (void)onGetStartLiveMessage:(NSString *)roomId uid:(NSString *)uid name:(NSString *)name playUrl:(NSString *)playUrl
    2. {
    3. ......
    4. }
  9. APP Server调用AliLive的混流接口,C加入混流画面。至此,观众C加入连麦成功。

    (APP Server端代码:controller\videocallCtrl.js文件中,调用OpenAPI接口AddMultipleStreamMixService)

    1. if (mainRoomId) {
    2. yield videoCall.addToMix(mainRoomId, roomId, liveInfo.uid, liveInfo.name);
    3. }
本文导读目录
本文导读目录
以上内容是否对您有帮助?