Class: WebRTC/NRTC

WebRTC/NRTC

音视频操作类,WebRTC与NRTC公共方法均会放到本文档中,其个性化使用方法请参考WebRTC/NRTC独立文档


new WebRTC/NRTC()

请使用 WebRTC.getInstance 来初始化音视频环境.(NRTC为:NRTC.getInstance)

Methods


cleanLogFile()

清除保存的日志。

Returns:
Type
Promise

cleanMediaRecording(options)

清除录制的音视频

Parameters:
Name Type Description
options Object

参数对象

Properties
Name Type Description
recordId String

录制id,可以通过listMediaRecording接口获取

Returns:
Type
Promise

downloadMediaRecording(param, options)

下载录制的音视频

Parameters:
Name Type Description
param Object

参数对象

options Object

参数对象

Properties
Name Type Description
recordId String

录制id,可以通过listMediaRecording接口获取

Returns:
Type
Promise

downLogFile()

下载保存的日志。

Returns:
Type
Promise

enableLocalAudio(enable)

开启/禁止本地音频(关闭设备停止推流/启用开始推流)

Parameters:
Name Type Description
enable Boolean

true:开启音频功能 false:关闭音频功能,并关闭麦克风。

Returns:
Type
Promise

enableLocalVideo(enable)

开启/禁止本地视频(关闭设备停止推流/启用开始推流)

Parameters:
Name Type Description
enable Boolean

true:开启视频功能 false:关闭视频功能,并关闭摄像头。

Returns:
Type
Promise

getAccount()

获取当前登录的 IM 账号

Returns:
Type
String

getAudioMixingPlayedTime()

获取伴音的播放进度

Returns:
Type
Number

getAudioMixingTotalTime()

获取伴音文件的总时长

Returns:
Type
Number

getCaptureVolume(accountList)

获取当前账号成员的音视频的播放状态

Parameters:
Name Type Description
accountList Array

accoutList,账号列表,可以为空,表示当前房间里所有成员

Returns:

播放状态

Type
Object

getCaptureVolume()

采集音量查询

Parameters:
Type Description
Void
Returns:

volume 音量大小,取值范围:0-255

Type
Number

getChannelInfo()

获取当前所在频道信息

Returns:

channelId,uid,account

Type
Object

getDevices(options)

获取设备列表

Parameters:
Name Type Description
options Object

配置参数

Properties
Name Type Description
type Number

设备类型

Returns:

未传type时为Object,传type时为Array

Type
Promise

getPlayVolume(options)

播放音量查询

Parameters:
Name Type Description
options Object

配置参数

Properties
Name Type Description
account String

账号[WebRTC]

uid String

账号[NRTC]

Returns:

volume 音量大小,取值范围:0-255

Type
Number

getUid()

获取当前登录的 uid

Returns:
Type
String

isSupportWebrtc()

是否支持webrtc

Returns:
Type
Boolean

listMediaRecording()

枚举录制的音视频

Returns:
Type
Promise

muteLocalAudioStream(options)

开关本地音频发送

Parameters:
Name Type Description
options Object

参数对象

Properties
Name Type Description
mute Boolean

true:不发送本地音频流,false:发送本地音频流(默认)

Returns:
Type
Promise

muteLocalVideoStream(options)

开关本地视频发送

Parameters:
Name Type Description
options Object

参数对象

Properties
Name Type Description
mute Boolean

true:不发送本地视频流,false:发送本地视频流(默认)

Returns:
Type
Promise

muteRemoteAudioStream(options)

接收/停止接收指定音频流。

Parameters:
Name Type Description
options Object

参数对象

Properties
Name Type Description
account Number

指定用户id[WebRTC]

uid Number

指定用户id[NRTC]

mute Boolean

true:停止接收指定音频流;false:继续接收指定音频流(默认)。

Returns:
Type
Promise

muteRemoteVideoStream(options)

接收/停止接收指定视频流。

Parameters:
Name Type Description
options Object

参数对象

Properties
Name Type Description
account Number

指定用户id[WebRTC]

uid Number

指定用户id[NRTC]

mute Boolean

true:停止接收指定视频流;false:继续接收指定视频流(默认)。

Returns:
Type
Promise

openLocalAudio(options)

开启本地麦克风(暂不开放)

Parameters:
Name Type Description
options Object

配置参数

Properties
Name Type Argument Description
videoDeviceId String <optional>

视频设备ID,不传则默认第一个

Returns:
Type
Promise

pauseAudioMixing()

暂停本地语音伴音。

Returns:
Type
Promise

playMediaRecording(options)

播放视频录制

Parameters:
Name Type Description
options Object

参数对象

Properties
Name Type Description
recordId String

录制id,可以通过listMediaRecording接口获取

view Element

音频或者视频画面待渲染的DOM节点,如div、span等非流媒体节点

Returns:
Type
Promise

rate(options)

给某次通话评分

Parameters:
Name Type Description
options Object
Properties
Name Type Argument Description
cid String
uid String
rate Number

1-5,整数

description String <optional>

描述


resumeAudioMixing()

恢复本地语音伴音,伴音文件将从暂停时位置开始播放。

Returns:
Type
Promise

setAudioMixingPlayTime(playStartTime)

设置伴音播放的位置,单位为ms

Parameters:
Name Type Description
playStartTime Number

伴音播放的位置

Returns:
Type
Promise

setAudioMixingVolume(volume)

设置伴音的音量

Parameters:
Name Type Description
volume Number

伴音文件的音量

Returns:
Type
Promise

setAudioProfile(options)

设置音频属性

Parameters:
Name Type Description
options Object

参数对象

Properties
Name Type Description
highAudio Boolean

高清语音

Returns:
Type
Void

setCaptureVolume(volume)

采集音量调整

Parameters:
Name Type Description
volume Number

音量大小,取值范围:0-255

Returns:

volume 实际设置音量大小,取值范围:0-255

Type
Number

setClientRole(role)

设置场景下的用户角色
多人通话:改变自己在房间中的角色(互动者),是否可以发送自己的音频和视频给房间中的其他人

Parameters:
Name Type Description
role Number

用户角色:0主播,1观众(默认0)

Returns:
Type
Promise

setLocalRenderMode(options)

设置本端视频画面大小

Parameters:
Name Type Description
options Object

配置对象

Properties
Name Type Description
width Number

宽度

height Number

高度

cut Boolean

是否裁剪

Returns:
Type
Void

setLocalVideoRenderer(options)

设置本地视图。

Parameters:
Name Type Description
options Object

参数对象

Properties
Name Type Description
view Element

本地画面待渲染的DOM节点,如div、span等非流媒体节点

Returns:
Type
Void

setMixMediaConfig(options)

摄像图画面和屏幕共享画面混频;需要在建立会话之前设置

Parameters:
Name Type Description
options Object

参数对象

Properties
Name Type Description
enableMixVideo Boolean

必须 是否启动混频功能

videoLayout Number

混频时摄像头的布局

videoCompressSize Number

混频时摄像头压缩的大小[旧功能,不推荐]

videoMixRatio Number

混频时压缩的比例[新功能]

videoSecWinType Number

混频时设置为小窗的流类型[新功能]

Returns:
Type
Promise

setRemoteRenderMode(options)

设置对端视频画面大小

Parameters:
Name Type Description
options Object

配置对象

Properties
Name Type Description
account String

账号,WebRTC适用

uid String

账号,NRTC适用

width Number

宽度

height Number

高度

cut Boolean

是否裁剪

Returns:
Type
Void

setRemoteVideoRenderer(options)

设置远端视图。

Parameters:
Name Type Description
options Object

参数对象

Properties
Name Type Description
account Number

IM账号(NRTC不适用,WebRTC可以使用account/uid二选一)

uid Number

uid账号

view Element

本地画面待渲染的DOM节点,如div、span等非流媒体节点

Returns:
Type
Void

setVideoProfile(options)

设置视频属性

Parameters:
Name Type Description
options Object

参数对象

Properties
Name Type Description
quality String

视频质量

frameRate String

视频帧率

Returns:
Type
Void

startAudioMixing(options)

云端音乐文件和本地麦克风声音混合;需要在启动麦克风之后使用

Parameters:
Name Type Description
options Object

参数对象

Properties
Name Type Description
audioFilePath String

必须,云端音频文件路径

loopback String

可选,是否循环播放,缺省为false,表示播放一次就结束(这里如果是false,则cycle参数不生效)

replace String

可选,是否替换麦克风采集的音频数据,缺省为false

cycle Number

可选,循环的次数,需要loopback参数置为true(如果想无限循环,cycle设置为0,loopback设置为true),缺省为0,如果loopback为true,表示无限循环,如果loopback为false,该参数不生效

playStartTime Number

可选,设置音频文件开始播放的位置,单位为 s。缺省设为 0,即从头开始播放

volume Number

可选,设置伴音的音量

auidoMixingEnd function

可选,伴音文件播放完成的通知反馈(正常停止伴音或关掉通话获取其他原因停止伴音不会触发)

Returns:
Type
Promise

startDevice(options)

开启设备

Parameters:
Name Type Description
options Object

配置参数

Properties
Name Type Argument Description
type Number

设备类型

device Object <optional>

设备, 如果没有指定, 那么开启该类型的第一个设备

Properties
Name Type Argument Description
deviceId String <optional>

设备id

enableEchoCancellation Boolean <optional>

是否使用回声消除来尝试去除通过麦克风回传到扬声器的音频

account String

im账号,可选,不填为操作指定人

uid String

uid,可选,不填为操作指定人

Returns:
Type
Promise

startMediaRecording(param)

开启单人视频录制

Parameters:
Name Type Description
param Object

参数对象

Properties
Name Type Description
account String

目标账号(NRTC值为 UID)

uid String

如果是远程流录制,account或uid二选一

type String

如果是自己流录制,'audio','video'或'screen'

reset Boolean

如果之前的录制视频未下载,是否重置,默认false

Returns:

包含recordId值,用于下载等操作

Type
Promise

startPreview(options)

开启预览本地画面(暂不开放)

Parameters:
Name Type Description
options Object

配置参数

Properties
Name Type Argument Description
videoDeviceId String <optional>

视频设备ID,不传则默认第一个

Returns:
Type
Promise

startPreview()

关闭本地麦克风(暂不开放)

Returns:
Type
Promise

startPreview()

停止预览本地画面(暂不开放)

Returns:
Type
Promise

stopAudioMixing()

停止伴音

Returns:
Type
Promise

stopDevice(options)

关闭设备

Parameters:
Name Type Description
options Object

配置参数

Properties
Name Type Description
type Number

设备类型

Returns:
Type
Promise

stopMediaRecording(options)

结束视频录制

Parameters:
Name Type Description
options Object

参数对象

Properties
Name Type Description
recordId String

录制id,可以通过listMediaRecording接口获取

Returns:
Type
Promise

takeSnapshot(options)

截取指定用户的视频画面(文件保存在浏览器默认路径)

Parameters:
Name Type Description
options Object

配置参数

Properties
Name Type Description
account String

指定用户的account

uid Number

指定用户的uid

Returns:
Type
Promise

updateRtmpHost()

更换互动直播主画面

Parameters:
Name Type Description
param.uid String

主画面的uid

Returns:
Type
Promise