TUICallEngine

TUICallEngine

tuicall-engine-webrtc is based on Tencent Cloud Instant Messaging IM and Real-time audio and video TRTC Audio and video communication components built by two paid PaaS services, supporting Audio and video calls in two-person and multi-person scenarios.

Methods

(static) createInstance(options)

Create a TUICallEngine instance

Example
let options = {
SDKAppID: 0, // You need to replace 0 with the SDKAppID of your cloud communication application when accessing
// The tim parameter is applicable to TIM instances that already exist in the business and needs to be passed in to ensure the uniqueness of the TIM instance.
tim: tim
};
let tuiCallEngine = TUICallEngine.createInstance(options);
Parameters:
Name Type Description
options Object required

Configuration

Properties
Name Type Description
SDKAppID Number required

SDKAppID of cloud communication application

tim ChatSDK

TIM instance (optional)

  • The tim parameter is applicable to TIM instances that already exist in the business and needs to be passed in to ensure the uniqueness of the TIM instance

(async) destroyInstance() → {Promise}

Destroy the TUICallEngine instance

  • Note: SDK will logout first and then release resources
Example
tuiCallEngine.destroyInstance().then(() => {
//success
}).catch(error => {
console.warn('destroyInstance error:', error)
});
Returns:
Type
Promise

setLogLevel(level)

Set the log level. Logs below the level will not be output.

Example
tuiCallEngine.setLogLevel(0);
Parameters:
Name Type Description
level LOG_LEVEL required

Log level

  • 0 Normal level, with a large amount of logs, is recommended for access
  • 1 main level, SDK outputs key information, default log level
  • 2 alarm level, the SDK only outputs alarm and error level logs
  • 3 error level, SDK only outputs error level logs
  • 4 No log level, SDK will not print any logs

on(eventName, callback, context)

Listening to events

Example
let onError = function(error) {
console.log(error);
};
tuiCallEngine.on(TUICallEvent.ERROR, onError, this);
Parameters:
Name Type Description
eventName String required

Event name

callback function required

Event response callback

context Any required

The context in which the callback is expected to be executed

off(eventName, callback, context)

Cancel listening events

Example
let onError = function(error) {
console.log(error)
};
tuiCallEngine.off(TUICallEvent.ERROR, onError, this);
Parameters:
Name Type Description
eventName String required

Event name

callback function required

Event response callback

context Any required

The context in which the callback is expected to be executed

(async) init() → {Promise}

An alias interface for the login() method, with the same parameters

Returns:
Type
Promise

(async) login(params) → {Promise}

Login interface, all functions need to be logged in before they can be used

Example
let promise = tuiCallEngine.login({userID: 'your userID', userSig: 'your userSig'});
promise.then(() => {
//success
}).catch(error => {
console.warn('login error:', error)
});
Parameters:
Name Type Description
params Object required

Login configuration

Properties
Name Type Description
userID String required

The ID of the current user, a string type, only allowed to contain English letters (az and AZ), numbers (0-9), hyphens (-) and underscores (_)

userSig String required

A security protection signature designed by Tencent Cloud. For how to obtain it, please refer to How to Calculate UserSig< /a>.

assetsPath String

AI noise reduction relies on denoiser-wasm.js, the CDN of file deployment or the path of the static resource server. For details, see: Use AI noise reduction.

Returns:
Type
Promise

(async) logout() → {Promise}

Log out of the interface. After logging out, you can no longer make calls

Example
let promise = tuiCallEngine.logout();
promise.then(() => {
//success
}).catch(error => {
console.warn('logout error:', error)
});
Returns:
Type
Promise

(async) call(params) → {Promise}

C2C invitation call, the invited party will receive the TUICallEvent.INVITED event

  • Note: Offline push is only available on terminals (Android or iOS), and is not supported by Web and WeChat mini programs.
Example
let promise = tuiCallEngine.call({userID: 'user1', type: 1});
promise.then(() => {
//success
}).catch(error => {
console.warn('call error:', error)
});
Parameters:
Name Type Description
params Object required

Dial call configuration

Properties
Name Type Description
userID String required

Invitee userID

type Number required

0-Unknown, 1-Voice call, 2-Video call

timeout Number

0 means no timeout, unit s (second) (optional) - default 30s

roomID Number

Numeric room number, range [1, 2147483647]. Support v1.4.2+ version.

userData String

Extension field: used to add extended information in invitation signaling. Support v1.4.2+ version.

offlinePushInfo Object

Customized offline message push (optional) -- tsignaling version required>= 0.8.0

name Type Description
title string Offline push title (optional)
description string Push content offline (optional)
androidOPPOChannelID string Offline push setting channel ID for OPPO mobile phone 8.0 system and above (optional)
extension string Push transparent content offline (optional) (tsignaling version>= 0.9.0)
Returns:
Type
Promise

(async) groupCall(params) → {Promise}

IM group invitation call, the invited party will receive the TUICallEvent.INVITED event
Note: Offline push is only available on terminals (Android or iOS), and is not supported by Web and WeChat mini programs.

Example
let promise = tuiCallEngine.groupCall({userIDList: ['user1', 'user2'], type: 1, groupID: 'IM group ID'});
promise.then(() => {
//success
}).catch(error => {
console.warn('groupCall error:', error)
});
Parameters:
Name Type Description
params Object required

Group chat call configuration

Properties
Name Type Description
userIDList Array required

Invitation list

type Number required

0-Unknown, 1-Voice call, 2-Video call

groupID String required

IM Group ID

timeout Number

0 means no timeout, unit s (second) (optional) - default 30s

roomID Number

Numeric room number, range [1, 2147483647]

userData String

Extension field: used to add extended information in invitation signaling

offlinePushInfo Object

Customized offline message push (optional) -- tsignaling version required>= 0.8.0

name Type Description
title string Offline push title (optional)
description string Push content offline (optional)
androidOPPOChannelID string Offline push setting channel ID for OPPO mobile phone 8.0 system and above (optional)
extension string Push transparent content offline (optional) (tsignaling version>= 0.9.0)
Returns:
Type
Promise

(async) joinInGroupCall(params)

Proactively join this group call.
Usage scenario: Users in the group actively join this group call.

Example
const params = {
roomID: 123,
type: 1,
groupID: '111'
};
tuiCallEngine.joinInGroupCall(params).then(() => {
//success
}).catch(error => {
console.error('joinInGroupCall error:', error);
});
Parameters:
Name Type Description
params Object required

Add configuration midway

Properties
Name Type Description
roomID Number required

The entered room number, the audio and video room ID of this call, currently only supports numeric room numbers, and subsequent versions will support string room numbers

type Number required

Call type, the media type of the call, for example: 1 - voice call, 2 - video call

groupID String required

Group ID for this group call

(async) inviteUser(params)

Invite others to invite users to join this group call.
Usage scenario: Used when a user in a group call actively invites others.

  • Only when the called party is connected and the call is ongoing can you invite others. For example: A calls B, and B can invite others only after B is connected.
  • The caller can invite others when he or she is on a call. For example: A calls B, whether B is connected or not, A can invite others.
Example
const userIDList = ['jack', 'john'];
const params = {
userIDList
};
tuiCallEngine.inviteUser(params).then(() => {
//success
}).catch(error => {
console.error('inviteUser error:', error);
});
Parameters:
Name Type Description
params Object required

Invite others to configure

Properties
Name Type Description
userIDList Array required

Invitation list

offlinePushInfo Object

Customized offline message push (optional) -- tsignaling version required>= 0.8.0

name Type Description
title string Offline push title (optional)
description string Push content offline (optional)
androidOPPOChannelID string Offline push setting channel ID for OPPO mobile phone 8.0 system and above (optional)
extension string Push transparent content offline (optional) (tsignaling version>= 0.9.0)

(async) accept() → {Promise}

When you receive the callback of the TUICallEvent.INVITED event as the invited party, you can call this interface to answer the call

Example
tuiCallEngine.on(TUICallEvent.INVITED, () => {
tuiCallEngine.accept().then(() => {
//success
}).catch(error => {
console.warn('accept error:', error);
});
});
Returns:
Type
Promise

(async) reject() → {Promise}

When you receive the callback of the TUICallEvent.INVITED event as the invited party, you can call this interface to reject the call

Example
tuiCallEngine.on(TUICallEvent.INVITED, () => {
tuiCallEngine.reject().then(() => {
//success
}).catch(error => {
console.warn('reject error:', error);
});
});
Returns:
Type
Promise

(async) hangup() → {Promise}

Hang up the current call. When you are on a call, you can call this function to end the call; when you are on a call, you can call this function to cancel the call

  1. When you are on a call, you can call this interface to end the call
  2. Can be used to cancel the call when no call is made
Example
tuiCallEngine.hangup().then(() => {
//success
}).catch(error => {
console.warn('hangup error:', error);
});
Returns:
Type
Promise

(async) startRemoteView(params) → {Promise}

Start remote screen rendering. Please wait until you receive USER_VIDEO_AVAILABLE When an event occurs and the isVideoAvailable parameter in the event is true, this interface can be called to render the remote user's camera data to the specified dom id node.

Example
let options = {
objectFit: 'contain'
}
let promise = tuiCallEngine.startRemoteView({userID: 'user1', videoViewDomID: 'video_1', options});
promise.then(() => {
//success
}).catch(error => {
console.warn('startRemoteView error:', error)
});
Parameters:
Name Type Description
params Object required

Rendering remote video configuration

Properties
Name Type Description
userID String required

User ID

videoViewDomID String required

The user data will be rendered into the dom id node

options String

Playback options

Properties
Name Type Description
objectFit String required

Video screen display mode

  • contain gives priority to ensuring that all video content is displayed. The video size is scaled proportionally until one side of the video window is aligned with the window border. If the video size is inconsistent with the display window size, the video will be scaled to fill the window while maintaining the aspect ratio. There will be a black border around the scaled video.

  • cover gives priority to ensuring that the window is filled. The video size is scaled proportionally until the entire window is filled with video. If the video length and width are different from the display window, the video stream will be cropped or stretched according to the proportion of the display window to fill the window.

  • fill ensures that the window is filled and all video content is displayed, but it does not guarantee that the video size ratio remains unchanged. The width and height of the video will be stretched to match the size of the viewport.

    Playing video streams uses cover mode by default.

muted Boolean required

Do you need mute sound

  • For local streams, muted defaults to true, preventing sound collected from the microphone from being played.
mirror Boolean required

Whether to enable video mirror preview Note

  • For local audio and video streams, mirror preview is enabled by default. It is recommended to turn on mirroring when using the front camera and turn off mirroring when using the rear camera.
  • For remote audio and video streams, mirror preview is turned off by default.
  • For screen sharing streams, turning on mirror preview is not supported.
  • This parameter is only valid for local preview, and there is no mirroring effect for push streaming.
Returns:
Type
Promise

(async) stopRemoteView(params) → {Promise}

Stop remote screen rendering

Example
let promise = tuiCallEngine.stopRemoteView({userID: 'user1'});
promise.then(() => {
//success
}).catch(error => {
console.warn('stopRemoteView error:', error)
});
Parameters:
Name Type Description
params Object required

Rendering remote video configuration

Properties
Name Type Description
userID String required

User ID

Returns:
Type
Promise

(async) startLocalView(params) → {Promise}

Start local screen rendering.

Deprecated:
  • It will be gradually abolished after version v1.3.2. You can call [openCamera](https://web.sdk.qcloud.com/component/trtccalling/doc/TUICallEngine/web/TUICallEngine.html#openCamera) to open the camera and preview it. .
Example
let promise = tuiCallEngine.startLocalView({userID: 'user1', videoViewDomID: 'video_1'});
promise.then(() => {
//success
}).catch(error => {
console.warn('startLocalView error:', error)
});
Parameters:
Name Type Description
params Object required

Render local video configuration

Properties
Name Type Description
userID String required

User ID

videoViewDomID String required

The user data will be rendered into the dom id node

options String

Playback options

Properties
Name Type Description
objectFit String required

Video screen display mode

  • contain gives priority to ensuring that all video content is displayed. The video size is scaled proportionally until one side of the video window is aligned with the window border. If the video size is inconsistent with the display window size, the video will be scaled to fill the window while maintaining the aspect ratio. There will be a black border around the scaled video.

  • cover gives priority to ensuring that the window is filled. The video size is scaled proportionally until the entire window is filled with video. If the video length and width are different from the display window, the video stream will be cropped or stretched according to the proportion of the display window to fill the window.

  • fill ensures that the window is filled and all video content is displayed, but it does not guarantee that the video size ratio remains unchanged. The width and height of the video will be stretched to match the size of the viewport.

    Playing video streams uses cover mode by default.

muted String required

Do you need mute sound

  • For local streams, muted defaults to true, preventing sound collected from the microphone from being played.
mirror String required

Whether to enable video mirror preview Note

  • For local audio and video streams, mirror preview is enabled by default. It is recommended to turn on mirroring when using the front camera and turn off mirroring when using the rear camera.
  • For remote audio and video streams, mirror preview is turned off by default.
  • For screen sharing streams, turning on mirror preview is not supported.
  • This parameter is only valid for local preview, and there is no mirroring effect for push streaming.
Returns:
Type
Promise

(async) stopLocalView(params) → {Promise}

Stop remote screen rendering

Deprecated:
  • It will be gradually abolished after version v1.3.2. You can call [closeCamera](https://web.sdk.qcloud.com/component/trtccalling/doc/TUICallEngine/web/TUICallEngine.html#closeCamera) to open the camera and preview it. .
Example
let promise = tuiCallEngine.stopLocalView({userID: 'user1'});
promise.then(() => {
//success
}).catch(error => {
console.warn('stopLocalView error:', error)
});
Parameters:
Name Type Description
params Object required

Render local video configuration

Properties
Name Type Description
userID String required

User ID TODO: Parameters can be left blank and will be confirmed later

Returns:
Type
Promise

(async) openCamera(videoViewDomID, isFrontCameraopt) → {Promise}

You can call this interface to turn on the camera, and the user in the call will receive the USER_VIDEO_AVAILABLE callback

Example
// 'localView' is the id value corresponding to the div tag
tuiCallEngine.openCamera('localView').then(() => {
//success
}).catch(error => {
console.warn('openCamera error:', error)
});
Parameters:
Name Type Description
videoViewDomID string required

The user data will be rendered into the dom id node

isFrontCamera boolean

Front and rear cameras, true means front camera. Only supported on mobile devices

Returns:

Note:

  • When passing in an elementId of string type, you need to ensure that the elementId is in the DOM, otherwise an error will be reported when calling the interface.
  • The business side can adjust the css width and height of the DOM element to control the width and height of the video tag display.
Type
Promise

(async) closeCamera() → {Promise}

You can call this interface to turn off the camera, and the user in the call will receive the USER_VIDEO_AVAILABLE callback

Example
tuiCallEngine.closeCamera().then(() => {
//success
}).catch(error => {
console.warn('closeCamera error:', error)
});
Returns:
Type
Promise

(async) openMicrophone() → {Promise}

Turn on the microphone and the user in the call will receive the USER_AUDIO_AVAILABLE callback

Example
tuiCallEngine.openMicrophone().then(() => {
//success
}).catch(error => {
console.warn('openMicrophone error:', error)
});
Returns:
Type
Promise

(async) closeMicrophone() → {Promise}

Turn off the microphone and the user in the call will receive the USER_AUDIO_AVAILABLE callback

Example
tuiCallEngine.closeMicrophone().then(() => {
//success
}).catch(error => {
console.warn('closeMicrophone error:', error)
});
Returns:
Type
Promise

(async) setVideoQuality(profile) → {Promise}

Set video resolution

Example
const profile = '720p';
//Set video quality to 720p
tuiCallEngine.setVideoQuality(profile).then(() => {
//success
}).catch(error => {
console.warn('setVideoQuality error:', error)
});
Parameters:
Name Type Description
profile String required

Video profile

Video Profile Resolution (width x height)
480p 640 x 480
720p 1280 x 720
1080p 1920 x 1080
  • iOS Safari does not support capturing 1080p
  • Due to device and browser limitations, the video resolution may not match exactly. In this case, the browser will automatically adjust the resolution to be close to the resolution corresponding to the Profile.
  • Uses 480p by default.
Returns:
Type
Promise

(async) setVideoRenderParams(params)

Set the display mode of user video screen

Parameters:
Name Type Description
params ITRTCRenderParams required

Display parameters

Properties
Name Type Description
userID String required

User ID. When userID is not passed in, the display mode is set for all previews (including: local preview and all remote previews)

objectFit String required

Video screen display mode. Currently only supported: 'contain' | 'cover' | 'fill'

  • contain gives priority to ensuring that all video content is displayed. The video size is scaled proportionally until one side of the video window is aligned with the window border. If the video size is inconsistent with the display window size, the video will be scaled to fill the window while maintaining the aspect ratio. There will be a black border around the scaled video. v3.0.0 Obsolete
  • cover gives priority to ensuring that the window is filled. The video size is scaled proportionally until the entire window is filled with video. If the video length and width are different from the display window, the video stream will be cropped or stretched according to the proportion of the display window to fill the window.
  • fill ensures that the window is filled and all video content is displayed, but it does not guarantee that the video size ratio remains unchanged. The width and height of the video will be stretched to match the size of the viewport. Playing video streams uses cover mode by default.
muted String required

Do you need mute sound? v3.0.0 obsolete

  • For local streams, muted defaults to true, preventing sound collected from the microphone from being played.
mirror TRTCVideoMirrorType required

Whether to enable video mirror preview

rotation TRTCVideoRotation required

Video screen rotation direction Note

  • For local audio and video streams, mirror preview is enabled by default. It is recommended to turn on mirroring when using the front camera and turn off mirroring when using the rear camera.
  • For remote audio and video streams, mirror preview is turned off by default.
  • For screen sharing streams, turning on mirror preview is not supported.
  • This parameter is only valid for local preview, and there is no mirroring effect for push streaming.

(async) switchCallMediaType(newMediaType)

Current call type switching

  • Only supported during 1v1 calls
  • Failed to monitor ERROR event, code: 60001
Example
tuiCallEngine.switchCallMediaType(1).then(() => { // Switch video call to voice call
//success
}).catch(error => {
console.warn('switchCallMediaType error:', error)
});
Parameters:
Name Type Description
newMediaType String required

Call type

  • 1 Voice call
  • 2 Video Call

(async) getDeviceList(deviceType)

Get device list

Example
tuiCallEngine.getDeviceList('camera').then((devices)=>{ // Get the camera list
console.log(devices)
}).catch(error => {
console.warn('getDeviceList error:', error)
});
Parameters:
Name Type Description
deviceType String required

Device type

  • 'camera' camera
  • 'microphones' Microphone, 'microphones' will be abandoned later. v3.0.0+ supports incoming 'microphone'
  • 'speaker' speaker, v3.0.0+ only supports this parameter

(async) switchCamera(cameraPosition)

Switch front and rear cameras
Note: v3.0.0+ is supported, and this interface is only effective on mobile terminals.

Example
await tuiCallEngine.switchCamera(TUICallCameraPosition.FRONT); // Switch front camera
await tuiCallEngine.switchCamera(TUICallCameraPosition.BACK); // Switch the rear camera
Parameters:
Name Type Description
cameraPosition TUICallCameraPosition required

Camera type

  • TUICallCameraPosition.FRONT front camera
  • TUICallCameraPosition.BACK rear camera

(async) switchDevice(params)

Switch camera or microphone device

Example
let promise = tuiCallEngine.switchDevice({deviceType: 'camera', deviceId: cameras[0].deviceId}) // Switch device
promise.then(() => {
//success
}).catch(error => {
console.warn('switchDevice error:', error)
});
Parameters:
Name Type Description
params ISwitchDeviceParams required
Properties
Name Type Description
deviceType string required

Device type that needs to be switched

  • 'video' camera, 'video' will be abandoned later. v3.0.0+ supports passing 'camera' to switch cameras.
  • 'audio' microphone, 'audio' will be abandoned later. v3.0.0+ supports passing in 'microphone' to switch microphones.
  • 'speaker' speaker, v3.0.0+ supported
deviceId string required

Device ID that needs to be switched

  • The camera device identifier is obtained through getDeviceList('camera').
  • The microphone device ID is obtained through getDeviceList('microphone').
  • The speaker device ID is obtained through getDeviceList('speaker').

(async) setSelfInfo(params)

Set your own nickname or avatar

Example
let promise = tuiCallEngine.setSelfInfo({
nickName: 'Jack',
avatar:'http(s)://url/to/image.jpg'
});
promise.then(() => {
//success
}).catch(error => {
console.warn('setSelfInfo error:', error);
});
Parameters:
Name Type Description
params ISwitchDeviceParams required
Properties
Name Type Description
nickName string required

Nickname

avatar string required

Avatar address

enableMultiDeviceAbility(enable) → {void}

Enable/disable TUICallEngine's multi-device login mode (Exclusive version package support)

  • Note: Only supported in v2.1.1+.
Example
tuiCallEngine.enableMultiDeviceAbility(true);
Parameters:
Name Type Description
enable boolean required

Enable and disable multi-device login. On: true; Off: false; Default: Off

Returns:
Type
void

(async) enableAIVoice(enable)

Turn on/off AI noise reduction

Example
let promise = tuiCallEngine.enableAIVoice(true);
promise.then(() => {
//success
}).catch(error => {
console.warn('enableAIVoice error:', error)
});
Parameters:
Name Type Description
enable boolean required

Turn on and off AI noise reduction. true means on; false means off

(async) setBlurBackground(blurLevel) → {Promise}

Switch/set picture background blur
Note: v3.0.5+ Supported, H5 is not supported currently, and will be supported in the future.

Example
await tuiCallEngine.setBlurBackground(1);
Parameters:
Name Type Description
blurLevel number required

Blur level, 0 - means background blur is turned off. The setting of blurLevel level is currently not supported and will be supported in the future. Requires blurLevel > 0 when using

Returns:
Type
Promise

(async) setVirtualBackground(imagePath) → {Promise}

Switch/set picture background blur
Note: v3.0.5+ Supported, H5 is not supported currently, and will be supported in the future.

Example
await tuiCallEngine.setVirtualBackground('https://xxx.png');
Parameters:
Name Type Description
imagePath string required

Image path (can be a url or a relative path). imagePath = '' means turning off image background blur.

Returns:
Type
Promise