CloudHub Docs
Download Documents

RTC


CloudHubSDK iOS

CloudHubRtcChannelKit

Set delegate

delegate:

Set delegate for CloudHubRtcChannelKit

@property (nonatomic, weak) id<CloudHubRtcChannelDelegate> _Nullable delegate;

Discussion

See CloudHubRtcChannelDelegate

Channel management

setClientRole

Sets the role of the user in interactive live streaming.

- (int)setClientRole:(CloudHubClientRole)role;

Parameters

ParametersDescribe
roleThe role of a user in interactive live streaming. See CloudHubClientRole

Return Value

Discussion

Before joining the channel, users need to set audience (default) or anchor role through this method. After joining the channel, users can switch user role through this method If you call this method to switch the user role after joining a channel,

Note

joinChannelByToken:properties:uid:autosubscribeAudio:autoSubscribeVideo:joinSuccess:

Joins the channel with a user ID.

- (int)joinChannelByToken:(NSString * _Nullable)token
               properties:(NSString * _Nullable)properties
                      uid:(NSString * _Nullable)uid
       autoSubscribeAudio:(BOOL)autoSubscribeAudio
       autoSubscribeVideo:(BOOL)autoSubscribeVideo
              joinSuccess:(void(^ _Nullable)(NSString * _Nonnull channelID, NSString * _Nonnull uid, NSInteger elapsed))joinSuccessBlock;

Parameters

ParametersDescribe
tokenThe token generated at your server,If the security requirements are not high, you can pass empty
propertiesUser-defined properties that will be synchronized to other users in the channel must be JSON strings that can be passed blank
uidThe unique identifier of the user in the channel. The character string must be a combination of letters and numbers.If null, ‘CloudHubRtcChannelKit’ will automatically generate a GUID for your UID,And through the rtcChannel:didJoinChannelwithUid:elapsed: delegate to told you
autoSubscribeAudioAutomatic audio subscription
autoSubscribeVideoAutomatic video subscription
joinSuccessBlockSuccessfully joined the channel delegate,and call after rtcChannel:didJoinChannelwithUid:elapsed:

Return Value

Discussion

In this method, users can join the calling channel. Users in the same channel can talk with each other, and multiple users can join the same channel and chat in groups. Apps with different App ids cannot communicate with each other,If the call is already on, the user must call leaveChannel: to exit the current call before going to the next channel

Note

joinChannelByToken:properties:uid:autosubscribeAudio:autoSubscribeVideo:publishLocalAudio:publishLocalVideo:joinSuccess:

Joins the channel with a user ID.

- (int)joinChannelByToken:(NSString * _Nullable)token
               properties:(NSString * _Nullable)properties
                      uid:(NSString * _Nullable)uid
       autoSubscribeAudio:(BOOL)autoSubscribeAudio
       autoSubscribeVideo:(BOOL)autoSubscribeVideo
        publishLocalAudio:(BOOL)publishLocalAudio
        publishLocalVideo:(BOOL)publishLocalVideo
              joinSuccess:(void(^ _Nullable)(NSString * _Nonnull channelID, NSString * _Nonnull uid, NSInteger elapsed))joinSuccessBlock;

Parameters

ParametersDescribe
tokenThe token generated at your server,If the security requirements are not high, you can pass empty
propertiesUser-defined properties that will be synchronized to other users in the channel must be JSON strings that can be passed blank
uidThe unique identifier of the user in the channel. The character string must be a combination of letters and numbers.If null, ‘CloudHubRtcChannelKit’ will automatically generate a GUID for your UID,And through the rtcChannel:didJoinChannelwithUid:elapsed: delegate to told you
autoSubscribeAudioAutomatic audio subscription
autoSubscribeVideoAutomatic video subscription
publishLocalAudioTo set whether to publish local audio streams within a channel:
•true: (default)publish
•false: Don’t publish
publishLocalVideoSets whether to publish local video streams within a channel:
•true: (default)publish
•false: Don’t publish
joinSuccessBlockSuccessfully joined the channel delegate,and call after rtcChannel:didJoinChannelwithUid:elapsed:

Return Value

Discussion

In this method, users can join the calling channel. Users in the same channel can talk with each other, and multiple users can join the same channel and chat in groups. Apps with different App ids cannot communicate with each other,If the call is already on, the user must call leaveChannel: to exit the current call before going to the next channel

Automatic publishing is enabled when automatic publishing audio (publishLocalAudio is true) or automatic publishing video ( publishLocalVideo is true) is set.

When automatic publishing comes on, If the audio stream or video stream is not automatically published (publishLocalAudio is false or publishLocalVideo is false ), its state of muted (equivalent to invoke muteLocalAudioStream/muteLocalVideoStream and passing parameters for true).

When automatic release function use, you can use the muteLocalAudioStream/muteLocalVideoStream method to reset is released within the channel local audio stream.

In single-current mode:

When automatic publish is enabled, the SDK will no longer publish the corresponding method until the unPublish method is called.

In multi-stream mode:

Only one camera will be published (devices whose index is 0 in the device enumeration result)

Note

leaveChannel:

Leaves the current channel.

- (int)leaveChannel:(void(^ _Nullable)(NSString * _Nonnull channelID))leaveChannelBlock;

Parameters

ParametersDescribe
leaveChannelBlockSuccessfully leave the channel delegate,and call after rtcChannel:didLeaveChannel: 之后调用

Return Value

Discussion

To leave a channel, which means to hang up or quit a call,When calling joinChannelByToken:properties:uid:autosubscribeAudio:autoSubscribeVideo:joinSuccess: method, you must call leaveChannel: to end the call. Otherwise, the next call cannot start. This method can be called regardless of whether a call is currently in progress or not, and has no side effects. This method frees all resources associated with the session. This method is asynchronous and does not actually exit the channel when the call returns

renewToken:

Renews the token when the current token expires.

- (int)renewToken:(NSString * _Nonnull)token;

Parameters

ParametersDescribe
tokenTokens generated by the developer service side

Return Value

Discussion

In the following situations, the SDK decides that the current token has expired:

You should get a new token from your server and call this method to renew it. Failure to do so results in the SDK disconnecting from the Cloudhub server.

getConnectionState

Gets the connection state of the SDK.

- (CloudHubConnectionStateType)getConnectionState;

Return Value

Release management

setPublishStreamInfo:

User-defined data when publishing local audio and video (Json string format)

- (int)setPublishStreamInfo:(NSString * _Nonnull)info;

Return Value

Discussion

This method must be in the [rtcChannel:didJoinChannelwithUid:elapsed: callback after a successful publishStream before the call. The successful if the remote subscription streaming video, will receive in rtcChannel:remoteVideoStateChangedOfUid:streamId:type:state:reason: callback, and distal via the streamInfo parameters.

publishStream

Start publish local audio and video

- (int)publishStream;

Return Value

Discussion

Post your audio and video to a channel for others to watch and listen to

Note

unPublishStream

Stop publish local audio and video

- (int)unPublishStream;

Return Value

Discussion

Stop their audio and video, when to stop after the release, the distal if shut down automatically subscribe, will receive rtcChannel:onUserUnPublished:type:stream: callback, in addition whether remote shut down automatically subscribe, Will receive rtcChannel:remoteVideoStateChangedOfUid:streamId:type:state:reason: callback

Note

Manual Subscription Management

subscribe

Start subscribing to audio and video

- (int)subscribe:(NSString * _Nonnull)streamId;

Parameters

ParametersDescribe
streamIdThis audio video stream in a channel only Id, this Id is available from rtcChannel:onUserPublished:type:stream: callback

Return Value

Discussion

Please in receive rtcChannel:onUserPublished:type:stream: the callback after the call

unSubscribe

Unsubscribe all the way audio and video

- (int)unSubscribe:(NSString * _Nonnull)streamId;

Parameters

ParametersDescribe
streamIdThis audio video stream in a channel only Id, this Id is available fromrtcChannel:onUserPublished:type:stream: rtcChannel:onUserUnPublished:type:stream: the callback after the call

Return Value

Discussion

Audio management

muteRemoteAudioStream:mute:

Receives or stops receiving the specified audio stream

- (int)muteRemoteAudioStream:(NSString* _Nonnull)uid 
                        mute:(BOOL)mute;

Parameters

ParametersDescribe
uidThe user ID of the specified remote user.
muteSets whether to stop receiving the specified audio stream

Return Value

Note

muteAllRemoteAudioStreams

Receive or stop receiving the specified audio stream

- (int)muteAllRemoteAudioStreams:(BOOL)mute;

Parameters

ParametersDescribe
muteWhether to stop receiving all users' voices

Return Value

adjustUserPlaybackSignalVolume:volume:

Adjust the playback signal volume of a specified remote user.

- (int)adjustUserPlaybackSignalVolume:(NSString* _Nonnull)uid
                               volume:(int)volume;

Parameter

ParameterDescription
volumeThe playback volume of the specified remote user. The value ranges between 0 and 100, including the following:
• 0: Mute.
• 00: (Default) Original volume.

Returns

Video management

setRemoteRenderMode:renderMode:mirrorMode:

Updates the display mode of the video view of a remote user.

- (int)setRemoteRenderMode:(NSString * _Nonnull)streamId
                renderMode:(CloudHubVideoRenderMode) renderMode
                mirrorMode:(CloudHubVideoMirrorMode) mirrorMode;

Parameters

ParametersDescribe
streamIdThe ID of the remote video stream can be obtained from this callback method:rtcChannel:remoteVideoStateChangedOfUid:streamId:type:state:reason:
renderModeSee CloudHubVideoRenderMode
mirrorModeSee CloudHubVideoMirrorMode

Return Value

Discussion

After initializing the video view of a remote user, you can call this method to update its rendering and mirror modes. This method affects only the video view that the local user sees.

Note

muteRemoteVideoStreamWithUid:mute:

Stops or resumes receiving to the video stream of a specified user.

- (int)muteRemoteVideoStreamWithUid:(NSString * _Nonnull)uid
                               mute:(BOOL)mute;

Parameters

ParametersDescribe
uidThe user ID of the specified remote user.
mute• YES: Do not receive remote video streams
• NO: Receiving remote video stream (default)

Return Value

Discussion

Called after joining a channel

Note

muteRemoteVideoByStreamId:mute:

Unsubscribe or resume receiving to the specified remote video stream

- (int)muteRemoteVideoByStreamId:(NSString * _Nonnull)streamId
                            mute:(BOOL)mute;

Parameters

ParametersDescribe
streamIdID of the remote video stream
mute• YES: Do not receive remote video streams
• NO: Receiving remote video stream (default)

Return Value

Discussion

Called after joining a channel

muteAllRemoteVideoStreams

Stops or resumes receiving to the video streams of all remote users.

- (int)muteAllRemoteVideoStreams:(BOOL)mute;

Parameters

ParametersDescribe
mute• YES: Do not receive remote video streams
• NO: Receiving remote video stream (default)

Return Value

Music File Playing

startPlayingMovie:cycle:

Start playing a music file

- (int) startPlayingMovie:(NSString * _Nonnull)filepath
                    cycle:(BOOL)cycle;

Parameters

ParametersDescribe
filepathPath to the music file. It can be a local file or an HTTP/HTTPS link
cycleWhether to start from the beginning automatically after playback, default is NO

Return Value

startPlayingMovie:cycle:view:paused:

Start playing a music file

- (int) startPlayingMovie:(NSString * _Nonnull)filepath
                    cycle:(BOOL)cycle
                     view:(VIEW_CLASS * _Nullable)view
                   paused:(BOOL)paused;

Parameters

ParametersDescribe
filepathPath to the music file. It can be a local file or an HTTP/HTTPS link
cycleWhether to start from the beginning automatically after playback, default is NO
viewUIView for viewing music files with videos, which can be null
pausedWhether to pause immediately after startup. The default value is NO

Return Value

stopPlayingMovie:

Stop playing a music file

- (int) stopPlayingMovie:(NSString * _Nonnull)filepath;

Parameters

ParametersDescribe
filepathSee startPlayingMovie:cycle:view:paused:

Return Value

pausePlayingMovie:

Pause playing a music file

- (int) pausePlayingMovie:(NSString * _Nonnull)filepath;

Parameters

ParametersDescribe
filepathSee startPlayingMovie:cycle:view:paused:

Return Value

resumePlayingMovie:

Continue playing a music file

- (int) resumePlayingMovie:(NSString * _Nonnull)filepath;

Parameters

ParametersDescribe
filepathSee startPlayingMovie:cycle:view:paused:

Return Value

getMovieInfo:

Get music file playback data

- (CloudHubLocalMovieInfo * _Nullable) getMovieInfo:(NSString * _Nonnull)filepath;

Parameters

ParametersDescribe
filepathSee startPlayingMovie:cycle:view:paused:

Return Value

getMovieCurrentPosition:

Get the playback progress of a music file

- (NSUInteger) getMovieCurrentPosition:(NSString * _Nonnull)filepath;

Parameters

ParametersDescribe
filepathSee startPlayingMovie:cycle:view:paused:

Return Value

setMoviePosition:withFile:

Sets the progress for the playing music file

- (int) setMoviePosition:(NSUInteger)pos 
                withFile:(NSString * _Nonnull)filepath;

Parameters

ParametersDescribe
posThe target time to move, in milliseconds
filepathSee startPlayingMovie:cycle:view:paused:

Return Value

Sound file playback

playEffect:filePath:loopCount:pitch:pan:gain:publish:startTimeMS:endTimeMS:

Start playing a sound file

- (int) playEffect:(int)soundId
          filePath:(NSString * _Nonnull)filepath
         loopCount:(int)loopCount
             pitch:(double)pitch
               pan:(double)pan
              gain:(int)gain
           publish:(BOOL)publish
       startTimeMS:(NSUInteger)starttime
         endTimeMS:(NSUInteger)endtime;

Parameters

ParametersDescribe
soundIdSelf - set sound Id, need to keep unique
filepathPath to the music file. It can be a local file or an HTTP/HTTPS link
loopCountSet the number of times the sound file is looping:
• 0: Play the sound file once
• 1: Loop the sound file twice
• -1: Play the sound file in an infinite loop until it stops when stopEffect: or stopAllEffects is invoked
pitchThe tone of the sound. The value range is [0.5,2.0]. The default value is 1.0, representing the original tone. The smaller the value, the lower the tone
panThe spatial location of sound effects. The value ranges from -1.0 to 1.0, for example:
• -1.0: Sound effects appear on the left
• 0.0: Sound effect appears directly ahead
• 1.0: Sound effects appear on the right
gainSet the volume of the sound effect
The value ranges from 0.0 to 100.0. The default value is 100.0. The smaller the value is, the lower the sound volume is
publishSets whether sound is transmitted to a remote end
• YES:When played locally in a sound file, remote users can also hear the sound
• NO:This sound can only be heard locally
starttimeSets the time (milliseconds) at which the file will start playing
endtimeSets the end time (ms) at which the file will end

Return Value

Discussion

This method can play specified local or online sound files to add sound effects to the application, such as the sound effects of specific actions in the game

In this method you can set the frequency and gain of playback of the sound file and whether the remote user can hear the sound. You can call this method many times and play multiple sound files simultaneously by passing in soundID and filePath of different sound files to achieve the best user experience. We recommend that no more than 3 sound files be played simultaneously

This method is invoked after the broadcast sound, will trigger rtcChannel:onAudioEffectFinish: callback

stopEffect:

Stops playing a sound file

- (int) stopEffect:(int)soundId;

Parameters

ParametersDescribe
soundIdIn playEffect:filePath:loopCount:pitch:pan:gain:publish:startTimeMS:endTimeMS: when the incoming sound Id

Return Value

stopAllEffects

Stops playing a sound file

- (int) stopAllEffects;

Return Value

preloadEffect:filePath:

Preloads the specified sound file into memory

- (int) preloadEffect:(int)soundId 
             filePath:(NSString * _Nonnull)filepath;

Parameters

ParametersDescribe
soundIdSelf - set sound Id, need to keep unique
filepathPath to the music file. It can be a local file or an HTTP/HTTPS link

Return Value

unloadEffect:

Releases a preloaded sound file from memory

- (int) unloadEffect:(int)soundId;

Parameters

ParametersDescribe
soundIdIn playEffect:filePath:loopCount:pitch:pan:gain:publish:startTimeMS:endTimeMS: when the incoming sound Id

Return Value

pauseEffect:

Pause playing a sound file

- (int) pauseEffect:(int)soundId;

Parameters

ParametersDescribe
soundIdIn playEffect:filePath:loopCount:pitch:pan:gain:publish:startTimeMS:endTimeMS: when the incoming sound Id

Return Value

pauseAllEffects

Pause all sound files

- (int) pauseAllEffects;

Return Value

resumeEffect:

Continue playing a sound file

- (int) resumeEffect:(int)soundId;

Parameters

ParametersDescribe
soundIdIn playEffect:filePath:loopCount:pitch:pan:gain:publish:startTimeMS:endTimeMS: when the incoming sound Id

Return Value

resumeAllEffects

Pause playing a sound file

- (int) resumeAllEffects;

Return Value

getEffectsVolume

Gets the sound file playback volume

- (int) getEffectsVolume;

Return Value

setEffectsVolume:

Setting the Volume of Sound Effect File Playback

- (int) setEffectsVolume:(int)volume;

Parameters

ParametersDescribe
volumeVolume value, range [0, 100], default is 100

Return Value

setVolumeOfEffect:volume:

Real-time adjustment of sound effect file playback volume in the range of [0, 100]

- (int) setVolumeOfEffect:(int)soundId 
                   volume:(int)volume;

Parameters

ParametersDescribe
soundIdIn playEffect:filePath:loopCount:pitch:pan:gain:publish:startTimeMS:endTimeMS: when the incoming sound Id
volumeVolume value, range [0, 100], default is 100

Return Value

CDN Push Streaming

addPublishStreamUrl:

Adding a push stream address

- (int) addPublishStreamUrl:(NSString* _Nonnull)url;

Parameters

ParametersDescribe
urlCDN push address, formatted as RTMP, the length of the string cannot exceed 1024 bytes, and the URL does not support special characters such as Chinese files.

Return Value

removePublishStreamUrl:

Delete push stream address

- (int) removePublishStreamUrl:(NSString* _Nonnull)url;

Parameters

ParametersDescribe
urlCDN push address in RTMP format, the length of the string cannot exceed 1024 bytes, and the URL does not support special characters such as Chinese files.

Return Value

setLiveTranscoding:

Set transcoding parameters

- (int) setLiveTranscoding:(CloudHubLiveTranscoding* _Nonnull)transcoding;

Parameters

ParametersDescribe
transcodingTranscoding parameters,See CloudHubLiveTranscoding

Return Value

Cross-channel media circulation

startChannelMediaRelay:

Start cross-channel media circulation

- (int) startChannelMediaRelay: (CloudHubChannelMediaRelayConfig* _Nonnull) config;

Parameters

ParametersDescribe
configConfigure cross-channel media transmission parameters,See CloudHubChannelMediaRelayConfig

Return Value

Discussion

After successfully calling the method, the SDK will trigger the rtcChannel:MediaRelayStateChanged:error: callback and report the current cross channel media stream forwarding status and events in the callback

Note

updateChannelMediaRelay:

Update channels for media circulation

- (int) updateChannelMediaRelay: (CloudHubChannelMediaRelayConfig* _Nonnull) config;

Parameters

ParametersDescribe
configCross-channel media transmission parameter configuration, See CloudHubChannelMediaRelayConfig

Return Value

Discussion

Call this method if you want to send the stream to multiple target channels or exit the current channel after you have successfully started forwarding media streams across channels

Note

stopChannelMediaRelay

Stop cross-channel media circulation

- (int) stopChannelMediaRelay;

Return Value

Discussion

Once stopped, the anchor will exit all target channels After this method is successfully invoked, the SDK triggers the [rtcChannel:MediaRelayStateChanged:error: callback. If CloudHub_RELAY_STATE_IDLE and CloudHub_RELAY_OK are reported, forwarding media streams has stopped.

Note

Advanced signaling method

These methods must all be called after joining the channel successfully

setPropertyOfUid:tell:properties:

Sets custom properties for a user in a channel

- (int)setPropertyOfUid:(NSString * _Nonnull)uid 
                   tell:(NSString * _Nullable)whom 
             properties:(NSString * _Nonnull)prop;

Parameters

ParametersDescribe
uidTarget user’s uid: from rtcChannel:didJoinedOfUid:properties:isHistory:fromChannel: callback
tellUser to be notified: if it is blank, all people in the channel will be notified. If a user’s uid is specified, only the users specified for notification will be notified. It is blank by default
propCustom attribute: must be a JSON object

Return Value

Discussion

There are two ways to set custom properties:

Note

sendChatMsg:to:withExtraData:

Sending a Chat Message

- (int)sendChatMsg:(NSString * _Nonnull)message 
                to:(NSString * _Nullable)whom 
     withExtraData:(NSString * _Nullable)extraData;

Parameters

ParametersDescribe
messageChat message text
whomUser to notify: If it is empty, all users in the channel are notified. If a user’s UID is specified, only the specified user is notified
extraDataThis message has custom attributes: it must be a JSON object and can be null

Return Value

Discussion

You can usually use extraData to pass information about fonts, avatars, and so on
Within the channel users will receivertcChannel:onChatMessageArrival:from:withExtraData: callback

pubMsg:msgId:to:withData:associatedWithUser:associatedWithMsg:save:extraData:

Publish a custom message

- (int)     pubMsg:(NSString * _Nonnull)msgName
             msgId:(NSString * _Nonnull)msgId
                to:(NSString * _Nullable)whom
          withData:(NSString * _Nullable)data
associatedWithUser:(NSString * _Nullable)uid
 associatedWithMsg:(NSString * _Nullable)assMsgID
              save:(BOOL)save
         extraData:(NSString * _Nullable)extra;

Parameters

ParametersDescribe
msgNameMessage name
msgIdMessage ID: The unique identifier of a message in a channel
whomUser to notify: If it is empty, all users in the channel are notified. If a user’s UID is specified, only the specified user is notified
dataMessage content: Must be a JSON string, which can be empty
uidUid of associated user: Once a message is associated with a user, the message is automatically deleted when the user exits
assMsgIdId of associated message: Once a message is associated with another message, this message is automatically deleted when the associated message is deleted
saveWhether to save:If I save it, After entering the channel user will in rtcChannel:onPubMsg:msgId:from:withData:associatedWithUser:associatedWithMsg:ts:withExtraData:isHistory: The signaling is received in the callback until the message is deleted using the delMsg:msgId:to: method
extraKeep parameters

Return Value

Discussion

PubMsg mechanism is similar to a message board, which is used to save and synchronize the business status within the channel,Whether you’re already in the channel, or if you’re new to it, Can pass rtcChannel:onPubMsg:msgId:from:withData:associatedWithUser:associatedWithMsg:ts:withExtraData:isHistory: callback received within the current channel has been released Custom message

delMsg:msgId:to:

Delete a custom message

- (int)delMsg:(NSString * _Nonnull)msgName
        msgId:(NSString * _Nonnull)msgId
           to:(NSString * _Nullable)whom;  

and

- (int)delMsg:(NSString * _Nonnull)msgName
        msgId:(NSString * _Nonnull)msgId
           to:(NSString * _Nullable)whom
     withData:(NSString * _Nullable)data;

Parameters

ParametersDescribe
msgNameMessage name
msgIdTo delete the message id,When publishing a message through the pubMsg:msgId:to:withData:associatedWithUser:associatedWithMsg:save:extraData: method, its ID will be specified
whomThe user to be notified, if empty, everyone in the channel will be notified, if the uid of a user is specified, only the user specified to be notified will be notified
dataKeep parameters

Return Value

Discussion

After the call is successful, users who are already in the channel will receive a rtcChannel:onDelMsg:msgId:from:withData: message

Note

evictUser:reason:

Kick a user out of the channel

- (int)evictUser:(NSString * _Nonnull)uid 
          reason:(NSInteger)reason;

Parameters

ParametersDescribe
uidUid of the kicked user
reasonCustom field

Return Value

Discussion

After the call is successful, the kicked user will receive a rtcChannel:onLocalUserEvicted: callback, and other users will receive a rtcChannel:didOfflineOfUid:reason: callback