tuicall-engine-webrtc 是基于腾讯云 即时通信 IM 和 实时音视频 TRTC 两项付费 PaaS 服务构建出的音视频通信组件,支持双人和多人场景下的音视频通话。
Methods
(static) createInstance(options)
创建 TUICallEngine 实例
Example
let options = {
  SDKAppID: 0, // 接入时需要将0替换为您的云通信应用的 SDKAppID
  // tim 参数适用于业务中已存在 TIM 实例,需要传入保证 TIM 实例唯一性
  tim: tim
};
let tuiCallEngine = TUICallEngine.createInstance(options);Parameters:
| Name | Type | Description | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| options | Object | required配置 Properties
 | 
(async) destroyInstance() → {Promise}
销毁 TUICallEngine 实例
- 注:SDK 会先 logout,然后释放资源
Example
tuiCallEngine.destroyInstance().then(() => {
  //success
}).catch(error => {
  console.warn('destroyInstance error:', error)
});Returns:
- Type
- Promise
setLogLevel(level)
设置日志级别,低于 level 的日志将不会输出。
Example
tuiCallEngine.setLogLevel(0);Parameters:
| Name | Type | Description | 
|---|---|---|
| level | LOG_LEVEL | required日志级别 
 | 
on(eventName, callback, context)
监听事件
Example
let onError = function(error) {
  console.log(error);
};
tuiCallEngine.on(TUICallEvent.ERROR, onError, this);Parameters:
| Name | Type | Description | 
|---|---|---|
| eventName | String | required事件名 | 
| callback | function | required事件响应回调 | 
| context | Any | required期望 callback 执行时的上下文 | 
off(eventName, callback, context)
取消监听事件
Example
let onError = function(error) {
  console.log(error)
};
tuiCallEngine.off(TUICallEvent.ERROR, onError, this);Parameters:
| Name | Type | Description | 
|---|---|---|
| eventName | String | required事件名 | 
| callback | function | required事件响应回调 | 
| context | Any | required期望 callback 执行时的上下文 | 
(async) init() → {Promise}
login() 方法的别名接口,参数一致
Returns:
- Type
- Promise
(async) login(params) → {Promise}
登录接口,所有功能需要先进行登录后才能使用
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登录配置 Properties
 | 
Returns:
- Type
- Promise
(async) logout() → {Promise}
登出接口,登出后无法再进行拨打操作
Example
let promise = tuiCallEngine.logout();
promise.then(() => {
  //success
}).catch(error => {
  console.warn('logout error:', error)
});Returns:
- Type
- Promise
(async) call(params) → {Promise}
C2C邀请通话,被邀请方会收到 TUICallEvent.INVITED 事件
- 注意:离线推送仅适用于终端(Android 或 iOS),Web 和 微信小程序不支持。
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拨打通话配置 Properties
 | 
Returns:
- Type
- Promise
(async) groupCall(params) → {Promise}
IM群组邀请通话,被邀请方会收到 TUICallEvent.INVITED 事件
              注意:离线推送仅适用于终端(Android 或 iOS),Web 和 微信小程序不支持。
Example
let promise = tuiCallEngine.groupCall({userIDList: ['user1', 'user2'], type: 1, groupID: 'IM群组 ID'});
promise.then(() => {
  //success
}).catch(error => {
  console.warn('groupCall error:', error)
});Parameters:
| Name | Type | Description | |||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| params | Object | required群聊拨打通话配置 Properties
 | 
Returns:
- Type
- Promise
(async) joinInGroupCall(params)
主动加入此次群组通话。
              使用场景:群组内用户主动加入此次群组通话使用。
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中途加入配置 Properties
 | 
(async) inviteUser(params)
邀请他人,邀请用户加入此次群组通话。
              使用场景:一个群组通话中的用户主动邀请其他人时使用。
- 被叫接通后处于通话中, 才能邀请他人。例如:A 呼叫 B,B 接通后,B 才能邀请他人。
- 主叫处于呼叫中、通话中时,都可以邀请他人。例如:A 呼叫 B,B 是否接通,A 都可以邀请他人。
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邀请他人配置 Properties
 | 
(async) accept() → {Promise}
当您作为被邀请方收到 TUICallEvent.INVITED 事件的回调时,可以调用该接口接听来电
Example
tuiCallEngine.on(TUICallEvent.INVITED, () => {
  tuiCallEngine.accept().then(() => {
    //success
  }).catch(error => {
    console.warn('accept error:', error);
  });
});Returns:
- Type
- Promise
(async) reject() → {Promise}
当您作为被邀请方收到 TUICallEvent.INVITED 事件的回调时,可以调用该接口拒绝来电
Example
tuiCallEngine.on(TUICallEvent.INVITED, () => {
  tuiCallEngine.reject().then(() => {
    //success
  }).catch(error => {
    console.warn('reject error:', error);
  });
});Returns:
- Type
- Promise
(async) hangup() → {Promise}
挂断当前通话,当您处于通话中,可以调用该函数结束通话;当您处于呼叫状态时,可以调用该函数取消通话
- 当您处于通话中,可以调用该接口结束通话
- 当未拨通时, 可用来取消通话
Example
tuiCallEngine.hangup().then(() => {
   // success
 }).catch(error => {
    console.warn('hangup error:', error);
 });Returns:
- Type
- Promise
(async) startRemoteView(params) → {Promise}
启动远端画面渲染。请在收到 USER_VIDEO_AVAILABLE 事件且事件里的 isVideoAvailable 参数为 true 时,可调用该接口将远端用户的摄像头数据渲染到指定的 dom id 节点里。
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渲染远端视频配置 Properties
 | 
Returns:
- Type
- Promise
(async) stopRemoteView(params) → {Promise}
停止远端画面渲染
Example
let promise = tuiCallEngine.stopRemoteView({userID: 'user1'});
promise.then(() => {
  //success
}).catch(error => {
  console.warn('stopRemoteView error:', error)
});Parameters:
| Name | Type | Description | ||||||
|---|---|---|---|---|---|---|---|---|
| params | Object | required渲染远端视频配置 Properties
 | 
Returns:
- Type
- Promise
(async) startLocalView(params) → {Promise}
启动本地画面渲染。
- Deprecated:
- 
              - 在v1.3.2版本后逐步废除,可调用 [openCamera](https://web.sdk.qcloud.com/component/trtccalling/doc/TUICallEngine/web/TUICallEngine.html#openCamera) 打开摄像头并预览。
 
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渲染本地视频配置 Properties
 | 
Returns:
- Type
- Promise
(async) stopLocalView(params) → {Promise}
停止远端画面渲染
- Deprecated:
- 
              - 在v1.3.2版本后逐步废除,可调用 [closeCamera](https://web.sdk.qcloud.com/component/trtccalling/doc/TUICallEngine/web/TUICallEngine.html#closeCamera) 打开摄像头并预览。
 
Example
let promise = tuiCallEngine.stopLocalView({userID: 'user1'});
promise.then(() => {
  //success
}).catch(error => {
  console.warn('stopLocalView error:', error)
});Parameters:
| Name | Type | Description | ||||||
|---|---|---|---|---|---|---|---|---|
| params | Object | required渲染本地视频配置 Properties
 | 
Returns:
- Type
- Promise
(async) openCamera(videoViewDomID, isFrontCameraopt) → {Promise}
您可以调用该接口开启摄像头,处于通话中的用户会收到 USER_VIDEO_AVAILABLE 回调
Example
// 'localView' 是 div 标签对应的 id 值
tuiCallEngine.openCamera('localView').then(() => {
  // success
}).catch(error => {
  console.warn('openCamera error:', error)
});Parameters:
| Name | Type | Description | 
|---|---|---|
| videoViewDomID | string | required该用户数据将渲染到该 dom id 节点里 | 
| isFrontCamera | boolean | 前后置摄像头,true 表示前置摄像头。仅支持移动端上使用 | 
Returns:
注意:
- 当传入 string 类型的 elementId 时,需要确保 elementId 在 DOM 中,否则调用接口会报错。
- 业务侧可自行调整该 DOM 元素的 css 宽高来控制 video 标签显示的宽高。
- Type
- Promise
(async) closeCamera() → {Promise}
您可以调用该接口关闭摄像头,处于通话中的用户会收到 USER_VIDEO_AVAILABLE 回调
Example
tuiCallEngine.closeCamera().then(() => {
  // success
}).catch(error => {
  console.warn('closeCamera error:', error)
});Returns:
- Type
- Promise
(async) openMicrophone() → {Promise}
打开麦克风,处于通话中的用户会收到 USER_AUDIO_AVAILABLE 回调
Example
tuiCallEngine.openMicrophone().then(() => {
  // success
}).catch(error => {
  console.warn('openMicrophone error:', error)
});Returns:
- Type
- Promise
(async) closeMicrophone() → {Promise}
关闭麦克风,处于通话中的用户会收到 USER_AUDIO_AVAILABLE 回调
Example
tuiCallEngine.closeMicrophone().then(() => {
  // success
}).catch(error => {
  console.warn('closeMicrophone error:', error)
});Returns:
- Type
- Promise
(async) setVideoQuality(profile) → {Promise}
设置视频分辨率
Example
const profile = '720p';
// 设置视频质量为 720p
tuiCallEngine.setVideoQuality(profile).then(() => {
  // success
}).catch(error => {
  console.warn('setVideoQuality error:', error)
});Parameters:
| Name | Type | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| profile | String | required视频 profile 
 
 | 
Returns:
- Type
- Promise
(async) setVideoRenderParams(params)
设置用户视频画面的显示模式
Parameters:
| Name | Type | Description | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| params | ITRTCRenderParams | required显示参数 Properties
 | 
(async) switchCallMediaType(newMediaType)
当前通话类型切换
- 仅支持1v1通话过程中使用
- 失败监听 ERROR 事件,code: 60001
Example
tuiCallEngine.switchCallMediaType(1).then(() => { // 视频通话切换语音通话
  // success
}).catch(error => {
  console.warn('switchCallMediaType error:', error)
});Parameters:
| Name | Type | Description | 
|---|---|---|
| newMediaType | String | required通话类型 
 | 
(async) getDeviceList(deviceType)
获取设备列表
Example
tuiCallEngine.getDeviceList('camera').then((devices)=>{  // 获取摄像头列表
 console.log(devices)
}).catch(error => {
  console.warn('getDeviceList error:', error)
});Parameters:
| Name | Type | Description | 
|---|---|---|
| deviceType | String | required设备类型 
 | 
(async) switchCamera(cameraPosition)
切换前后置摄像头
              Note: v3.0.0+ 支持,且该接口仅在移动端使用生效。
            
Example
await tuiCallEngine.switchCamera(TUICallCameraPosition.FRONT); // 切换前置摄像头
await tuiCallEngine.switchCamera(TUICallCameraPosition.BACK); // 切换后置摄像头Parameters:
| Name | Type | Description | 
|---|---|---|
| cameraPosition | TUICallCameraPosition | required摄像头类型 
 | 
(async) switchDevice(params)
切换摄像头或麦克风设备
Example
let promise = tuiCallEngine.switchDevice({deviceType: 'camera', deviceId: cameras[0].deviceId}) // 切换设备
promise.then(() => {
  // success
}).catch(error => {
  console.warn('switchDevice error:', error)
});Parameters:
| Name | Type | Description | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| params | ISwitchDeviceParams | requiredProperties
 | 
(async) setSelfInfo(params)
设置自己的昵称或头像
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 | requiredProperties
 | 
enableMultiDeviceAbility(enable) → {void}
开启/关闭 TUICallEngine 的多设备登录模式 (尊享版套餐支持)
- 注意:v2.1.1+ 才支持。
Example
tuiCallEngine.enableMultiDeviceAbility(true);Parameters:
| Name | Type | Description | 
|---|---|---|
| enable | boolean | required开启、关闭多设备登录. 开启: true; 关闭: false; 默认: 关闭 | 
Returns:
- Type
- void
(async) enableAIVoice(enable)
开启/关闭 AI 降噪
- 1.2.1 版本以后支持,具体使用详情请参见 使用 AI 降噪。
Example
let promise = tuiCallEngine.enableAIVoice(true);
promise.then(() => {
  // success
}).catch(error => {
  console.warn('enableAIVoice error:', error)
});Parameters:
| Name | Type | Description | 
|---|---|---|
| enable | boolean | required开启、关闭 AI 降噪. true 表示开启; false 表示关闭 |