@tencent-classroom/sdk
v2.0.0-alpha.1
Published
腾讯云互动课堂 SDK — 纯 TypeScript,零框架依赖 / Tencent Cloud Interactive Classroom SDK
Downloads
329
Maintainers
Readme
@tencent-classroom/sdk
腾讯云实时互动-教育版, 即原腾讯云互动课堂, 无 UI SDK(Web 端)— 纯 TypeScript,零框架依赖。
Tencent Cloud Low-Code Interactive Classroom SDK for Web — Pure TypeScript, framework-agnostic.
安装 / Installation
NPM(推荐)/ NPM (Recommended)
npm install @tencent-classroom/sdk
# or
pnpm add @tencent-classroom/sdkCDN / Script Tag
通过 unpkg 直接引入(将 {VERSION} 替换为实际版本号,如 2.0.0):
Load via unpkg — replace {VERSION} with the actual version (e.g. 2.0.0):
<script src="https://unpkg.com/@tencent-classroom/sdk@{VERSION}/dist/umd/tencent-classroom-sdk.js"></script>
<script>
const { TencentClassroom, TEvent, StreamType } = TencentClassroomSDK;
// ...
</script>建议 / Recommendation
unpkg 是社区 CDN,加载速度受网络环境影响。为保障生产环境的加载性能和稳定性,强烈建议将该文件下载后部署到自己的 CDN:
- 下载文件:
https://unpkg.com/@tencent-classroom/sdk@{VERSION}/dist/umd/tencent-classroom-sdk.js- 上传至你的 CDN 或静态资源服务
- 在页面中引用你自己的 CDN 地址
For production use, we strongly recommend downloading the UMD bundle and hosting it on your own CDN to ensure load performance and availability.
AI 辅助开发 / AI-Assisted Development
npx skills add InteractiveClassroom/skills --skill tcic-sdk-helper快速上手 / Quick Start
import { TencentClassroom, TEvent, StreamType } from '@tencent-classroom/sdk';
// 1. 创建实例 / Create instance
const classroom = new TencentClassroom({ language: 'zh-CN' });
// 2. 初始化 / Initialize
await classroom.init();
// 3. 监听关键事件 / Listen to key events
classroom.on(TEvent.KICK_OUT, ({ message }) => alert(message));
classroom.on(TEvent.CLASS_END, () => console.log('课堂结束'));
// 4. 进房 / Join classroom
const result = await classroom.joinClass({
classId: 123456,
userId: 'student_001',
token: 'your_token',
});
if (!result.ok) {
console.error('进房失败:', result.message);
return;
}
// 5. 开启摄像头 / Start camera
await classroom.startCamera(document.getElementById('local-video'));
// 6. 绑定远端视频 / Bind remote video
const binding = classroom.bindRemoteView(
'teacher_001',
document.getElementById('remote-video'),
StreamType.Camera,
);
// 7. 发送消息 / Send message
await classroom.sendTextMessage('大家好!');
// 8. 订阅响应式状态 / Subscribe to reactive state
const unsub = classroom.state.classStatus$.subscribe(status => {
console.log('课堂状态:', status); // 'notStarted' | 'started' | 'ended'
});
// 9. 离房 / Leave
await classroom.leaveClass();
await classroom.destroy();
unsub();文档 / Documentation
完整 API 文档请访问:https://www.tencentclass.net/docs/sdk/
浏览器兼容性 / Browser Compatibility
支持现代浏览器(Chrome 72+、Firefox 68+、Safari 12.1+、Edge 79+)。依赖 WebRTC,不支持 IE。
License
MIT
