BRTC Web SDK 一个互动低延时 Web 实时通信解决方案。它是通过 HTML 网页加载的 JavaScript 库。开发者可以使用 BRTC Web SDK 提供的 API 建立连接,控制实时音视频通话或者直播服务。
NPM 集成
npm install brtc-js --save
在项目脚本里引入模块。
let BRTC = require('./dist/BRTC.js'); import * as BRTC from './dist/BRTC.js';
Script 集成您只需要在您的 Web 页面中添加如下代码即可:
<script src="./dist/BRTC.js"></script>
<div id="self-player"></div> <div id="remote-player"></div> const client = BRTC.createClient({mode: 'live', codec: 'h264'}); client .on('stream-added', (data) => { let remotestream = data.stream; console.log(`user ${remotestream.getUserId()} publish`); client.subscribe(remotestream, {video: true, audio: true}).then(() => { console.log(`user ${remotestream.getUserId()} subscribed`); remotestream.play('remote-player').then(() => { console.log(`user ${remotestream.getUserId()} played`); }); }) .catch(error) { console.log('subscribe fail', error); } }) .on('stream-removed', (data) => { let remotestream = data.remotestream; console.log(`user ${remotestream.getUserId()} unpublish`); remotestream.stop(); client.unsubscribe(remotestream).then(() => { console.log(`user ${remotestream.getUserId()} unsubscribe success`); }) .catch(error) { console.log('unsubscribe fail'); } }) .on('stream-subscribed', (data) => { let remotestream = data.stream; console.log(`user ${remotestream.getUserId()} subscribe success`); }) .on('stream-published',(data) => { let localstream = data.stream; localstream.play('self-player').then(() => { console.log('localstream play success'); }); console.log(`user ${localstream.getUserId()} publish success`); }) .on('stream-updated', (data) => { let stream = data.stream; console.log(`user ${stream.getUserId()} update`); }); client.init('room').then(() => { client.join('token').then(() => { const localstream = BRTC.createStream({ video: true, audio: true, cameraId: 'herhjerh4th', microphoneId: '976i5j64u6u56' }); localstream.setVideoProfile('720p'); localstream.setAudioProfile('standard'); localstream.init(() => { client.publish(localstream).then(() => { console.log('localstream published'); }); }) .catch(error) { console.log('create localstream fail', error); } }); })
Web
BRTC Web SDK 一个互动低延时 Web 实时通信解决方案。它是通过 HTML 网页加载的 JavaScript 库。开发者可以使用 BRTC Web SDK 提供的 API 建立连接,控制实时音视频通话或者直播服务。
API 概要
Documentation
Modules
Classes
Events
Error
Installation
NPM 集成
在项目脚本里引入模块。
Script 集成
您只需要在您的 Web 页面中添加如下代码即可:
Usage
Tutotials