Class: WebRTC

WebRTC


new WebRTC()

请使用 WebRTC.getInstance 来初始化音视频环境.

Methods


<static> getInstance(options)

此接口为单例模式

Parameters:
Name Type Description
options Object

配置参数

Properties
Name Type Argument Default Description
nim NIM

NIM 实例

container Node

播放自己视频画面的dom容器节点,如div、span等非流媒体节点,可为null,可通过后续播放操作时再传入

remoteContainer Node

播放对方画面的dom容器节点,如div、span等非流媒体节点,可为null,可通过后续播放操作时再传入

debug Boolean <optional>
false

是否开启debug模式,默认不开启,debug模式下浏览器会打印log日志


<static> setPlayVolume()

播放音量调整

Parameters:
Name Type Description
options.volume Number

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

options.account String

账号[WebRTC], 不设置则操作所有远程流

options.uid String

账号[NRTC], 不设置则操作所有远程流

Returns:

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

Type
Number

call(options)

双人通话:主叫发起通话

Parameters:
Name Type Description
options Object

请求参数对象

Properties
Name Type Description
type Number

通话类型

webrtcEnable Boolean

是否支持WebRTC方式接入,可选,默认为不开启

account String

对方账号

pushConfig Object

推送配置

sessionConfig Object

通话配置

Returns:
Type
Promise

changeRoleToAudience()

多人通话:改变自己在房间中的角色(观众):只允许接收其他人的音频和视频,不能发送自己的音频和视频

Returns:
Type
Promise

changeRoleToPlayer()

多人通话:改变自己在房间中的角色(互动者):可以发送自己的音频和视频给房间中的其他人

Returns:
Type
Promise

control(controlRequestParam)

双人通话:通话过程中发送控制指令: 例如开关摄像头、麦克风,音视频互相切换,没有可用设备

Parameters:
Name Type Description
controlRequestParam Object
Properties
Name Type Description
channelId String

当前会话的唯一ID值

command Number

会话控制指令

Returns:
Type
NULL

createChannel(options)

多人通话:创建房间

Parameters:
Name Type Description
options Object

配置对象

Properties
Name Type Description
channelName String

房间房号,可以任意英文字母和数组的组合

custom String

扩展字段,在通话的创建和加入之间传递自定义的额外信息

webrtcEnable Boolean

如果需要与 WebRTC 客户端互通,需要指定 WebRTC 兼容开关 webrtcEnable 为 true, 如果没有 WebRTC 客户端参与, 不要打开该开关。

createChannelRequestParam.rtmpConf Object

推流配置参数。

Returns:
Type
Promise

destroy()

实例销毁


detectNetworkStatus(options)

探测网络状况

Parameters:
Name Type Description
options Object

参数对象

Properties
Name Type Argument Description
detectTime Number

探测时间建议20s以上;sdk内部最少5秒

fromDevice Boolean <optional>

是否通过本地摄像头作为探测源(优先级1)

imageNode Element <optional>

标签节点,传入该参数,则可以使用本地图片作为探测源(优先级2)

videoNode Element <optional>


getDevices(type)

获取设备列表

Parameters:
Name Type Description
type Number

设备类型,详见: DEVICE_TYPE

Returns:

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

Type
Promise

getLocalAudioVolume()

得到mic采集到的音量

Returns:
Type
number

hangup()

双人通话:挂断通话

Returns:
Type
NULL

initSignal()

初始化信令

  • 信令通道初始化完毕之后, 开发者可以启用音视频相关的 UI, 比如说展示呼叫别人的按钮
  • 信令通道初始化失败的时候, 请展示错误并禁用所有音视频相关的 UI
  • 当信令通道断开时, 会触发 signalClosed 事件
  • 注:该方法目前是个假的方法,直接返回Promise.resolve(),原因是为了和agent方案保持一致
Returns:
Type
Promise

joinChannel(options)

多人通话:加入房间

Parameters:
Name Type Description
options Object

配置对象

Properties
Name Type Description
channelName String

房间房号,可以任意英文字母和数组的组合

role Number

个人角色,WebRTC.ROLE_PLAYER表示互动者,WebRTC.ROLE_AUDIENCE表示观众

type Number

房间通话类型,音频、视频

sessionConfig Object

通话配置

Returns:
Type
Promise

leaveChannel()

多人通话:离开房间

Returns:
Type
Promise

response(options)

双人通话:被叫响应通话

Parameters:
Name Type Description
options Object

配置对象

Properties
Name Type Description
accepted Boolean

回应类型

beCalledInfo Object

呼叫信息,必传,该值可以在 beCalling 回调事件中获取(即BeCallingEvent)

sessionConfig Object

通话配置内容,具体信息请参考上面的主叫发起通话时的参数注解

channelId String

推送配置

command Number

通话控制命令

Returns:
Type
Promise

resumeLocalStream()

恢复本地视频流

Returns:
Type
NULL

resumeRemoteStream(account)

恢复所有远程视频流

Parameters:
Name Type Description
account String
Returns:
Type
NULL

setAudioBlack(account)

设置指定用户静音

Parameters:
Name Type Description
account String
Returns:
Type
NULL

setAudioStart(account)

开启音量

Parameters:
Name Type Description
account String
Returns:
Type
NULL

setAudioStart(options)

绕过IM登录,直接开启音视频通话,需传入im登录信息,此接口目前仅适用于 白板+音视频 场景
注意此入口参数为白板服务端透传,无需用户手动拼接

Parameters:
Name Type Description
options Object

请求参数对象

Properties
Name Type Description
channelId Number

房间ID

netcallType number

通话类型

rtcServerMap Object

rtc服务端地址列表

accountUidMap object

account与uid的映射表

Returns:
Type
Promise

setIsPrivateDeployment(isPrivateDeployment)

设置是否使用音视频代理

Parameters:
Name Type Description
isPrivateDeployment Boolean
Returns:
Type
NULL

setMixConf(param)

视频和演示混频

Parameters:
Name Type Description
param Object

配置对象

Properties
Name Type Description
enableMixVideo Boolean

是否启动混频功能

videoLayout Number

混频时摄像头的布局

videoCompressSize Number

混频时摄像头压缩的比例


setPrivateDeploymentConf()

配置音视频代理域名

Parameters:
Name Type Description
privateDeploymentConf.wssServer String

媒体网关服务器域名

privateDeploymentConf.turnServer String

媒体中转服务器域名

Returns:
Type
NULL

setVideoViewRemoteSize(options)

设置对端视频画面大小

Parameters:
Name Type Description
options Object

配置对象

Properties
Name Type Description
account String

账号

width Number

宽度

height Number

高度

cut Boolean

是否裁剪

Returns:
Type
Promise

setVideoViewSize(setVideoViewSizeRequestParam)

设置本端视频画面大小

Parameters:
Name Type Description
setVideoViewSizeRequestParam Object

配置对象

Properties
Name Type Description
width Number

宽度

height Number

高度

cut Boolean

是否裁剪

Returns:
Type
Promise

startLocalStream(node)

开启本地画面

Parameters:
Name Type Description
node DOM

本地画面待渲染的DOM节点

Returns:
Type
Promise

startRecordMp4(account)

开启视频录制(6.2.0版本开始废弃该接口)
推荐使用 startMediaRecording

Parameters:
Name Type Description
account String

录制的目标账号,不传或者为空时,默认录制自己

Deprecated:
  • Yes
Returns:
Type
Promise

startRecordMp4()

结束视频录制(6.2.0版本开始废弃该接口)
推荐使用 stopMediaRecording

Deprecated:
  • Yes
Returns:
Type
Promise

startRemoteStream(startRemoteStreamRequestParam)

开启对方画面

Parameters:
Name Type Description
startRemoteStreamRequestParam Object

配置对象

Properties
Name Type Description
account String

目标账号

node DOM

视频显示的DOM容器

poster String

无视频流时的默认视频海报图片

Returns:
Type
Promise

startRtc()

开启RTC连接

Returns:
Type
Promise

stopLocalStream()

关闭本地画面

Returns:
Type
NULL

stopRecordAac()

结束混音录制(6.2.0版本开始废弃该接口)
推荐使用 stopMediaRecording

Deprecated:
  • Yes
Returns:
Type
Promise

stopRemoteStream(account)

关闭对方画面

Parameters:
Name Type Description
account String

目标账号

Returns:
Type
NULL

suspendLocalStream()

暂停本地视频流

Returns:
Type
NULL

suspendRemoteStream(account)

挂起所有远程视频流

Parameters:
Name Type Description
account String
Returns:
Type
NULL

switchAudioToVideo()

双人通话:切换视频模式

Returns:
Type
NULL

switchVideoToAudio()

双人通话:切换音频模式

Returns:
Type
NULL

Events


beCalling

beCalling 收到呼叫请求

Type: object
Properties:
Name Type Description
channelId number

加入频道ID

account number

用户账号(WebRTC有意义)

uid string

用户uid


callAccepted

callAccepted 主叫收到被叫应答通知: 接受

Type: object

callerAckSync

callerAckSync 其他端已处理的通知

Type: object

callRejected

callRejected 主叫收到被叫应答通知: 拒绝

Type: object

control

control 通话进行中收到对端的控制通知

Type: object

hangup

hangup 收到挂断通知

Type: object

sessionDuration

sessionDuration 通话计时完成的通知

Type: object