CloudHub Docs
Download Documents

RTC


Fast integration SDK

Prepare

Add the CloudHubRTC.framework to the project

Configure project files

1.Add the CloudHubRTC.framework to the project

2.Modify the reference settings of CloudHubRTC.framework ,General–>Frameworks, Libraries, and Embedded Content image

3.Modification of engineering configuration(Build Settings) 1.Build Optins->Enable Bitcode->Change to NO image

2.Linkink->Other Linker Flage add **-all_load** 和 **-ObjC**
![image](/images/whiteboard/ios/whiteboard-ios_sdk-linkflag.jpg)

4.Adding a dependency library Build Phases->Link Binary With Libaries Add the necessary dependency libraries: libc++.tbd image

Adding Device Rights

CloudHubRTC will use the microphone and camera of iOS device, so you need to add permission request in the project info.plist file

Realize audio and video functions

1.Import the class

Before calling CloudHubRTC API,you need to import in the project CloudHubRTC ,and define a rtcEngine variable, declare CloudHubRtcEngineDelegate,listens for correction


// ViewController.h

// Import CloudHubRTC class
#import <CloudHubRTC/CloudHubRTC.h>

// Statement CloudHubRtcEngineDelegate to listens for correction
@interface ViewController : UIViewController <CloudHubRtcEngineDelegate>
// Define the  rtcEngine variable
@property (nonatomic, strong) CloudHubRtcEngineKit *rtcEngine;

2. Initialize the CloudHubRtcEngineKit object and set up the proxy

Call sharedEngineWithAppId:config: to create and initialize the CloudHubRtcEngineKit object.You need to replace YourAppID with the AppID you got in the admin background.See App ID

self.rtcEngine = [CloudHubRtcEngineKit sharedEngineWithAppId:@"Your App Id" config:nil];
self.rtcEngine.delegate = self;

3. Setting channel Scene

Call setChannelProfile

[self.cloudHubRtcEngineKit setChannelProfile:<#(CloudHubChannelProfile)#>];

4. Enter the channel

Call joinChannelByToken:channelId:properties:uid:autosubscribeAudio:autoSubscribeVideo:joinSuccess:

You will need to replace YourToken with your own generated Token and YourChannelId with Your ChannelId

[self.rtcEngine joinChannelByToken:@"YourToken" channelId:@"YourChannelId" properties:nil uid:@"YourUserId" autosubscribeAudio:YES autoSubscribeVideo:YES joinSuccess:nil];

5. Handles intra-channel callbacks

Reference CloudHubRtcEngineDelegate

- (void)       rtcEngine:(CloudHubRtcEngineKit * _Nonnull)engine
   didJoinChannelwithUid:(NSString * _Nonnull)uid
                 elapsed:(NSInteger) elapsed
{
    // Channel entry successful
    // Enable the audio/video module (subscription prerequisite)
    [engine enableAudio];
    [engine enableVideo];

    // Enabling local audio or video collection (Prerequisite for publishing)
    [engine enableLocalAudio:YES];
    [engine enableLocalVideo:YES];
}
- (void)rtcEngine:(CloudHubRtcEngineKit *)engine didOccurError:(CloudHubErrorCode)errorCode withMessage:(NSString *)message;
- (void)       rtcEngine:(CloudHubRtcEngineKit * _Nonnull)engine
 didReJoinChannelwithUid:(NSString * _Nonnull)uid
                 elapsed:(NSInteger) elapsed;

6. Local publication flow

Call publishStream to publish a local audio and video stream

[self.rtcEngine publishStream];

7. Subscribe to the remote video stream

This callback is received locally when there is a user publishing stream on the remote end.In this callback you can call startPlayingRemoteVideo:streamId:renderMode:mirrorMode: to play the user stream,and Your View can be set to a custom UIView

- (void)            rtcEngine:(CloudHubRtcEngineKit * _Nonnull)engine
 remoteVideoStateChangedOfUid:(NSString * _Nonnull)uid
                     streamId:(NSString * _Nonnull)streamId
                         type:(CloudHubMediaType)type
                        state:(CloudHubVideoRemoteState)state
                       reason:(CloudHubVideoRemoteStateReason)reason
{
    [self.rtcEngine startPlayingRemoteVideo:@"Your View" streamId:streamId renderMode:CloudHubVideoRenderModeHidden mirrorMode:CloudHubVideoMirrorModeDisabled];
}

8. Leave the channel

Call leaveChannel leaves current channel

[self.rtcEngine leaveChannel:nil];

An Away channel callback is triggered when you leave the channel rtcEngine:didLeaveChannel

- (void)rtcEngine:(CloudHubRtcEngineKit * _Nonnull)engine didLeaveChannel:(CloudHubChannelStats * _Nonnull)stats;

Specific reference to Sample program source download