## TUICallEngine API 简介

TUICallEngine API 是 **无 UI** 音视频通话接口。如果带 **UI [TUICallKit](https://www.npmjs.com/package/@tencentcloud/call-uikit-wechat) 组件** 的交互不满足您的需求，您可以使用 TUICallEngine 接口自己封装交互。
由于小程序开发的限制，需要先给 [live-pusher](https://developers.weixin.qq.com/miniprogram/dev/component/live-pusher.html) 绑定事件，具体可以参照 [TUICallKit](https://www.npmjs.com/package/@tencentcloud/call-uikit-wechat)。


## 安装依赖
npm：
```
npm install tuicall-engine-wx;
```
yarn：
```
yarn add tuicall-engine-wx;
```

使用
```
import TUICallEngine, { EVENT } from "tuicall-engine-wx";

const options = {
  sdkAppID: 0, // 接入时需要将 0 替换为您的云通信应用的 SDKAppID
  tim: tim, // tim 参数适用于业务中已存在 TIM 实例，为保证 TIM 实例唯一性。非必填
}
wx.$TUICallEngine = TUICallEngine.createInstance(options);
wx.$TUICallEngine.on(EVENT.INVITED, () => {});
```

## API 概览

### 创建实例和事件回调

| API | 描述 |
|-----|-----|
| [createInstance](https://cloud.tencent.com/document/product/647/78761#createinstance) | 创建 TUICallEngine 实例（静态方法）|
| [destroyInstance](https://cloud.tencent.com/document/product/647/78761#destroyinstance) | 销毁 TUICallEngine 实例（静态方法）|
| [on](https://cloud.tencent.com/document/product/647/78761#on) | 增加事件监听 |
| [off](https://cloud.tencent.com/document/product/647/78761#off) | 取消事件监听 |


### 通话操作相关接口函数

| API | 描述 |
|-----|-----|
| [call](https://cloud.tencent.com/document/product/647/78761#call) | 发起 1v1 通话 |
| [accept](https://cloud.tencent.com/document/product/647/78761#accept) | 接听通话 |
| [reject](https://cloud.tencent.com/document/product/647/78761#reject) | 拒绝通话 |
| [hangup](https://cloud.tencent.com/document/product/647/78761#hangup) | 结束通话 |
| [switchCallMediaType](https://cloud.tencent.com/document/product/647/78761#switchCallMediaType) | 切换通话媒体类型，比如视频通话切音频通话 |


### 设备控制相关接口函数

| API | 描述 |
|-----|-----|
| [openCamera](https://cloud.tencent.com/document/product/647/78761#openCamera) | 开启摄像头 |
| [closeCamera](https://cloud.tencent.com/document/product/647/78761#closeCamera) | 关闭摄像头 |
| [switchCamera](https://cloud.tencent.com/document/product/647/78761#switchCamera) | 切换前后摄像头 |
| [openMicrophone](https://cloud.tencent.com/document/product/647/78761#openMicrophone) | 打开麦克风 |
| [closeMicrophone](https://cloud.tencent.com/document/product/647/78761#closeMicrophone) | 关闭麦克风 |
| [selectAudioPlaybackDevice](https://cloud.tencent.com/document/product/647/78761#selectAudioPlaybackDevice) | 选择音频播放设备（听筒/扬声器）|


### 其他接口函数

| API | 描述 |
|-----|-----|
| [setSelfInfo](https://cloud.tencent.com/document/product/647/78761#setselfinfo) | 设置用户的头像、昵称 |
| [setLogLevel](https://cloud.tencent.com/document/product/647/78761#setLogLevel) | 设置日志级别，低于 level 的日志将不会输出 |


## 事件

| 事件名 | 说明 |
|-----|-----|
| [INVITED](https://cloud.tencent.com/document/product/647/81012#invited) | 被邀请通话 |
| [USER_ACCEPT](https://cloud.tencent.com/document/product/647/81012#user_accept) | 用户接听 |
| [USER_ENTER](https://cloud.tencent.com/document/product/647/81012#user_enter) | 用户进入通话 |
| [USER_LEAVE](https://cloud.tencent.com/document/product/647/81012#user_leave) | 用户离开通话 |
| [USER_UPDATE](https://cloud.tencent.com/document/product/647/81012#user_update) | 用户更新 |
| [REJECT](https://cloud.tencent.com/document/product/647/81012#reject2) | 用户拒绝通话 |
| [NO_RESP](https://cloud.tencent.com/document/product/647/81012#no_resp) | 用户无响应 |
| [LINE_BUSY](https://cloud.tencent.com/document/product/647/81012#line_busy) | 用户忙线 |
| [CALLING_CANCEL](https://cloud.tencent.com/document/product/647/81012#calling_cancel) | 通话被取消 |
| [CALL_END](https://cloud.tencent.com/document/product/647/81012#call_end) | 通话结束 |
| [SDK_READY](https://cloud.tencent.com/document/product/647/81012#sdk_ready) | SDK Ready 回调 |
| [KICKED_OUT](https://cloud.tencent.com/document/product/647/81012#kicked_out) | 被踢下线 |
| [CALL_MODE](https://cloud.tencent.com/document/product/647/81012#call_mode) | 切换通话模式 |

## 参考文档
- [TUICallEngine API](https://cloud.tencent.com/document/product/647/78761)
- [含 UI TUICallKit](https://cloud.tencent.com/document/product/647/78760)
- [腾讯云即时通信 IM](https://cloud.tencent.com/document/product/269/1498)
- [腾讯实时音视频 TRTC](https://cloud.tencent.com/document/product/647/16788)
