Install
npm
npm i --save-dev @efox/webrtc
yarn
yarn add -s @efox/webrtc
Use it in your project
import { RtcService } from '@efox/webrtc'
APIs
RtcService
Function | Summary | Useage | Paramter | ReturnType |
---|---|---|---|---|
initWebRtc | 根据参数初始化实例,并根据refs中的uid自动填装绑定video标签 | initWebRtc(param) | param: initParam | Promise |
startLiveAndJoinRoom | 开播并创建房间 | startLiveAndJoinRoom(param) | param: startLiveParam | Promise |
joinRoom | 加入房间 | joinRoom(uid, roomid) | uid: string, roomid: string | Promise |
showVideo | 将流填充入对应el中 | showVideo(el, MediaStreamId) | el: HTMLVideoElement, MediaStreamId: string | void |
publishVideo | 根据type发布视频 | publishVideo(type, param) | type: 'screen'or'camera', param: publishParam | Promise |
unpublishVideo | 取消发布 | unpublishVideo(type) | type: 'screen'or'camera' | Promise |
enableVideo | 打开视频采集 | enableVideo(type) | type: 'screen'or'camera' | void |
disableVideo | 关闭视频采集 | disableVideo(type) | type: 'screen'or'camera' | void |
enableAudio | 打开音频采集 | enableAudio(type) | type: 'screen'or'camera' | void |
disableAudio | 关闭音频采集 | disableAudio(type) | type: 'screen'or'camera' | void |
getVideoDevice | 获取视频设备 | getVideoDevice(fn) | fn:Function(deviceInfo?: {deviceId: string}) | void |
getAudioDevice | 获取音频设备 | getAudioDevice(fn) | fn:Function(deviceInfo?: {deviceId: string}) | void |
setPublisherVolume | 设置麦克风音量 | setPublisherVolume(type, volume) | type: 'screen' | 'camera', volume: 0-100 |
changeRoom | 更换房间 | changeRoom(uid) | uid: string | Promise |
addRefs | 添加展示流的标签 | addRefs(refs) | refs: videoRefs[] | void |
addBaseInfo | 添加基本信息 | addBaseInfo(param) | param: baseInfo | void |
onLiveRoomInfoChange | 房间信息更改监听 | onLiveRoomInfoChange(fn) | fn: (data?: liveRoomInfo) => void | void |
offLiveRoomInfoChange | 取消监听 | offLiveRoomInfoChange(fn) | fn: (data?: liveroomInfo) => void | void |
leaveRoom | 离开房间 | leaveRoom() | null | Promise |
otherType
Name | value | Summary |
---|---|---|
publishParam | audio?: boolean | 是否发布音频 |
video?: {videoMode: number; deviceId?: string} | videoMode: 视频开播档位(流畅度,默认为7档), deviceId: 输入设备id,可不填 | |
startLiveParam | uid: string | udb登录用户的id |
liveBzType: number | 中台开播类型,需向中台申请 | |
baseInfo | uid?: string | udb登录用户的id |
otp?: string | udb登录用户的token | |
appid?: number | 系统id | |
region?: string | 地区代码 | |
videoRefs | uid: string | udb登录用户的id |
mainRef: HTMLVideoElement | 展示摄像头流的video元素 | |
extRef: HTMLVideoElement | 展示共享视频流的video元素 | |
liveRoomInfo | liveBzType: number | 中台开播类型,需向中台申请 |
owUser: any | ||
channelInfo: any | 频道信息 | |
liveInterconnectStreamInfos: any | 房间内流推送信息 | |
audienceLineStreamInfos: any | ||
extend: string | ||
audienceCdnStatus: any | ||
initParam | uid: string | udb登录用户id |
otp: string | udb登录用户token | |
appid: number | 系统id | |
region: string | 地区代码, 例如印度为'ap_south' | |
roomid?: number | 房间号,若是开播,可不传,加入房间需传 | |
start?: boolean | 是否开播,可不传 | |
refs: videoRefs[] | ||
groupType: string | 组类型 | |
businessType?: number | 业务类型,可不传 | |
liveBzType: number | 中台开播类型,需向中台申请 | |
cameraPublishParam?: publishParam | ||
screenPublishParam?: publishParam | ||
initPublish?: boolean | 初始化完成后是否立刻推送流,默认不推送 |
videoMode
档位值 | 分辨率 | 码率 | 帧率 |
---|---|---|---|
1 | 320*180 | 200kbps | 15fps |
2 | 320*240 | 200kbps | 15fps |
3 | 640*360 | 400kbps | 15fps |
4 | 640*480 | 600kbps | 15fps |
5 | 960*544 | 1000kbps | 24fps |
6 | 1280*720 | 1600kbps | 24fps |
7 | 1920*1080 | 4500kbps | 24fps |