如下是一个总体接入流程,详细细节请参见 RTC服务开通指南。



- (void)joinRTCRoomWithModel:(VideoCallRoomUserModel *)localUserModel
rtcToken:(NSString *)rtcToken {
// 初始化 RTC Video 对象
// Initialize the RTC Video object
self.rtcRTCVideo = [ByteRTCVideo createRTCVideo:appID
delegate:self
parameters:@{}];
// 初始化 RTC Room 对象
// Initialize the RTC Room object
self.rtcRoom = [self.rtcRTCVideo createRTCRoom:roomId];
self.rtcRoom.delegate = self;
// 开启麦克风采集
// Enable microphone capture
[self.rtcRTCVideo startAudioCapture];
// 根据预览页配置开启/关闭相机采集
// Enable/disable camera capture according to the preview page configuration
if (preSetting.isEnableVideo) {
[self.rtcRTCVideo startVideoCapture];
} else {
[self.rtcRTCVideo stopVideoCapture];
}
// 根据预览页配置开启/关闭音频推送
// Enable/disable audio push according to the preview page configuration
if (preSetting.isEnableAudio) {
[self.rtcRoom publishStream:ByteRTCMediaStreamTypeAudio];
} else {
[self.rtcRoom unpublishStream:ByteRTCMediaStreamTypeAudio];
}
//设置音频路由模式,扬声器/听筒
//Set the audio routing mode, speaker/earpiece
[self.rtcRTCVideo setAudioPlaybackDevice:preSetting.playback];
//开启/关闭发言者音量键控
//Turn on/off speaker volume keying
ByteRTCAudioPropertiesConfig *audioPropertiesConfig = [[ByteRTCAudioPropertiesConfig alloc] init];
audioPropertiesConfig.interval = 1000;
[self.rtcRTCVideo enableAudioPropertiesReport:audioPropertiesConfig];
//加入房间,开始连麦,需要申请AppId和Token
//Join the room, start connecting the microphone, you need to apply for AppId and Token
ByteRTCUserInfo *userInfo = [[ByteRTCUserInfo alloc] init];
userInfo.userId = localUserModel.uid;
NSDictionary *extraInfo = @{
@"user_name": localUserModel.name,
@"user_id": localUserModel.uid
};
userInfo.extraInfo = [extraInfo yy_modelToJSONString];
ByteRTCRoomConfig *config = [[ByteRTCRoomConfig alloc] init];
config.profile = ByteRTCRoomProfileCommunication;
// 开启自动推送
// enable automatic push
config.isAutoPublish = YES;
// 开启自动订阅音视频
// Enable automatic subscription of audio and video
config.isAutoSubscribeAudio = YES;
config.isAutoSubscribeVideo = YES;
[self.rtcRoom joinRoomByToken:rtcToken userInfo:userInfo roomConfig:config];
}
objectivec- (void)leaveRTCRoom {
//离开频道
//Leave the channel
[self.rtcRTCVideo stopAudioCapture];
[self.rtcRoom leaveRoom];
[self.rtcRoom destroy];
self.rtcRoom = nil;
}
objectivec-rtcRoom:onUserJoined:elapsed: 回调。- (void)rtcRoom:(ByteRTCRoom *)rtcRoom onRoomStateChanged:(NSString *)roomId withUid:(NSString *)uid state:(NSInteger)state extraInfo:(NSString *)extraInfo {
NSDictionary *dic = [self dictionaryWithJsonString:extraInfo];
NSInteger joinType = -1;
if ([dic isKindOfClass:[NSDictionary class]]) {
NSString *joinTypeStr = [NSString stringWithFormat:@"%@", dic[@"join_type"]];
joinType = joinTypeStr.integerValue;
}
// joinType '0'为首次进房,'1'为重连进房 ;state '0'为加入房间成功
// joinType '0' is the first time entering the room, '1' is the reconnection entering the room; state '0' means join the room successfully
if (state == 0 && joinType == 1) {
// 执行业务重连API,更新业务状态
// Execute business re-API, update business status
[Networking reconnectBlock:^(RTMACKModel * _Nonnull model) {
// do something
}];
}
}
objectivec屏幕共享参看iOS 端屏幕共享
| 功能点 | API |
|---|---|
| 创建 ByteRTCVideo 实例 | createRTCVideo:delegate:parameters: |
| 设置视频发布参数 | SetVideoEncoderConfig: |
| 开启本地音频采集 | startAudioCapture: |
| 开启本地视频采集 | startVideoCapture |
| 设置本地视频渲染 | setLocalVideoCanvas:withCanvas: |
| 加入 RTC 房间 | joinRoomByToken:userInfo:roomConfig: |
| 设置视频渲染视图 | setRemoteVideoCanvas:withIndex:withCanvas: |
| 离开房间 | leaveRoom |
| 关闭内部音频采集 | stopAudioCapture |
| 关闭内部视频采集 | stopVideoCapture |
| 销毁引擎实例对象 | destroy |
| 发布本地通过摄像头/麦克风采集的媒体流 | publishStream: |
| 取消发布本地通过摄像头/麦克风采集的媒体流 | unpublishStream: |
| 设置音频播放设备为扬声器或者听筒 | setAudioRoute: |
| 开启音量提示 | enableAudioPropertiesReport: |
| 开启镜像 | setLocalVideoMirrorType: |
| 设置音质档位 | setAudioProfile: |
| 切换视前置/后置摄像头 | switchCamera: |
| 功能点 | 回调 |
|---|---|
| 本地进房成功回调 | rtcRoom:onRoomStateChanged:uid:state:extraInfo |
| 远端可见用户加入房间 | rtcRoom:onUserJoined:elapsed: |