Overview
TUIRoom is an open-source audio/video component that comes with UI elements. It allows you to quickly integrate conferencing capabilities like screen sharing and chatting into your project.
Note:
All components of TUIKit use Tencent Cloud's TRTC and Chat services. When you activate TRTC, Chat and the trial edition of the Chat SDK (which supports up to 100 DAUs) will also be activated automatically. For Chat billing details, see Pricing. Click here to try out more features of TUIRoom. Click here to download the TUIRoom code and refer to this document to run the TUIRoom web demo. This document shows you how to integrate the TUIRoom web component into your existing project.
Integration
The TUIRoom component is developed using Vue 3 + TypeScript + Pinia + Element Plus + SCSS, so your project must be based on Vue 3 + TypeScript.
Step 1. Activate the TRTC service
TUIRoom is based on TRTC and Chat.
1. Create a TRTC application
If you don’t have a Tencent Cloud account yet, sign up for one first. In the TRTC console, click Application Management on the left sidebar and then click Create Application. 2. Get the SDKAppID and key
3. On the Application Management page, find the application you created, and click Application Info to view its SDKAppID (different applications cannot communicate with each other).
4. Select the Quick Start tab to view the application's secret key. Each SDKAppID corresponds to a secret key. They are used to generate the signature (UserSig) required to legitimately use TRTC services.
5. Generate UserSigUserSig is a security signature designed by Tencent Cloud to prevent attackers from accessing your Tencent Cloud account. It is required when you initialize the TUIRoom component.
Step 2. Download and copy the TUIRoom component
1. Click here to clone or download the TUIRoom repository code. 2. Open your Vue3 + TypeScript project. You can use the build tool Vite or Webpack. If you don’t have a Vue3 + TypeScript project, create a template using either of the following two methods:
Create a Vue3 + Vite + TypeScript template
Create a Vue3 + Webpack + Typescript template
npm create vite@latest TUIRoom-demo -- --template vue
Note:
During the creation process, press Enter first, select "Vue", and then select "vue-ts".
After the template is generated, run the script below:
cd TUIRoom-demo
npm install
npm run dev
// Install Vue CLI. If you use Vue CLI 4.x, your Node.js version must be v10 or later.
npm install -g @vue/cli
// Create a Vue3 + Webpack + TypeScript template
vue create TUIRoom-demo
Note:
Select "Manually select features" as the template generation mode. For other settings, refer to the figure below:
After the template is generated, run the script below:
cd TUIRoom-demo
npm run serve
3. Copy the TUIRoom/Web/src/TUIRoom folder to the project's src/ directory.
Step 3. Import the TUIRoom component
1. Import the TUIRoom component into your webpage, such as App.vue.
The TUIRoom component classifies users as hosts and members and offers APIs including init, createRoom, and enterRoom. Hosts and members can call init to initialize application and user data. Hosts can call createRoom to create and enter rooms. Members can call enterRoom to join the rooms created by hosts. <template>
<room ref="TUIRoomRef"></room>
</template>
<script setup lang="ts">
import { ref, onMounted } from 'vue';
import Room from './TUIRoom/index.vue';
const TUIRoomRef = ref();
onMounted(async () => {
await TUIRoomRef.value.init({
sdkAppId: 0,
userId: '',
userSig: '',
userName: '',
userAvatar: '',
shareUserId: '',
shareUserSig: '',
})
await handleCreateRoom();
})
async function handleCreateRoom() {
const roomId = 123456;
const roomMode = 'FreeSpeech';
const roomParam = {
isOpenCamera: true,
isOpenMicrophone: true,
}
await TUIRoomRef.value.createRoom(roomId, roomMode, roomParam);
}
async function handleEnterRoom() {
const roomId = 123456;
const roomParam = {
isOpenCamera: true,
isOpenMicrophone: true,
}
await TUIRoomRef.value.enterRoom(roomId, roomParam);
}
</script>
<style>
html, body {
width: 100%;
height: 100%;
margin: 0;
}
#app {
width: 100%;
height: 100%;
}
</style>
Note:
Copy the above code to your webpage and replace the parameter values for the APIs with the actual values.
After the TUIRoom component is imported, in order to ensure that the project can run normally, the following configurations are required:
Set up the Vue3 + Vite + TypeScript development environment
Set up the Vue3 + Webpack + TypeScript environment
1. Install dependencies
Install development environment dependencies:
npm install sass typescript unplugin-auto-import unplugin-vue-components -S -D
Install production environment dependencies:
npm install element-plus events mitt pinia rtc-beauty-plugin tim-js-sdk trtc-js-sdk tsignaling -S
2. Register PiniaTUIRoom uses Pinia for room data management. You need to register Pinia in the project entry file src/main.ts.
import { createPinia } from 'pinia';
const app = createApp(App);
app.use(createPinia());
app.mount('#app');
3. Import Element Plus components
TUIRoom uses Element Plus UI components, which you need to import in vite.config.ts. You can import only the components you need.
Note:
Add the code in the file. Do not delete the existing configuration.
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
export default defineConfig({
plugins: [
AutoImport({
resolvers: [ElementPlusResolver()],
}),
Components({
resolvers: [ElementPlusResolver({
importStyle: 'sass',
})],
}),
],
css: {
preprocessorOptions: {
scss: {
additionalData: `
@use "./src/TUIRoom/assets/style/element.scss" as *;
`,
},
},
},
});
Meanwhile, in order to ensure that Element Plus UI components can display styles properly, you need to load Element Plus component styles in the entry file src/main.ts.
// src/main.ts
import 'element-plus/theme-chalk/el-message.css';
import 'element-plus/theme-chalk/el-message-box.css';
1. Install dependencies
Install development environment dependencies:
npm install sass sass-loader typescript unplugin-auto-import unplugin-vue-components unplugin-element-plus @types/events -S -D
Install production environment dependencies:
npm install element-plus events mitt pinia rtc-beauty-plugin tim-js-sdk trtc-js-sdk tsignaling -S
2. Register PiniaTUIRoom uses Pinia for room data management. You need to register Pinia in the project entry file src/main.ts.
import { createPinia } from 'pinia';
const app = createApp(App);
app.use(createPinia());
app.mount('#app');
3. Import Element Plus components
TUIRoom uses Element Plus UI components, which you need to import in vue.config.js. You can manually import only the components you need.
Note:
Add the code in the file. Do not delete the existing configuration.
const { defineConfig } = require('@vue/cli-service')
const AutoImport = require('unplugin-auto-import/webpack')
const Components = require('unplugin-vue-components/webpack')
const { ElementPlusResolver } = require('unplugin-vue-components/resolvers')
const ElementPlus = require('unplugin-element-plus/webpack')
module.exports = defineConfig({
transpileDependencies: true,
css: {
loaderOptions: {
scss: {
additionalData: '@use "./src/TUIRoom/assets/style/element.scss" as *;'
}
}
},
configureWebpack: {
plugins: [
AutoImport({
resolvers: [ElementPlusResolver({ importStyle: 'sass' })]
}),
Components({
resolvers: [ElementPlusResolver({ importStyle: 'sass' })]
}),
ElementPlus({
useSource: true
})
]
}
})
Meanwhile, in order to ensure that Element Plus UI components can display styles properly, you need to load Element Plus component styles in the entry file src/main.ts.
// src/main.ts
import 'element-plus/theme-chalk/el-message.css';
import 'element-plus/theme-chalk/el-message-box.css';
4. Configure the TS file.
Add the following configuration to src/shims-vue.d.ts:
declare module 'tsignaling/tsignaling-js' {
import TSignaling from 'tsignaling/tsignaling-js';
export default TSignaling;
}
declare module 'tim-js-sdk' {
import TIM from 'tim-js-sdk';
export default TIM;
}
declare const Aegis: any;
Step 5. Run your project in the development environment
In the console, execute the development environment script. Then, open the page integrated with the TUIRoom component with a browser.
If you used the script in step 2 to create a Vue + Vite + TypeScript project, follow the steps below: 1.1 Run the development environment command.
1.2 Open http://localhost:3000/ in a browser.
Note:
Because Element Plus components are imported manually, it may take a relatively long time for the page to load in the development environment for the first time. This will not be an issue after packaging.
1.3 Try out the features of the TUIRoom component.
If you used the script in step 2 to create a Vue + Webpack + TypeScript project, follow the steps below: 1.1 Run the development environment command.
1.2 Open http://localhost:8080/ in a browser.
Note:
If an ESLint error occurs in the src/TUIRoom directory, you can disable ESLint by adding /src/TUIRoom to the .eslintignore file.
1.3 Try out the features of the TUIRoom component.
Step 6. Commercial Scenario Deployment
1. Package dist file.
Note:
Please check the package.json file for the actual packaging command.
2. Deploy the dist file to the server.
Note:
Commercial Scenario requires the use of https domain name.
Appendix: TUIRoom APIs
TUIRoom APIs
init
This API is used to initialize TUIRoom data. All users using TUIRoom need to call this API first.
TUIRoomRef.value.init(roomData);
The parameters are described below:
|
| | - |
| | |
| | |
| | |
| | |
| | |
| | The UserId used for screen sharing, which must be in the format of share_${userId}. You don’t need to pass this parameter if you don’t need the screen sharing feature. |
| | UserSig used for screen sharing, which is optional.
|
createRoom
This API is used by a host to create a room.
TUIRoomRef.value.createRoom(roomId, roomMode, roomParam);
The parameters are described below:
|
| | |
| | The speech mode, including FreeSpeech (free speech) and ApplySpeech (request-to-speak). The default value is FreeSpeech, which is the only supported mode currently. |
| | |
| | Whether to turn on the camera upon room entry. This parameter is optional and the default is no. |
roomParam.isOpenMicrophone | | Whether to turn on the mic upon room entry. This parameter is optional and the default is no. |
roomParam.defaultCameraId | | The ID of the default camera, which is optional. |
roomParam.defaultMicrophoneId | | The ID of the default mic, which is optional. |
roomParam.defaultSpeakerId | | The ID of the default speaker, which is optional. |
enterRoom
This API is used by a member to enter a room.
TUIRoomRef.value.enterRoom(roomId, roomParam);
The parameters are described below:
|
| | |
| | |
| string | Whether to turn on the camera upon room entry. This parameter is optional and the default is no. |
roomParam.isOpenMicrophone | | Whether to turn on the mic upon room entry. This parameter is optional and the default is no. |
roomParam.defaultCameraId | | The ID of the default camera, which is optional. |
roomParam.defaultMicrophoneId | | The ID of the default mic, which is optional. |
roomParam.defaultSpeakerId | | The ID of the default speaker, which is optional. |
TUIRoom events
onRoomCreate
A room was created.
<template>
<room ref="TUIRoomRef" @on-room-create="handleRoomCreate"></room>
</template>
<script setup lang="ts">
import Room from './TUIRoom/index.vue';
function handleRoomCreate(info) {
if (info.code === 0) {
console.log('Room created successfully')
}
}
</script>
onRoomEnter
A member entered the room.
<template>
<room ref="TUIRoomRef" @on-room-enter="handleRoomEnter"></room>
</template>
<script setup lang="ts">
import Room from './TUIRoom/index.vue';
function handleRoomEnter(info) {
if (info.code === 0) {
console.log('Entered room successfully')
}
}
</script>
onRoomDestory
The host closed the room.
<template>
<room ref="TUIRoomRef" @on-room-destory="handleRoomDestory"></room>
</template>
<script setup lang="ts">
import Room from './TUIRoom/index.vue';
function handleRoomDestory(info) {
if (info.code === 0) {
console.log('The host closed the room successfully')
}
}
</script>
onRoomExit
A member exited the room.
<template>
<room ref="TUIRoomRef" @on-room-exit="handleRoomExit"></room>
</template>
<script setup lang="ts">
import Room from './TUIRoom/index.vue';
function handleRoomExit(info) {
if (info.code === 0) {
console.log('The member exited the room successfully')
}
}
</script>
onKickOff
A member was removed from the room by the host.
<template>
<room ref="TUIRoomRef" @on-kick-off="handleKickOff"></room>
</template>
<script setup lang="ts">
import Room from './TUIRoom/index.vue';
function handleKickOff(info) {
if (info.code === 0) {
console.log('The member was removed from the room by the host')
}
}
</script>