### TUIRoomEngine WX SDK

### 简介

TUIRoomEngine WX SDK 依托腾讯云 [实时音视频 TRTC](https://cloud.tencent.com/document/product/647/16788) 和 [即时通信 IM](https://cloud.tencent.com/document/product/269/42440) 服务，为用户提供房间管理，多人实时音视频互动，屏幕分享，成员管理，即时聊天等功能。

+ [快速接入 uniapp 小程序](https://cloud.tencent.com/document/product/647/97754)
+ [github](https://github.com/tencentyun/TUIRoomKit/tree/main/MiniProgram)

### 安装

```bash
// with npm
npm i @tencentcloud/tuiroom-engine-wx --save

// with yarn
yarn add @tencentcloud/tuiroom-engine-wx

// with pnpm
pnpm i @tencentcloud/tuiroom-engine-wx --save
```

### 示例代码

```javascript
import TUIRoomEngine from '@tencentcloud/tuiroom-engine-wx';

let roomEngine = null;

// 错误
function onError(error) {
  console.error(error);
}

// 音量变化
function onUserVoiceVolumeChanged(eventInfo) {
  console.log(eventInfo.userVolumeList);
}

// 网络质量变化
function onUserNetworkQualityChanged(eventInfo) {
  console.log(eventInfo.userNetworkList);
}

// 被踢出房间
function onKickedOutOfRoom(eventInfo) {
  console.log(`roomId: ${eventInfo.roomId}, ${eventInfo.message}`);
}

// 用户是否被禁止发消息
function onUserMuteStateChanged(eventInfo) {
  console.log(`user ${eventInfo.userId} isMute:${eventInfo.muted}`);
}

// 用户签名 userSig 过期
function onUserSigExpired() {
  console.log('userSig expire');
}

// 被踢下线
function onKickedOffLine(eventInfo) {
  console.log(`user offline, reason: ${eventInfo.message}`);
}

// 房间信息变更
function onRoomInfoChanged(eventInfo) {
  console.log(`roomInfo ${JSON.stringify(eventInfo)}`);
}

async function init() {
  TUIRoomEngine.once('ready', () => {
    roomEngine = new TUIRoomEngine();
    roomEngine.on(TUIRoomEvents.onError, onError);
    roomEngine.on(TUIRoomEvents.onUserVoiceVolumeChanged, onUserVoiceVolumeChanged);
    roomEngine.on(TUIRoomEvents.onUserNetworkQualityChanged, onUserNetworkQualityChanged);
    roomEngine.on(TUIRoomEvents.onKickedOutOfRoom, onKickedOutOfRoom);
    roomEngine.on(TUIRoomEvents.onUserMuteStateChanged, onUserMuteStateChanged);
    roomEngine.on(TUIRoomEvents.onUserSigExpired, onUserSigExpired);
    roomEngine.on(TUIRoomEvents.onKickedOffLine, onKickedOffLine);
    roomEngine.on(TUIRoomEvents.onRoomInfoChanged, onRoomInfoChanged);
    roomEngine.on(TUIRoomEvents.onDeviceChange, onDeviceChange);
  });

  // sdkAppId 获取和 userSig 生成详见官网文档
  // https://cloud.tencent.com/document/product/647/81962#step1
  await TUIRoomEngine.login({ sdkAppId: 0, userId: '', userSig: '' });
  await TUIRoomEngine.setSelfInfo({ userName: 'zhangsan', avatarUrl: 'https://testurl' });
}

init();

```

### API 列表

| API                               | 含义               |
| :-------------------------------- | :----------------- |
| [TUIRoomEngine.login](https://cloud.tencent.com/document/product/647/98556#login)         | 登录 TUIRoomEngine         |
| [TUIRoomEngine.setSelfInfo](https://cloud.tencent.com/document/product/647/98556#setSelfInfo)                | 设置当前用户基本信息（用户名、用户头像）       |
| [TUIRoomEngine.logout](https://cloud.tencent.com/document/product/647/98556#logout)                | 登出 TUIRoomEngine       |
| [roomEngine.createRoom](https://cloud.tencent.com/document/product/647/98556#createRoom)                | 创建房间       |
| [roomEngine.enterRoom](https://cloud.tencent.com/document/product/647/98556#enterRoom)                | 进入房间       |
| [roomEngine.destroyRoom](https://cloud.tencent.com/document/product/647/98556#destroyRoom)                | 销毁房间       |
| [roomEngine.exitRoom](https://cloud.tencent.com/document/product/647/98556#exitRoom)                | 离开房间       |
| [roomEngine.fetchRoomInfo](https://cloud.tencent.com/document/product/647/84265#fetchRoomInfo)                | 获取房间信息       |
| [roomEngine.updateRoomNameByAdmin](https://cloud.tencent.com/document/product/647/84265#updateRoomNameByAdmin)                | 更新房间的名字（仅群主或者管理员可以调用）      |
| [roomEngine.updateRoomSeatModeByAdmin](https://cloud.tencent.com/document/product/647/98556#updateRoomSeatModeByAdmin)                | 更新房间上麦模式（仅群主或者管理员可以调用）       |
| [roomEngine.getUserList](https://cloud.tencent.com/document/product/647/98556#getUserList)                | 获取当前房间用户列表       |
| [roomEngine.getUserInfo](https://cloud.tencent.com/document/product/647/98556#getUserInfo)                | 获取用户的详细信息       |
| [roomEngine.takeSeat](https://cloud.tencent.com/document/product/647/98556#takeSeat)                | 获取麦位       |
| [roomEngine.leaveSeat](https://cloud.tencent.com/document/product/647/98556#leaveSeat)                | 释放麦位       |
| [roomEngine.getSeatList](https://cloud.tencent.com/document/product/647/98556#getSeatList)                | 获取麦位信息       |
| [roomEngine.requestToOpenRemoteCamera](https://cloud.tencent.com/document/product/647/98556#requestToOpenRemoteCamera)                | 请求远端用户打开摄像头       |
| [roomEngine.closeRemoteCamera](https://cloud.tencent.com/document/product/647/98556#closeRemoteCamera) | 关闭远端用户摄像头       |
| [roomEngine.requestToOpenRemoteMicrophone](https://cloud.tencent.com/document/product/647/98556#requestToOpenRemoteMicrophone)                | 请求远端用户打开麦克风       |
| [roomEngine.closeRemoteMicrophone](https://cloud.tencent.com/document/product/647/98556#closeRemoteMicrophone) | 关闭远端用户麦克风       |
| [roomEngine.requestRemoteUserOnSeat](https://cloud.tencent.com/document/product/647/98556#requestRemoteUserOnSeat)                | 邀请其他人上麦       |
| [roomEngine.kickRemoteUserOffSeat](https://cloud.tencent.com/document/product/647/98556#kickRemoteUserOffSeat) | 要求其他人下麦       |
| [roomEngine.cancelRequest](https://cloud.tencent.com/document/product/647/98556#cancelRequest)                | 取消已经发出的请求       |
| [roomEngine.responseRemoteRequest](https://cloud.tencent.com/document/product/647/98556#responseRemoteRequest)                | 回复远端用户的请求       |
| [roomEngine.setLocalRenderView](https://cloud.tencent.com/document/product/647/98556#setLocalRenderView)                | 设置本地流的渲染位置       |
| [roomEngine.openLocalCamera](https://cloud.tencent.com/document/product/647/98556#openLocalCamera)                | 本地摄像头视频流采集       |
| [roomEngine.closeLocalCamera](https://cloud.tencent.com/document/product/647/98556#closeLocalCamera)                | 关闭本地摄像头       |
| [roomEngine.openLocalMicrophone](https://cloud.tencent.com/document/product/647/98556#openLocalMicrophone)                | 打开本地麦克风       |
| [roomEngine.closeLocalMicrophone](https://cloud.tencent.com/document/product/647/98556#closeLocalMicrophone)                | 关闭本地麦克风       |
| [roomEngine.setLocalVideoProfile](https://cloud.tencent.com/document/product/647/98556#setLocalVideoProfile)                | 设置本地视频的参数       |
| [roomEngine.setLocalAudioProfile](https://cloud.tencent.com/document/product/647/98556#setLocalAudioProfile)                | 设置本地音频的参数       |
| [roomEngine.startPushLocalVideo](https://cloud.tencent.com/document/product/647/98556#startPushLocalVideo)                | 开始向远端推本地视频流     |
| [roomEngine.stopPushLocalVideo](https://cloud.tencent.com/document/product/647/98556#stopPushLocalVideo)                | 停止向远端推本地视频流       |
| [roomEngine.setRemoteRenderView](https://cloud.tencent.com/document/product/647/98556#setRemoteRenderView)                | 设置远端流渲染的区域       |
| [roomEngine.startPlayRemoteVideo](https://cloud.tencent.com/document/product/647/98556#startPlayRemoteVideo)                | 开始播放远端用户视频流       |
| [roomEngine.stopPlayRemoteVideo](https://cloud.tencent.com/document/product/647/98556#stopPlayRemoteVideo)                | 停止播放远端用户视频流       |
| [roomEngine.changeUserRole](https://cloud.tencent.com/document/product/647/98556#changeUserRole)                | 改变用户的角色       |
| [roomEngine.muteRemoteUser](https://cloud.tencent.com/document/product/647/98556#muteRemoteUser)                | 禁止远端用户发送消息       |
| [roomEngine.unmuteRemoteUser](https://cloud.tencent.com/document/product/647/98556#unmuteRemoteUser)                | 取消禁止远端用户发送消息       |
| [roomEngine.kickOutRemoteUser](https://cloud.tencent.com/document/product/647/98556#kickOutRemoteUser)               | 将用户踢出房间       |
| [~~roomEngine.sendTextMessage~~](https://cloud.tencent.com/document/product/647/98556#sendTextMessage)                | 发送文本消息，该接口自 v2.0.0 版本废弃       |
| [~~roomEngine.sendCustomMessage~~](https://cloud.tencent.com/document/product/647/98556#sendCustomMessage)                | 发送自定义消息，该接口自 v2.0.0 版本废弃       |
| [roomEngine.on](https://cloud.tencent.com/document/product/647/98556#on)                | 监听 roomEngine 的事件       |
| [roomEngine.off](https://cloud.tencent.com/document/product/647/98556#off)                | 取消监听 roomEngine 的事件       |
| [roomEngine.getTRTCCloud](https://cloud.tencent.com/document/product/647/98556#getTRTCCloud)                | 获取 trtcCloud 实例       |
| [roomEngine.getTIM](https://cloud.tencent.com/document/product/647/98556#getTIM)                | 获取 tim 实例       |

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