ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
### **开发流程** 在工程准备好了之后,只需简单的几步,即可实现基础的音视频通话。 #### **1.初始化SDK** 加载资源,应用程序中只需要执行一次,其他的功能接口都必须在初始化之后才能正常使用。 #import <AnyChatSDK/AnyChatSDK.h> 导入AnyChatSDK.framework 后需要引用<AnyChatSDK/AnyChatSDK.h> //初始化配置信息 AnyChatInitOpt *initOpt = [[AnyChatInitOpt alloc]init]; initOpt.serverIp = @"demo.anychat.cn"; initOpt.serverPort = @"8906"; initOpt.nickName = @"demo@anychat.cn"; initOpt.loginDelegate = self; //初始化 AnyChatSDK *brac = [AnyChatSDK sdkInit:initOpt]; //遵循LoginDelegate协议 实现代理回调 //登录回调 - (void)onLogin:(NSDictionary *)data ; //连接失败回调 - (void)onDisconnect:(AnyChatResult *)result ; //连接断开回调 - (void)OnLinkClose:(AnyChatResult *)result; #### **2.进入房间** // 初始化房间配置信息 AnyChatRoomOpt *roomOpt = [[AnyChatRoomOpt alloc]init]; roomOpt.roomDelegate = self; [AnyChatSDK getInstance].roomOpt = roomOpt; // 进入房间 [[AnyChatSDK getInstance] enterRoomWithRoomId:RoomId passWord:nil completion:^(AnyChatResult *result, NSString *roomId) { //进入房间操作的回调 } //遵循RoomDelegate协议 实现代理回调 用户进出房间事件回调 - (void)onRoomUserInAndOut:(NSDictionary *)data; 房间用户数变化事件回调 - (void)onRoomUserChanged:(NSDictionary *)data; 接收房间内的文本消息事件回调 - (void)onRoomUserMsgReceived:(NSDictionary *)data; #### **3.打开自己的麦克风以及摄像头** //获取视频设备列表 0为后置摄像头 1为前置摄像头 AnyChatCamera *videoDevice = [[AnyChatSDK getInstance]getCameras][1]; self.videoDevice = videoDevice; [self.videoDevice openWithRenderView:self.theLocalView]; //获取音频设备列表 移动端默认为0 AnyChatMicrophone *audioDevice = [[AnyChatSDK getInstance]getMicrophones][0]; self.audioDevice = audioDevice; //打开自己音频设备(麦克风) [self.audioDevice open]; #### **4.接收对方的音视频流** //开启接收对方音频流 [[AnyChatSDK getInstance] getRemoteAudioStreamWithUserId:self.iRemoteUserId]; //开启接收对方视频流 [[AnyChatSDK getInstance] getRemoteVideoStreamWithUserId:self.iRemoteUserId renderView:self.remoteVideoSurface]; #### **5.结束音视频通话** //关闭自己麦克风和摄像头 [self.audioDevice close]; [self.videoDevice close]; //关闭接收对方的音频流 [[AnyChatSDK getInstance] cancelRemoteAudioStreamWithUserId:self.iRemoteUserId]; //关闭接收对方的视频流 [[AnyChatSDK getInstance] cancelRemoteVideoStreamWithUserId:self.iRemoteUserId]; //离开房间 [[AnyChatSDK getInstance]leaveRoom]; //退出SDK [[AnyChatSDK getInstance] logout];