声网Agora SDK 的使用

公司最近开了个新项目,一对一视频聊天。 因为之前有做过直播的经验,所以我建议老板用腾讯的SDK(毕竟腾讯直播技术已经很成熟了)但是老板的朋友推荐我们使用声网的SDK,因为他们家就是使用声网的,用着还不错。

首先我们看下声网
官方地址
声网Agora.io提供一个极简SDK让开发者接入SD-RTN™实时虚拟通信网,在任何App和网站实现高质量的语音聊天、视频聊天、全互动直播。
他们主打简单接入SDK,能快速实现直播更能。的确,在笔者接入过程中,发现接入是先的确简单。
你在发送视频请求时,会通过一个信令系统发送通知,信令系统其实就是一个长链接
下面是信令系统的处理,

signalEngine = [AgoraAPI getInstanceWithoutMedia:[KeyCenter appId]];
    
    WeakSelf(self)
    
    signalEngine.onLoginSuccess = ^(uint32_t uid, int fd) {
        
        MYLog(@"Login successfully, uid: %u", uid);
        dispatch_async(dispatch_get_main_queue(), ^{
           
        });
        
    };
    
    signalEngine.onLoginFailed = ^(AgoraEcode ecode) {
        
        MYLog(@"Login failed, error: %lu", (unsigned long)ecode);
        dispatch_async(dispatch_get_main_queue(), ^{
            if ([MYUser share].isLogin) {
                  [weakSelf loginAgoraSig];
            }
          
        });
        
    };
    
    signalEngine.onLogout = ^(AgoraEcode ecode) {
        
        if (ecode == 103) {
            
            [[NSNotificationCenter defaultCenter] postNotificationName:MY_SignalEngine_OnLogout_Notification object:nil userInfo:nil];
            
            //获取退出登录的网络请求
            [self getUserLoginOutNetRequest];
            
        }else {
            
//            if ([MYUser share].isLogin) {
//
//                [weakSelf loginAgoraSig];
//
//            }
            
        }
        
        MYLog(@"onLogout, error: %lu", (unsigned long)ecode);
        
    };
    
    signalEngine.onInviteReceived = ^(NSString* channelID, NSString *account, uint32_t uid, NSString *extra) {
        
        MYLog(@"onInviteReceived, channel: %@, account: %@, uid: %u, extra: %@", channelID, account, uid, extra);
        
        NSData *jsonData = [extra dataUsingEncoding:NSUTF8StringEncoding];
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
                                                            options:NSJSONReadingMutableContainers
                                                              error:nil];
        
        if ([MYUser share].isBusy) {

            NSDictionary *dataDict = @{};
            
            NSDictionary *allDataDict = @{@"uid":[MYUser share].uid,@"type":@"4",@"data":dataDict};
            
            NSString *message = [MYHelper convertToJSONData:allDataDict];
            
            [signalEngine messageInstantSend:dic[@"uid"] uid:[[MYUser share].uid integerValue] msg:message msgID:[MYHelper getTime]];
            
            [signalEngine channelInviteEnd:channelID account:dic[@"uid"] uid:[[MYUser share].uid integerValue]];
            
            return;
            
        }
        
        dispatch_async(dispatch_get_main_queue(), ^{
            
            MYReceiveVideoViewController *rvVC = [[MYReceiveVideoViewController alloc] init];
            rvVC.channelIdAndName = channelID;
            rvVC.channelKey = dic[@"channelKey"];
            rvVC.remoteAvatar = dic[@"avatar"];
            rvVC.remoteNickName = dic[@"nickname"];
            rvVC.remoteAccount = dic[@"uid"];
            [[MYGlobal share].lastVC.navigationController pushViewController:rvVC animated:YES];
            
        });
    };
    
    signalEngine.onInviteEndByPeer = ^(NSString* channelID, NSString *account, uint32_t uid, NSString *extra) {
        NSLog(@"onInviteEndByPeer, channel: %@, account: %@, uid: %u, extra: %@", channelID, account, uid, extra);
       
        [MYUser share].isBusy = NO;
    };

推流拉流那些都是 AgoraRtcVideoCanvas 实现的,不需要自己单独去处理。比较方便。
视频聊天集成的地址

暂时先简单的这么说下,后面再说下美颜等一些东西

你可能感兴趣的:(声网Agora SDK 的使用)