Class: NetcallWeixin

NetcallWeixin

音视频操作类,RTC与NRTC业务方法均在此类中,会根据是否传入nim对象动态加载对应的方法,每个方法后面注明了适用场景,敬请注意!


new NetcallWeixin()

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

Methods


<static> destroy()

清除类引用

Parameters:
Type Description
Void
Returns:
Type
Void

<static> getInstance(options)

此接口为单例模式,获取音视频操作实例

Parameters:
Name Type Description
options Object

初始配置项

Properties
Name Type Argument Description
nim Object <optional>

im实例,传入此项后会初始化RTC部分API,此时拥有IM+音视频能力;不传则仅仅拥有音视频能力

debug Boolean

是否开启调试, 如果开启调试, 将会在控制台输出一些log。默认false不输出日志, 可以传true来开启日志。

Returns:

小程序音视频操作实例对象

Type
Object
Example
// RTC流程,开启IM+音视频逻辑,`前提需要引入IM的SDK`
import NIM from 'path/to/NIM_Web_NIM_weixin.js'
import Netcall from 'path/to/NIM_Web_Netcall_weixin.js'
NIM.use(Netcall)
nim = NIM.getInstance({
  // 初始化SDK
  // debug: true
  appKey: 'appKey',
  account: 'account',
  token: 'token',
  onconnect: onConnect
})
function onConnect() {
  console.log('连接成功');
  netcallInstance = Netcall.getInstance({
    debug: true,
    nim: nim
  })
 netcallInstance.on('syncDone', (data) => {
   console.log('音视频通知:同步成功')
 })
 netcallInstance.on('clientLeave', (data) => {
   console.log('音视频通知:有人离开了')
 })
 netcallInstance.on('clientJoin', (data) => {
   console.log('音视频通知:有人加入了')
 })
 netcallInstance.on('clientUpdate', (data) => {
   console.log('音视频通知:有人更新了')
 })
 netcallInstance.on('liveRoomClose', (data) => {
   console.log('音视频通知:房间解散了')
 })
 netcallInstance.on('kicked', (data) => {
   console.log('音视频通知:被踢了')
 })
 netcallInstance.on('joinChannel', (data) => {
   console.log('IM通知:有人加入房间了')
 })
 netcallInstance.on('callAccepted', (data) => {
   console.log('IM通知:对方接听了')
 })
 netcallInstance.on('callRejected', (data) => {
   console.log('IM通知:对方拒绝了')
 })
 netcallInstance.on('control', (data) => {
   console.log('IM通知:收到控制指令')
 })
 netcallInstance.on('hangup', (data) => {
   console.log('IM通知:对端挂断了')
 })
 netcallInstance.on('callerAckSync', (data) => {
   console.log('IM通知:本通通话在其他端已经处理了')
 })
}
// NRTC流程,只有音视频逻辑,仅拥有实现加入、离开房间能力
import Netcall from 'path/to/NIM_Web_Netcall_weixin.js'
netcallInstance = Netcall.getInstance({ 
 debug: true,
 appkey: 'appkey',
 })
 netcallInstance.on('syncDone', (data) => {
   console.log('音视频通知:同步成功')
 })
 netcallInstance.on('clientLeave', (data) => {
   console.log('音视频通知:有人离开了')
 })
 netcallInstance.on('clientJoin', (data) => {
   console.log('音视频通知:有人加入了')
 })
 netcallInstance.on('clientUpdate', (data) => {
   console.log('音视频通知:有人更新了')
 })
 netcallInstance.on('liveRoomClose', (data) => {
   console.log('音视频通知:房间解散了')
 })
 netcallInstance.on('kicked', (data) => {
   console.log('音视频通知:被踢了')
 })

call(callRequestParam)

<RTC适用>
双人通话:主叫发起通话

Parameters:
Name Type Description
callRequestParam CallRequestParam

请求参数对象

Properties
Name Type Description
type Number

通话类型:1音频,2视频

callee String

呼叫账号(IM账号)

forceKeepCalling Boolean

是否开启持续呼叫,true是开启持续呼叫

pushConfig Object

推送配置

Properties
Name Type Description
custom String

自定义字段

Returns:
Type
Promise

control(controlParam)

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

Parameters:
Name Type Description
controlParam controlParam
Properties
Name Type Argument Description
command Number

会话控制指令

cid Number <optional>

要发送指令的通话的 channelId, 如果不填那么默认为当前通话

Returns:
Type
Promise

createChannel(createChannelRequestParam)

<RTC适用>
多人通话:创建房间

Parameters:
Name Type Description
createChannelRequestParam CreateChannelRequestParam

配置对象

Properties
Name Type Description
channelName String

创建房间名称

custom String

自定义参数

Returns:
Type
Promise

createChannel()

<NRTC适用>
创建房间(为了保持接口一致,此接口为空,请勿直接调用)

Parameters:
Type Description
null
Returns:
Type
void

getUploadUserList()

<NRTC适用>
获取当前当前时间下,房间的推流用户列表

Parameters:
Type Description
Void
Returns:
Type
Void

hangup()

<RTC适用>
双人通话:挂断通话

Parameters:
Type Description
Void
Returns:
Type
Promise

joinChannel(joinChannelParam)

<RTC适用>
多人通话:加入房间

Parameters:
Name Type Description
joinChannelParam Object

配置对象

Properties
Name Type Argument Description
channelName String

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

mode Number

模式,0音视频,1纯音频,2纯视频,3静默(无音频无视频)

role Number

角色,0-主播 1-观众(默认0)

liveEnable String <optional>

是否开启旁路直播,0不需要,1需要

rtmpRecord Number <optional>

是否开启互动直播录制,0不需要,1需要(默认0)

recordAudio Number <optional>

是否开启音频实时音录制,0不需要,1需要(默认0)

recordVideo Number <optional>

是否开启视频实时音录制,0不需要,1需要(默认0)

recordType String <optional>

录制模式,0混单(产生混合录制文件+单独录制文件) 1只混(只产生混合录制文件) 2只单(只产生单独录制文件)

Returns:
Type
Promise

joinChannel(joinChannelParam)

<NRTC适用>
加入房间

Parameters:
Name Type Description
joinChannelParam Object
Properties
Name Type Argument Description
channelName String

房间名称

scene Number

通话类型:1:双人、2:多人

accid String

加入房间的用户名称(可重复)

mode Number

模式,0音视频,1纯音频,2纯视频,3静默(无音频无视频)

role Number

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

uid Number <optional>

用户唯一标识(建议五位数以上),如果传入则采用传入值,否则SDK自动生成

rtmpRecord Number <optional>

是否开启互动直播录制,0不需要,1需要(默认0)

recordAudio Number <optional>

是否开启音频实时音录制,0不需要,1需要(默认0)

recordVideo Number <optional>

是否开启视频实时音录制,0不需要,1需要(默认0)

recordType String <optional>

录制模式,0混单(产生混合录制文件+单独录制文件) 1只混(只产生混合录制文件) 2只单(只产生单独录制文件)

liveEnable Number <optional>

是否旁路直播,0:不需要,1:需要

Returns:
Type
Promise

leaveChannel()

<RTC适用>
多人通话:离开房间

Parameters:
Type Description
Void
Returns:
Type
Promise

leaveChannel()

<NRTC适用>
离开房间

Parameters:
Type Description
Void
Returns:
Type
Promise

response(responseParam)

<RTC适用>
双人通话:被叫响应通话

Parameters:
Name Type Description
responseParam Object

配置对象

Properties
Name Type Description
caller String

呼叫者账号

accepted Boolean

接听与否

type Number

通话类型 1 音频 2 视频

cid String

房间id

Returns:
Type
Promise

startRtc()

<RTC适用>
双人通话:开启音视频通话

Parameters:
Name Type Description
param.mode Number

模式,0音视频,1纯音频,2纯视频,3静默(无音频无视频)

param.recordVideo Number

视频实时音录制

param.recordAudio Number

音频实时音录制

param.rtmpRecord Number

互动直播录制

param.recordType String

录制模式 0-混单 1-只混 2-只单

param.isHostSpeaker Number

是否是主讲人,默认false

Returns:
Type
Promise

switchMode(mode)

<RTC适用>
更新推流模式,注意同步切换live-pusher组件的摄像头以及麦克风状态。音视频:打开麦克风摄像头;纯音频:打开麦克风关闭摄像头;纯视频:关闭麦克风打开摄像头;静默:关闭麦克风摄像头

Parameters:
Name Type Description
mode Number

模式,0音视频,1纯音频,2纯视频 3 静默

Returns:
Type
Promise

switchMode(mode)

<NRTC适用>
更新推流模式,注意同步切换live-pusher组件的摄像头以及麦克风状态。音视频:打开麦克风摄像头;纯音频:打开麦克风关闭摄像头;纯视频:关闭麦克风打开摄像头;静默:关闭麦克风摄像头

Parameters:
Name Type Description
mode Number

模式,0音视频,1纯音频,2纯视频 3 静默

Returns:
Type
Void