TcrSession Class Reference

Inherits from NSObject
Declared in TcrSession.h

– initWithParams:andDelegate:

Initialize local resources, asynchronously callback results

- (instancetype _Nonnull)initWithParams:(NSDictionary *_Nullable)params andDelegate:(id<TcrSessionObserver> _Nonnull)Observer

Parameters

params

Optional, the following key-value pairs can be selected: - @“preferredCodec”: Optional values are @“H264”, @“H265”, @“VP8”, and @“VP9”. Used to set the preferred codec. If this field is set, the session will try to use the preferred codec for communication. If the preferred codec is not available, other available codecs will be used. If this field is not set or the setting is invalid, the session will use the default codec.

  • @“preferredCodecList”: The value is an NSArray, which contains the optional values @“H264”, @“H265”, @“VP8”, and @“VP9”. Indicate preferred codecs, where the order of the elements in the list represents priority, such as index 0 being the highest priority preferred codec. If the set codecs cannot be selected for various reasons, other available codecs will be chosen.

  • @“idleThreshold”: The idle detection threshold, that is, the duration of user inactivity. The unit is Millisecond. When this threshold is reached, the event TcrEvent.CLIENT_IDLE will be triggered.

  • @“local_video”: Optional value is of bool type. Used to enable the local camera.

  • @“local_audio”: Optional value is of bool type. Used to enable the local microphone.

  • @“enableCustomVideoCapture”: @{@“captureWidth”:NSInteger, @“captureHeight”:NSInteger, @“captureFps”: NSInteger}, enable custom video capture and bring the resolution and fps of the custom captured video (both parameters are required). e.g. @“enableCustomVideoCapture”:@{@“captureWidth”:@(720), @“captureHeight”:@(1280), @“captureFps”:@(30)} In addition, to enable custom video capture, you also need to set @“local_video” to enable local video upstream.

  • @“enableCustomAudioCapture”:@{@“sampleRate”:NSInteger, @“useStereoInput”: BOOL}, enable custom audio capture and bring the sample rate and channel count of the custom captured audio (both parameters are required). e.g. @“enableCustomAudioCapture”:@{@“sampleRate”:@(48000), @“useStereoInput”:@(false)} means a sample rate of 48000 and mono data. In addition, to enable custom audio capture, you also need to set @“local_audio” to enable local audio upstream.

  • @“remoteDesktopResolution”:@{@“width”:NSInteger , @“height”:NSInteger} ,Set the resolution of Cloud Desktop. If the cloud PC application is in full-screen mode, the resolution of the downstream video stream will also change accordingly. NOTE:This param is only for PC application, and the mobile application is not supported.

  • @“sessionMode”: Optional values are @“ExclusiveSession” or @“SharedSession”. Default is @“SharedSession”. @“ExclusiveSession” will request the cloud instance to disconnect other client streaming connections, while @“SharedSession” allows keeping other client connections.

  • @“audioSessionCategoryOptions”: Optional. An NSNumber wrapping AVAudioSessionCategoryOptions. Applied whenever the SDK writes AVAudioSession on mic on/off, overriding the SDK default options entirely (mic on: AllowBluetooth | DefaultToSpeaker; mic off: 0).

  • @“audioSessionMode”: Optional. An AVAudioSessionMode value, e.g. AVAudioSessionModeDefault. Applied whenever the SDK writes AVAudioSession on mic on/off, overriding the SDK default mode (mic on: AVAudioSessionModeVoiceChat for system-level echo cancellation; mic off: AVAudioSessionModeDefault). Typical use: coexisting with third-party audio SDKs whose voice processing conflicts with VoiceChat mode and suppresses capture volume.

IMPORTANT: this key only controls the mode the SDK writes explicitly. It cannot prevent the implicit override: whenever a VoiceProcessingIO (VPIO) AudioUnit has its input side enabled, iOS forces the session mode to VoiceChat (the system AEC/AGC chain is tied to the VPIO + chat-mode combination), and this implicit override does not go through AVAudioSession’s ObjC interface, so neither this key nor TCRAudioSessionDelegate can intercept it. - SDK internal capture uses VPIO: mic-on enables its input, so the mode will still be pulled to VoiceChat regardless of this key. - With custom audio capture (enableCustomAudioCapture), the SDK’s capture VPIO keeps its input disabled, so the implicit override is not triggered — provided the custom capturer itself does NOT use VPIO (e.g. uses RemoteIO). If the custom capturer uses VPIO, its own input-enable will again pull the mode to VoiceChat.

  • @“audioSessionCategory”: Reserved. The SDK always forces the category according to mic state (PlayAndRecord when the mic is on, Playback when off), so this key currently has no effect.

When both mechanisms are used, the priority is: TCRAudioSessionDelegate > the audio keys above > SDK defaults. For typical audio-coexistence needs, prefer these declarative keys over TCRAudioSessionDelegate.

Observer

The delegate of the TcrSession, listening for callback of events.

Declared In

TcrSession.h

– setTcrSessionObserver:

setOberServer for session

- (void)setTcrSessionObserver:(id<TcrSessionObserver> _Nonnull)Observer

Parameters

Observer

session Observer

Declared In

TcrSession.h

– start:

Starts the session. This method should only be called once.

- (BOOL)start:(NSString *_Nonnull)serverSession

Parameters

serverSession

The ServerSessionreturned from CreateSessionAPI.

Return Value

true if success, false otherwise.

Declared In

TcrSession.h

– releaseSession

Release the session.
The session will disconnect from the sever, and the local resources of this session will be released. Once released, this session instance cannot be used anymore.

- (void)releaseSession

Declared In

TcrSession.h

– getRequestId

Get the current connection’s requestId.

- (NSString *_Nonnull)getRequestId

Discussion

It takes effect after calling TcrSession.start().

Declared In

TcrSession.h

– setRenderView:

Set the rendering view for this session, and thus the SDK will render the streaming content to the view.

- (void)setRenderView:(TcrRenderView *_Nullable)renderView

Parameters

renderView

The rendering view to be set.

Declared In

TcrSession.h

– removeRenderView:

Remove the rendering view for this session.

- (void)removeRenderView:(TcrRenderView *_Nullable)renderView

Parameters

renderView

The rendering view to be removed.

Declared In

TcrSession.h

– setVideoSink:

Sets a video sink for this session. After that, the SDK will callback the decoded video frame data to the videoSink.

- (void)setVideoSink:(id<VideoSink> _Nullable)videoSink

Parameters

videoSink

The view sink to be set.This can be null to remove any existing one.

Discussion

You may use this interface to post-process or render video images.

Declared In

TcrSession.h

– setAudioSink:

Sets a audio sink for this session. After that, the SDK will callback the audio data to the audioSink

- (void)setAudioSink:(id<AudioSink> _Nullable)audioSink

Parameters

audioSink

The audio sink to be set.

Declared In

TcrSession.h

– setEnableAudioPlaying:

Set whether the SDK plays audio.

- (void)setEnableAudioPlaying:(BOOL)enable

Parameters

enable

true to enable audio playback, false otherwise.

Declared In

TcrSession.h

– setEnableLocalAudio:

Enable or disable the local audio track that is captured from the mic.

- (void)setEnableLocalAudio:(BOOL)enable

Parameters

enable

true to enable the local audio, false otherwise.

Declared In

TcrSession.h

– setEnableLocalVideo:

Enable or disable the local video track that is captured from the camera.

- (void)setEnableLocalVideo:(BOOL)enable

Parameters

enable

true to enable the local video, false otherwise.

Declared In

TcrSession.h

– pauseStreaming

Pause the media stream.

- (void)pauseStreaming

Declared In

TcrSession.h

– resumeStreaming

Resume the media stream.

- (void)resumeStreaming

Declared In

TcrSession.h

– setRemoteVideoProfile:minBitrate:maxBitrate:

Set the remote video profile.

- (void)setRemoteVideoProfile:(int)fps minBitrate:(int)minBitrate maxBitrate:(int)maxBitrate

Parameters

fps

The frame rate. Value range: [10,60]. Default value: 60.

minBitrate

The minimum bitrate in Kbps. Value range: [1000,15000]. Default value: 1000.

maxBitrate

The maximum bitrate in Kbps. Value range: [1000,15000]. Default value: 15000.

Declared In

TcrSession.h

– setRemoteVideoProfile:minBitrate:maxBitrate:width:height:

Set the remote video profile.

- (void)setRemoteVideoProfile:(int)fps minBitrate:(int)minBitrate maxBitrate:(int)maxBitrate width:(int)width height:(int)height

Parameters

fps

The frame rate. Value range: [10,60]. Default value: 60.

minBitrate

The minimum bitrate in Kbps. Value range: [1000,15000]. Default value: 1000.

maxBitrate

The maximum bitrate in Kbps. Value range: [1000,15000]. Default value: 15000.

width

The video resolution width. Valid range: 128 to 1920 pixels.

height

The video resolution height. Valid range: 128 to 1920 pixels.

Declared In

TcrSession.h

– setLocalVideoProfile:height:fps:minBitrate:maxBitrate:isFrontCamera:

Set the local video profile.

- (void)setLocalVideoProfile:(int)width height:(int)height fps:(int)fps minBitrate:(int)minBitrate maxBitrate:(int)maxBitrate isFrontCamera:(BOOL)isFrontCamera

Parameters

width

The frame width, range[128, 1920]. Suggested value: 1280.

height

The frame height, range[128, 1920]. Suggested value: 720.

fps

The frame rate must be greater than 0 Default value: 30.

minBitrate

The minimum bitrate in Kbps. Value range: [1000,15000]. Default value: 1000.

maxBitrate

The maximum bitrate in Kbps. Value range: [1000,15000]. Default value: 15000.

Declared In

TcrSession.h

– setLocalVideoProfile:height:fps:minBitrate:maxBitrate:isFrontCamera:degrationPreference:

Set the local video profile.

- (void)setLocalVideoProfile:(int)width height:(int)height fps:(int)fps minBitrate:(int)minBitrate maxBitrate:(int)maxBitrate isFrontCamera:(BOOL)isFrontCamera degrationPreference:(RTCDegradationPreference)degrationPreference

Parameters

width

The frame width, range[128, 1920]. Suggested value: 1280.

height

The frame height, range[128, 1920]. Suggested value: 720.

fps

The frame rate must be greater than 0 Default value: 30.

minBitrate

The minimum bitrate in Kbps. Value range: [1000,15000]. Default value: 1000.

maxBitrate

The maximum bitrate in Kbps. Value range: [1000,15000]. Default value: 15000.

degrationPreference

Specifies the preferred way the WebRTC layer should handle optimizing bandwidth against quality in constrained-bandwidth situations. The possible values are RTCDegradationPreferenceDisabled, RTCDegradationPreferenceMaintainFramerate, RTCDegradationPreferenceMaintainResolution or RTCDegradationPreferenceBalanced. The default value is RTCDegradationPreferenceBalanced.

Declared In

TcrSession.h

– setRemoteAudioProfile:

Set the playing profile of the remote audio.

- (void)setRemoteAudioProfile:(float)volume

Parameters

volume

The volume scalar in the range of [0,10] that will be set on this remote audio stream.

Declared In

TcrSession.h

– restartCloudApp

Restart the cloud application process.

- (void)restartCloudApp

Declared In

TcrSession.h

– pasteText:

Send the text to the input box in the cloud application.
The input box of the cloud application must have obtained the focus and allow the user to paste text from the clipboard.

- (void)pasteText:(NSString *_Nonnull)text

Parameters

text

The text to be sent

Discussion

For Android cloud applications, sent text replaces the input box content.
For Windows cloud applications, sent text is added to the existing content in the input box.

Declared In

TcrSession.h

– inputText:mode:

Inputs text to cloud device without modifying clipboard.

- (void)inputText:(NSString *_Nonnull)text mode:(BOOL)append

Parameters

text

Text to input (non-null).

append

Writing mode control: - YES: Append mode (default). Inserts text at the current cursor position in the cloud input field. - NO: Override mode. Clears the cloud input field and replaces its content with the provided text.

Discussion

This method is available only when the client switches to local input method mode. It sends text directly to the cloud device’s input field and does not alter the local clipboard content.

Note: Key constraints and behaviors: 1. Input method dependency: Only effective when IME_TYPE = local; otherwise, the call has no effect. 2. Clipboard isolation: Text will not be written to the clipboard, preventing contamination of user clipboard data.

@example Example usage: // Append mode (default) [device inputText:@“Hello” mode:YES];

// Override mode [device inputText:@“New Text” mode:NO];

Declared In

TcrSession.h

– inputText:mode:indexAfterOverride:

Inputs text to cloud device without modifying clipboard.

- (void)inputText:(NSString *_Nonnull)text mode:(BOOL)isOverride indexAfterOverride:(int)indexAfterOverride

Parameters

text

Text to input (non-null). @isOverride append Writing mode control: - YES: Override mode. Clears the cloud input field and replaces its content with the provided text. - NO: Append mode (default). Inserts text at the current cursor position in the cloud input field.

indexAfterOverride

The cursor position after override (only effective in override mode)

Discussion

This method is available only when the client switches to local input method mode. It sends text directly to the cloud device’s input field and does not alter the local clipboard content.

Note: Key constraints and behaviors: 1. Input method dependency: Only effective when IME_TYPE = local; otherwise, the call has no effect. 2. Clipboard isolation: Text will not be written to the clipboard, preventing contamination of user clipboard data.

@example Example usage: // Override mode (default) [device inputText:@“Hello” mode:YES indexAfterOverride:1];

// Append mode [device inputText:@“New Text” mode:NO];

Declared In

TcrSession.h

– setDisableCloudInput:

Disable the Cloud input.
When the cloud input is disable, the cloud application’s soft keyboard won’t appear.

This function is only supported for mobile cloud applications.

- (void)setDisableCloudInput:(BOOL)disableCloudInput

Parameters

disableCloudInput

true disables the cloud input.
false enables the cloud input, allowing the soft keyboard to appear for user interaction with the cloud application via touch screen.

Declared In

TcrSession.h

– setRemoteDesktopResolution:height:

Set the resolution of Cloud Desktop. If the cloud PC application is in full-screen mode, the resolution of the downstream video stream will also change accordingly.
This method is currently only valid for scenarios where the cloud is a PC application, and the scenario where the cloud is a mobile application is to be supported.

- (void)setRemoteDesktopResolution:(int)width height:(int)height

Parameters

width

Width of cloud desktop.

height

Height of cloud desktop.

Declared In

TcrSession.h

– sendCustomAudioData:captureTimeNs:

Send custom audio data.
This method is only effective when custom audio capture is enabled.
To enable custom audio capture, see initWithParams

- (BOOL)sendCustomAudioData:(NSData *_Nonnull)audioData captureTimeNs:(uint64_t)captureTimeNs

Parameters

audioData

The non-null NSData object containing the PCM data(16-bit) to be sent.

captureTimeNs

The capture time of the audio data in nanoseconds.

Return Value

The result of send custom audio data.

Declared In

TcrSession.h

– sendCustomVideoPixelBuffer:rotation:captureTimeNs:

Send custom video data.
This method is only effective when custom video capture is enabled.
To enable custom video capture, see initWithParams

- (BOOL)sendCustomVideoPixelBuffer:(CVPixelBufferRef _Nonnull)pixelBuffer rotation:(RTCVideoRotation)rotation captureTimeNs:(uint64_t)captureTimeNs

Parameters

pixelBuffer

The non-null CVPixelBufferRef object containing the frame data to be sent.

rotation

The rotation of video frame.

captureTimeNs

The capture time of the video frame data in nanoseconds.

Return Value

The result of send custom video data.

Declared In

TcrSession.h

– getKeyboard

Return the interface to interact with the cloud keyboard in this session.

- (id<Keyboard> _Nonnull)getKeyboard

Return Value

The interface to interact with the cloud keyboard in this session.

Declared In

TcrSession.h

– getMouse

Return the interface to interact with the cloud Mouse in this session.

- (id<Mouse> _Nonnull)getMouse

Return Value

The interface to interact with the cloud Mouse in this session.

Declared In

TcrSession.h

– getGamepad

Return the interface to interact with the cloud Gamepad in this session.

- (id<Gamepad> _Nonnull)getGamepad

Return Value

The interface to interact with the cloud Gamepad in this session.

Declared In

TcrSession.h

– getTouchScreen

Return the interface to interact with the cloud TouchScreen in this session.

- (id<TouchScreen> _Nonnull)getTouchScreen

Return Value

The interface to interact with the cloud TouchScreen in this session.

Declared In

TcrSession.h

– getMotionSensor

Return the interface to interact with the cloud MotionSensor in this session.

- (id<MotionSensor> _Nonnull)getMotionSensor

Return Value

The interface to interact with the cloud MotionSensor in this session.

Declared In

TcrSession.h

– sendKeycodeMessage:

send keycode message to cloud

- (void)sendKeycodeMessage:(NSDictionary *_Nonnull)msg

Declared In

TcrSession.h

– createCustomDataChannel:observer:

Creates a custom data channel.

- (CustomDataChannel *_Nonnull)createCustomDataChannel:(int)port observer:(id<CustomDataChannelObserver> _Nullable)observer

Parameters

port

The cloud port number uniquely identifying the data channel.

observer

The CustomDataChannel.CustomDataChannelObserver object .

Return Value

the created data channel.

Declared In

TcrSession.h

– changeSeat:targetRole:targetPlayerIndex:blk:

Switch the role and seat of a user (userID) to targetRole and targetPlayerIndex respectively.

- (void)changeSeat:(NSString *_Nonnull)userId targetRole:(NSString *_Nonnull)targetRole targetPlayerIndex:(int)targetPlayerIndex blk:(void ( ^ _Nullable ) ( int retCode ))finishBlk

Parameters

userId

The target user ID

targetRole

The target role,. valid value: ( ‘player’ / ‘viewer’ )

targetPlayerIndex

The target seat. This parameter can take effect only for the Player role and will be 0 for the Viewer role.

finishBlk

Execution result callback. retcode: TcrCode#ErrMultiPlayerBaseCode

Declared In

TcrSession.h

– requestChangeSeat:targetRole:targetPlayerIndex:blk:

Apply to the room owner to switch the role and seat of a player (userID) to targetRole and targetPlayerIndex respectively.

- (void)requestChangeSeat:(NSString *_Nonnull)userId targetRole:(NSString *_Nonnull)targetRole targetPlayerIndex:(int)targetPlayerIndex blk:(void ( ^ _Nullable ) ( int retCode ))finishBlk

Parameters

userId

The target user ID

targetRole

The target role,. valid value: ( ‘player’ / ‘viewer’ )

targetPlayerIndex

The target seat. This parameter can take effect only for the Player role and will be 0 for the Viewer role.

finishBlk

Execution result callback. retcode: TcrCode#ErrMultiPlayerBaseCode

Declared In

TcrSession.h

– setMicMute:micStatus:blk:

Apply to the room owner to switch the role and seat of a player (userID) to targetRole and targetPlayerIndex respectively.

- (void)setMicMute:(NSString *_Nonnull)userId micStatus:(int)micStatus blk:(void ( ^ _Nullable ) ( int retCode ))finishBlk

Parameters

userId

The target user ID

micStatus

The mic Status set.

finishBlk

Execution result callback. retcode: TcrCode#ErrMultiPlayerBaseCode

Declared In

TcrSession.h

– syncRoomInfo

Apply to synchronize room information and return the result through TcrEvent#MULTI_USER_SEAT_INFO

- (void)syncRoomInfo

Declared In

TcrSession.h

+ setAudioSessionDelegate:

Set the audio session delegate to take over AVAudioSession management.

+ (void)setAudioSessionDelegate:(id<TCRAudioSessionDelegate> _Nonnull)delegate

Parameters

delegate

The delegate to set. Passing nil is a no-op.

Discussion

Advanced API — prefer the declarative audio keys of initWithParams:andDelegate: for typical audio-coexistence needs. Must be called before creating any TcrSession and takes effect only once per process. The delegate is held weakly; keep it alive for the whole session lifetime. See TCRAudioSessionDelegate for the full contract and warnings.

Declared In

TcrSession.h