Others
这里整理了一些单独暴露出来的方法和对象,一般在一些特殊的场景中需要
version
string
类型 该对象显示当前 SDK 的版本号信息
import { version } "pili-rtc-web";
console.log("current version");
browserReport
{ support: boolean }
类型 如果 support
为 false,表示 SDK 不兼容这个浏览器
isChromeExtensionAvailable
Promise<boolean>
返回 检查是否安装了 Chrome 的屏幕共享插件,详细参考 屏幕共享
createCustomTrack(mediaStreamTrack, tag, bitrate)
如果您熟悉 WebRTC 相关的 API,通过这个方法允许您通过 WebRTC 原生的媒体对象 MediaStreamTrack
创建自定义的 SDK 内部媒体对象 Track
MediaStreamTrack
mediaStreamTrack:浏览器 WebRTC 原生的媒体对象
Electron 的 desktopCapture 通过特殊的
getUserMedia
API 会返回这个原生的媒体对象,可以利用这个方法来在 Electron 应用中实现屏幕共享
tag: string 可选
转换成 SDK 的 Track 对象后所打上的 tag
bitrate: number 可选
转换成 SDK 的 Track 后,用于发布时的比特率,单位 kbps
Track>
返回 Promise<用法可以参考下面的例子,这样只要是能获取 MediaStreamTrack
的方法都能和 SDK 耦合起来。不用局限于媒体设备采集。
import { createCustomTrack } from "pili-rtc-web";
const mediaStream = await navigator.mediaDevices.getUserMedia({ audio: true });
const audioMediaStreamTrack = mediaStream.getAudioTracks()[0];
const videoMediaStreamTrack = mediaStream.getVideoTracks()[0];
// 这里的 audioTrack / videoTrack 就是 SDK 内部的 Track 对象,可以直接用来在 Track 模式下发布
const audioTrack = await createCustomTrack(audioMediaStreamTrack, "audio-track", 64);
const videoTrack = await createCustomTrack(videoMediaStreamTrack, "video-track", 600);