文档首页 > > SDK参考> Mac SDK> SDK使用

SDK使用

分享
更新时间:2020/11/18 GMT+08:00
  1. 创建引擎并初始化,其中域名请保持默认值即可,AppId提交工单申请。

    1
    2
    _rtcEngine = [HWRtcEngine sharedEngine];
    [_rtcEngine init:domain appId:appid];
    

  2. 设置本地窗口。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    _localVideoSession = [[HWVideoSession alloc] initWithUserID:self.userName];
    HwRtcVideoView *videoView = [[HwRtcVideoView alloc] initWithFrame:self.view.bounds];
    _localVideoSession.videoView = videoView;
    _localVideoSession.userName = self.userName;
    _localVideoSession.isPlaying = YES;
    [_rtcEngine setupLocalVideo:_localVideoSession.canvas viewMode:self.displayMode];
    self.localVideoSession.isPlaying = YES;
    [self.view addSubview:videoView];
    [self.showViewsArray addObject:_localVideoSession];
    

  3. 加入房间。

    1
    2
    3
    4
    5
    6
    7
    HWRtcUserInfo *userInfo = [[HWRtcUserInfo alloc]init];
    userInfo.role = roleType;
    userInfo.userId = userid;
    userInfo.userName = userid;
    userInfo.signature = signature;
    userInfo.ctime = time;
    BOOL result = [weakSelf.rtcEngine joinRoom:userInfo roomId:roomid mediaType:HWRtcMediaTypeVideo];
    

  4. 监听远端用户加入房间,并设置远端窗口。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    -(void)onUserJoined:(NSString*)roomId userId:(NSString*)userId nickName:(NSString*)nickName{
        if([userId isEqualToString:localUid] || self.roleType ==HWRtcRolePublisher){
            return;
        }
        @synchronized (self) {
             dispatch_async(dispatch_get_main_queue(),
                              ^{
    
                                         HWVideoSession *videoSession = [[HWVideoSession alloc] initWithUserID:userId];
                                         videoSession.isPlaying = YES;
                                         videoSession.userName= userId;
                                         [self.viewsArray addObject:videoSession];
                                         HwRtcVideoView *videoView = [[HwRtcVideoView alloc] initWithFrame:NSRectFromCGRect(CGRectMake(0, 0, 90, 160))];
                                         videoSession.videoView = videoView;
                                         int result = [self.rtcEngine startRemoteStreamView:videoSession.canvas streamType:self.streamType];
                                         if (result == 0) {
                                                     [self.rtcEngine setRemoteViewDisplayMode:self.displayMode userid:videoSession.canvas.uid]; }
    
                                                      [self.showViewsArray addObject:videoSession];
    
            });
         }
    }
    

  5. 监听远端用户离开房间,并删除远端窗口。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    - (void)onUserOffline:(NSString *)roomId userId:(NSString *)userId reason:(NSInteger)reason
    {
        if(self.roleType == HWRtcRolePublisher)){
            return;
        }
        dispatch_async(dispatch_get_main_queue(),
        ^{
    
                 HWVideoSession *offlineVideoSession;
                 for (HWVideoSession *videoSession in self.viewsArray){
                          if ([userId isEqualToString:videoSession.canvas.uid] )
                            {
                                  offlineVideoSession = videoSession; 
                                    break;
                             }
                      }
     
                   if (offlineVideoSession) {
                          [self.viewsArray removeObject:offlineVideoSession];
    
                    }
    
     
        });
    }
    

  6. 离开房间。

    1
    [_rtcEngine leaveRoom];
    

分享:

    相关文档

    相关产品

文档是否有解决您的问题?

提交成功!非常感谢您的反馈,我们会继续努力做到更好!
反馈提交失败,请稍后再试!

*必选

请至少选择或填写一项反馈信息

字符长度不能超过200

提交反馈 取消

如您有其它疑问,您也可以通过华为云社区问答频道来与我们联系探讨

智能客服提问云社区提问