brtc-js
v2.24.1
Published
baijiayun BRTC SDK
Downloads
4
Readme
百家云实时通信 SDK(BRTC SDK)
一个互动低延时 Web 实时通信解决方案。
Documentation
Modules
Classes
Events
Error
Installation
BRTC 通过 script 引用得到 BRTC 全局对象,或者也可以通过模块加载
<script src="./dist/BRTC.min.js"></script>
let BRTC = require('./dist/BRTC.min.js');
import * as BRTC from './dist/BRTC.min.js';
Usage
<div id="self-player"></div>
<div id="remote-player"></div>
const client = BRTC.createClient({
mode: 'live',
codec: 'h264',
appId: ''
});
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.join('roomId', 123, 'sig').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);
}
});