SDKAppID
(different applications cannot communicate with each other).SDKAppID
corresponds to a secret key. They are used to generate the signature (UserSig
) required to legitimately use TRTC services.UserSig
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.cd electron-vite-vuenpm installnpm run dev
TUIRoom/Electron/packages/renderer/src/TUIRoom
folder to packages/renderer/src/
of your project.App.vue
.<template><room ref="TUIRoomRef"></room></template><script setup lang="ts">import { ref, onMounted } from 'vue';// Import the TUIRoom component. Be sure to use the correct import path.import Room from './TUIRoom/index.vue';// Get the TUIRoom component elements used to call the component’s APIsconst TUIRoomRef = ref();onMounted(async () => {// Initialize the TUIRoom component// A host needs to initialize the TUIRoom component before creating a room// A participant needs to initialize the TUIRoom component before entering a roomawait TUIRoomRef.value.init({// Get the `SDKAppID` (see step 1)sdkAppId: 0,// The user's unique ID in your businessuserId: '',// For local development and debugging, you can quickly generate a `UserSig` at https://console.tencentcloud.com/trtc/usersigtool. Each `UserID` corresponds to a `UserSig`.userSig: '',// The user's username in your businessuserName: '',// The URL of the user's profile photo in your businessuserAvatar: '',// The user's unique ID used for screen sharing. It 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.shareUserId: '',// Refer to steps 1-3 above and use the `SDKAppID` and `shareUserId` to generate `shareUserSig`shareUserSig: '',})// By default, a room is created at this point. During actual implementation, you can specify when to call `handleCreateRoom()`.await handleCreateRoom();})// The host creates a room. Call this API only when you need to create a room.async function handleCreateRoom() {// `roomId` is the ID of the room to enter, which must be a number.// The valid values of `roomMode` are `FreeSpeech` (free speech mode) and `ApplySpeech` (request-to-speak mode). The default value is `FreeSpeech`, which is the only supported mode currently.// `roomParam` specifies whether to turn on the mic/camera upon room entry, as well as the default media device ID to useconst roomId = 123456;const roomMode = 'FreeSpeech';const roomParam = {isOpenCamera: true,isOpenMicrophone: true,}await TUIRoomRef.value.createRoom(roomId, roomMode, roomParam);}// The participant enters a room. This API is called by a participant to join an existing room.async function handleEnterRoom() {// `roomId` is the ID of the room to enter, which must be a number.// `roomParam` specifies whether to turn on the mic/camera upon room entry, as well as the default media device ID to useconst 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>
npm install sass typescript unplugin-auto-import unplugin-vue-components -S -D
npm install element-plus events mitt pinia trtc-electron-sdk tim-js-sdk tsignaling -S
packages/renderer/src/main.ts
.// `src/main.ts` fileimport { createPinia } from 'pinia';const app = createApp(App);// Register PiniacreateApp(App).use(createPinia()).mount('#app').$nextTick(window.removeLoading)
packages/renderer/vite.config.ts
. You can manually import only the components you need.// vite.config.tsimport AutoImport from 'unplugin-auto-import/vite';import Components from 'unplugin-vue-components/vite';import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';const path = require('path');export default defineConfig({// ...plugins: [AutoImport({resolvers: [ElementPlusResolver()],}),Components({resolvers: [ElementPlusResolver({importStyle: 'sass',})],}),],css: {preprocessorOptions: {scss: {additionalData: `@use '${path.resolve(__dirname, 'src/TUIRoom/assets/style/element.scss')}' as *;`,},},},});
// src/main.tsimport 'element-plus/theme-chalk/el-message.css'import 'element-plus/theme-chalk/el-message-box.css'
trtc-electron-sdk
using the import statement at the UI layer, you need to configure packages/renderer/vite.config.ts
as follows (otherwise, you will have to use the require statement):resolve
with the following:// vite.config.tsexport default defineConfig({// ...plugins: [resolve({"trtc-electron-sdk": `const TRTCCloud = require("trtc-electron-sdk");const TRTCParams = TRTCCloud.TRTCParams;const TRTCAppScene = TRTCCloud.TRTCAppScene;const TRTCVideoStreamType = TRTCCloud.TRTCVideoStreamType;const TRTCScreenCaptureSourceType = TRTCCloud.TRTCScreenCaptureSourceType;const TRTCVideoEncParam = TRTCCloud.TRTCVideoEncParam;const Rect = TRTCCloud.Rect;const TRTCAudioQuality = TRTCCloud.TRTCAudioQuality;const TRTCScreenCaptureSourceInfo = TRTCCloud.TRTCScreenCaptureSourceInfo;const TRTCDeviceInfo = TRTCCloud.TRTCDeviceInfo;const TRTCVideoQosPreference = TRTCCloud.TRTCVideoQosPreference;const TRTCQualityInfo = TRTCCloud.TRTCQualityInfo;const TRTCStatistics = TRTCCloud.TRTCStatistics;const TRTCVolumeInfo = TRTCCloud.TRTCVolumeInfo;const TRTCDeviceType = TRTCCloud.TRTCDeviceType;const TRTCDeviceState = TRTCCloud.TRTCDeviceState;const TRTCBeautyStyle = TRTCCloud.TRTCBeautyStyle;const TRTCVideoResolution = TRTCCloud.TRTCVideoResolution;const TRTCVideoResolutionMode = TRTCCloud.TRTCVideoResolutionMode;const TRTCVideoMirrorType = TRTCCloud.TRTCVideoMirrorType;const TRTCVideoRotation = TRTCCloud.TRTCVideoRotation;const TRTCVideoFillMode = TRTCCloud.TRTCVideoFillMode;export {TRTCParams,TRTCAppScene,TRTCVideoStreamType,TRTCScreenCaptureSourceType,TRTCVideoEncParam,Rect,TRTCAudioQuality,TRTCScreenCaptureSourceInfo,TRTCDeviceInfo,TRTCVideoQosPreference,TRTCQualityInfo,TRTCStatistics,TRTCVolumeInfo,TRTCDeviceType,TRTCDeviceState,TRTCBeautyStyle,TRTCVideoResolution,TRTCVideoResolutionMode,TRTCVideoMirrorType,TRTCVideoRotation,TRTCVideoFillMode,};export default TRTCCloud.default;`,}),]// ...});
env.d.ts
env.d.ts
file in packages/renderer/src/env.d.ts
as follows:env.d.ts
. Do not delete the existing configuration in the file.// env.d.tsdeclare 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;}
packages/renderer/vite.config.ts
as follows.// vite.config.tsexport default defineConfig({// ...build: {rollupOptions: {output: {format: 'es'}}},});
npm run dev
release
directory.npm run build
TUIRoomRef.value.init(roomData);
Parameter | Type | Description |
roomData | object | |
roomData.sdkAppId | number | The SDKAppID. |
roomData.userId | string | The unique user ID. |
roomData.userSig | string | The UserSig. |
roomData.userName | string | The username. |
roomData.userAvatar | string | The user’s profile photo. |
roomData.shareUserId | string | 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. |
roomData.shareUserSig | string | The UserSig used for screen sharing, which is optional. |
TUIRoomRef.value.createRoom(roomId, roomMode, roomParam);
Parameter | Type | Description |
roomId | number | The room ID. |
roomMode | string | The speech mode, including FreeSpeech (free speech) and ApplySpeech (request-to-speak). The default value is FreeSpeech , which is the only supported mode currently. |
roomParam | Object | Optional |
roomParam.isOpenCamera | string | Whether to turn on the camera upon room entry. This parameter is optional and the default is no. |
roomParam.isOpenMicrophone | string | Whether to turn on the mic upon room entry. This parameter is optional and the default is no. |
roomParam.defaultCameraId | string | The ID of the default camera, which is optional. |
roomParam.defaultMicrophoneId | string | The ID of the default mic, which is optional. |
roomParam.defaultSpeakerId | String | The ID of the default speaker, which is optional. |
TUIRoomRef.value.enterRoom(roomId, roomParam);
Parameter | Type | Description |
roomId | number | The room ID. |
roomParam | Object | Optional |
roomParam.isOpenCamera | string | Whether to turn on the camera upon room entry. This parameter is optional and the default is no. |
roomParam.isOpenMicrophone | string | Whether to turn on the mic upon room entry. This parameter is optional and the default is no. |
roomParam.defaultCameraId | string | The ID of the default camera, which is optional. |
roomParam.defaultMicrophoneId | string | The ID of the default mic, which is optional. |
roomParam.defaultSpeakerId | String | The ID of the default speaker, which is optional. |
<template><room ref="TUIRoomRef" @on-room-create="handleRoomCreate"></room></template><script setup lang="ts">// Import the TUIRoom component. Be sure to use the correct import path.import Room from './TUIRoom/index.vue';function handleRoomCreate(info) {if (info.code === 0) {console.log('Room created successfully')}}</script>
<template><room ref="TUIRoomRef" @on-room-enter="handleRoomEnter"></room></template><script setup lang="ts">// Import the TUIRoom component. Be sure to use the correct import path.import Room from './TUIRoom/index.vue';function handleRoomEnter(info) {if (info.code === 0) {console.log('Entered room successfully')}}</script>
<template><room ref="TUIRoomRef" @on-room-destory="handleRoomDestory"></room></template><script setup lang="ts">// Import the TUIRoom component. Be sure to use the correct import path.import Room from './TUIRoom/index.vue';function handleRoomDestory(info) {if (info.code === 0) {console.log('The host closed the room successfully')}}</script>
<template><room ref="TUIRoomRef" @on-room-exit="handleRoomExit"></room></template><script setup lang="ts">// Import the TUIRoom component. Be sure to use the correct import path.import Room from './TUIRoom/index.vue';function handleRoomExit(info) {if (info.code === 0) {console.log('The participant exited the room successfully')}}</script>
Was this page helpful?