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
|
(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
|
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
|
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
|
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
|
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
|
(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
|
(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
- When you are on a call, you can call this interface to end the call
- 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
|
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
|
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
|
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
|
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
|
Returns:
- Type
- Promise
(async) setVideoRenderParams(params)
Set the display mode of user video screen
Parameters:
Name | Type | Description | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
params |
ITRTCRenderParams |
required
Display parameters Properties
|
(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
|
(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
|
(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
|
(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
|
(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
|
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
- Supported after version 1.2.1. For specific usage details, please see Use 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