@tencentcloud/tuiroom-engine-js
TypeScript icon, indicating that this package has built-in type declarations

2.7.2 • Public • Published

TUIRoomEngine Web SDK

简介

TUIRoomEngine Web SDK 依托腾讯云 实时音视频 TRTC即时通信 IM 服务,为用户提供房间管理,多人实时音视频互动,屏幕分享,成员管理,即时聊天等功能。

安装

// with npm
npm i @tencentcloud/tuiroom-engine-js --save

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

// with pnpm
pnpm i @tencentcloud/tuiroom-engine-js --save

示例代码

import TUIRoomEngine from '@tencentcloud/tuiroom-engine-js';

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}`);
}

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

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

// 设备变化:设备切换、设备插拔事件
function onDeviceChange(eventInfo) {
  console.log(`deviceChange ${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.onUserSigExpired, onUserSigExpired);
    roomEngine.on(TUIRoomEvents.onKickedOffLine, onKickedOffLine);
    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 登录 TUIRoomEngine
TUIRoomEngine.setSelfInfo 设置当前用户基本信息(用户名、用户头像)
TUIRoomEngine.getSelfInfo 获取当前用户信息
TUIRoomEngine.logout 登出 TUIRoomEngine
roomEngine.createRoom 创建房间
roomEngine.enterRoom 进入房间
roomEngine.destroyRoom 销毁房间
roomEngine.exitRoom 离开房间
roomEngine.fetchRoomInfo 获取房间信息
roomEngine.updateRoomNameByAdmin 更新房间的名字(仅群主或者管理员可以调用)
roomEngine.updateRoomSeatModeByAdmin 更新房间上麦模式(仅群主或者管理员可以调用)
roomEngine.getUserList 获取当前房间用户列表
roomEngine.getUserInfo 获取用户的详细信息
roomEngine.takeSeat 获取麦位
roomEngine.setMaxSeatCount 设置房间麦位最大值
roomEngine.leaveSeat 释放麦位
roomEngine.lockSeatByAdmin 锁定某个麦位状态
roomEngine.getSeatList 获取麦位信息
roomEngine.openRemoteDeviceByAdmin 请求远端用户打开摄像头
roomEngine.applyToAdminToOpenLocalDevice 参会者向主持人申请打开设备
roomEngine.closeRemoteDeviceByAdmin 关闭远端用户设备
roomEngine.takeUserOnSeatByAdmin 邀请其他人上麦
roomEngine.kickUserOffSeatByAdmin 要求其他人下麦
roomEngine.cancelRequest 取消已经发出的请求
roomEngine.responseRemoteRequest 回复远端用户的请求
roomEngine.setLocalVideoView 设置本地流的渲染位置
roomEngine.openLocalCamera 本地摄像头视频流采集
roomEngine.closeLocalCamera 关闭本地摄像头
roomEngine.openLocalMicrophone 打开本地麦克风
roomEngine.closeLocalMicrophone 关闭本地麦克风
roomEngine.updateVideoQuality 设置本地视频流的编码参数
roomEngine.updateAudioQuality 设置本地音频的参数
roomEngine.startPushLocalVideo 开始向远端推本地视频流
roomEngine.stopPushLocalVideo 停止向远端推本地视频流
roomEngine.startPushLocalAudio 开始向远端推本地音频流
roomEngine.stopPushLocalAudio 停止向远端推本地音频流
roomEngine.setRemoteVideoView 设置远端流渲染的区域
roomEngine.startPlayRemoteVideo 开始播放远端用户视频流
roomEngine.stopPlayRemoteVideo 停止播放远端用户视频流
roomEngine.muteRemoteAudioStream 停止播放远端用户的音频流
roomEngine.changeUserRole 改变用户的角色
roomEngine.kickRemoteUserOutOfRoom 将用户踢出房间
roomEngine.disableDeviceForAllUserByAdmin 所有用户的设备是否允许被使用
roomEngine.disableSendingMessageForAllUser 所有用户的是否允许发消息
roomEngine.disableSendingMessageByAdmin 特定用户是否被允许发消息
roomEngine.sendTextMessage 发送文本消息,该接口自 v2.0.0 版本废弃
roomEngine.sendCustomMessage 发送自定义消息,该接口自 v2.0.0 版本废弃
roomEngine.startScreenSharing 开始屏幕共享
roomEngine.stopScreenSharing 停止屏幕共享
roomEngine.on 监听 roomEngine 的事件
roomEngine.off 取消监听 roomEngine 的事件
roomEngine.getCameraDevicesList 获取摄像头设备列表
roomEngine.getMicDevicesList 获取麦克风设备列表
roomEngine.getSpeakerDevicesList 获取扬声器设备列表
roomEngine.setCurrentCameraDevice 设置要使用的摄像头设备
roomEngine.setCurrentMicDevice 设置要使用的麦克风设备
roomEngine.setCurrentSpeakerDevice 设置要使用的扬声器设备
roomEngine.getCurrentCameraDevice 获取当前正在使用的摄像头设备
roomEngine.getCurrentMicDevice 获取当前正在使用的麦克风设备
roomEngine.getCurrentSpeakerDevice 获取当前正在使用的扬声器设备
roomEngine.startCameraDeviceTest 开始进行摄像头测试
roomEngine.stopCameraDeviceTest 停止摄像头测试
roomEngine.getTRTCCloud 获取 trtcCloud 实例
roomEngine.getTIM 获取 tim 实例

参考文档

Package Sidebar

Install

npm i @tencentcloud/tuiroom-engine-js

Weekly Downloads

150

Version

2.7.2

License

ISC

Unpacked Size

4.8 MB

Total Files

6

Last publish

Collaborators

  • dawnrking
  • bernlao
  • ashfieldfox
  • chenximo
  • llwyct
  • allen0809npm
  • ashster
  • xinli123
  • wbxl2000
  • viktorli
  • alsotang