3.3.2 • Published 5 months ago

@xkit-yx/call-kit v3.3.2

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

网易云信 呼叫组件 API

安装

1.6.0 版本开始,呼叫组件将通过 npm 进行版本发包管理

npm install @xkit-yx/call-kit
// or
yarn add @xkit-yx/call-kit

单呼

详细请参照 ts 接口定义

使用示例

初始化

// 结合im的初始化
import NIM from 'xxxx' // im sdk path
import { NECall } from '@xkit-yx/call-kit'

let neCall: NECall
const im = NIM.getInstance({
  appKey: 'xxxx', // im appkey
  token: 'xxxx', // im token
  account: 'xxxx', // im account
  debugLevel: 'debug',
  lbsUrls: ['xxxx'],
  linkUrl: 'xxxx',
  onconnect: () => {
    neCall = new NECall({
      nim, // im 实例用户需要先初始化
      appKey, // 应用的 appKey,G2 平台的 appKey
      currentUserInfo: { accId: 'xxx', uid: 'xxx' }, // 当前用户的信息,accId 为 im 的 id,uid 为加入RTC的 id。accId 必填; uid 可选:不填系统将自动生成
      debug: true, // 是否需要开启日志,默认开启
      rtcConfig: {
        videoResolution: VIDEO_QUALITY.VIDEO_QUALITY_720p,
        videoFrameRate: VIDEO_FRAME_RATE.CHAT_VIDEO_FRAME_RATE_NORMAL,
        audioQuality: 'speech_low_quality',
      }, // rtcConfig 用来设置 RTC 可选。相关参数参照 可以参考[G2官方文档](https://doc.yunxin.163.com/docs/jcyOTA0ODM/zUxMDQzOTM?platformId=50082)
    })
  },
  ondisconnect: () => {
    neCall?.destroy()
  },
})

主叫

// 发起呼叫
const calleeId = 'xxx' // 被叫的im id
neCall.call({
  accId: calleeId, // 被叫 im 的 id
  callType: '1', //
})
// 设置视图
const localView = document.getElementById('localView')
const remoteView = document.getElementById('remoteView')
neCall.setLocalView(localView)
neCall.setRemoteView(remoteView, calleeId)
// 取消呼叫
neCall.hangup()

被叫

// 订阅邀请事件
neCall.on('onReceiveInvited', (value) => {
  // 用户可以触发视图,比如弹起邀请页面
})
// 设置视图
const localView = document.getElementById('localView')
const remoteView = document.getElementById('remoteView')
neCall.setLocalView(localView)
neCall.setRemoteView(remoteView, calleeId)
// 接受邀请,需要先设置视图
neCall.accept()
// 取消呼叫
neCall.hangup()

通话中,主叫与被叫

// 订阅会话建立事件
neCall.on('onCallConnected', (value) => {
  // 用户可以触发视图,比如弹起邀请页面
})
// 切换会话类型
neCall.switchCallType('2') // 入参为 callType
// 监听会话切换
neCall.on('onSwitchCallType', (value) => {})
// 开关本地视频
neCall.enableLocalVideo(true)
// 开关本地音频
neCall.enableLocalAudio(false)
// 挂断当前通话
neCall.hangup()

其他

// 订阅会话结束事件
neCall.on('onCallEnd', (value) => {
  // 用户可以触发视图,比如弹起邀请页面
  const reason = value.reason
  // 0:正常流程 | 1:token请求失败 | 2:呼叫超时 | 3:用户占线 | 4:nertc 初始化失败 | 5:加入 rtc 房间失败 | 6:cancel 取消参数错误 | 7:发起呼叫失败 | 8:对方rtc失败 | 9:其他端接受邀请 | 10:其他端拒绝邀请 | 11:通话中rtc 异常
})
//本端发送话事件
neCall.on('onMessageSent', (value) => {
  //当通话因为 取消、拒绝、超时或占线 结束时,组件会主动发送一条话单消息给对端,可以在此事件中更新本端的UI
})

群呼

详细请参照 ts 接口定义

使用示例

初始化

// 结合im的初始化
import NIM from 'xxxx' // im sdk path
import { NEGroupCall } from '@xkit-yx/call-kit'

let neGroupCall: NEGroupCall

const im = NIM.getInstance({
  appKey: 'xxxx', // im appkey
  token: 'xxxx', // im token
  account: 'xxxx', // im account
  onconnect: () => {
    neGroupCall = new NEGroupCall({
      im: im,
    })
  },
  shouldIgnoreMsg: (msg) => {
    if (msg.type === 'custom') {
      return neGroupCall?.receiveNimMsg(msg.content)
    }
    return false
  },
  ondisconnect: () => {
    neGroupCall?.destroy()
  },
})

主叫

// 发起呼叫
const members = ['accId1', 'accId2'] // 被叫的im id数组
neGroupCall.groupCall({ calleeList: members })
// 设置自己摄图
const myAccId = 'xxx' // 自己的im id
neGroupCall.setRtcView(dom, myAccId) // dom: 视图的dom
// 设置被邀请人的视图
members.forEach((accId) => {
  neGroupCall.setRtcView(dom, accId) // dom: 视图的dom
})
neGroupCall.jionRtc({ video: false }) // 参数为false时,只加入音频
// 挂断
neGroupCall.groupHangup()

被叫

// 订阅邀请事件
neGroupCall.on('onReceiveInvited', (value) => {
  // 用户可以触发视图,比如弹起邀请页面
})
// 接受邀请
neGroupCall.groupAccept()
// 设置视图
const myAccId = 'xxx' // 自己的im id
neGroupCall.setRtcView(dom, myAccId) // dom: 视图的dom
// 设置被邀请人的视图
members.forEach((accId) => {
  neGroupCall.setRtcView(dom, accId) // dom: 视图的dom
})
neGroupCall.jionRtc({ video: false }) // 参数为false时,只加入音频
// 拒绝
neGroupCall.groupHangup()

通话中,主叫与被叫

// 订阅用户变化通知
neGroupCall.on('onMembersChange', (value) => {
  // 用户变更
})
// 开关本地视频
neGroupCall.enableLocalVideo(true)
// 开关本地音频
neGroupCall.enableLocalAudio(false)
// 挂断当前通话
neGroupCall.groupHangup()

其他

// 订阅会话结束事件
neCall.on('onCallEnd', (value) => {
  // 通话结束
})
neGroupCall.groupInvite({ calleeList: ['accId1', 'accId2'] }) // 通话中邀请
neGroupCall.groupJoin({ callId: 'xxx' }) // 加入某个通话
neGroupCall.groupQueryCallInfo({ callId: 'xxx' }) // 查询某个通话的信息,参数不传就查询当前通话
3.3.2

5 months ago

3.3.1

8 months ago

2.3.0

8 months ago

3.3.0

8 months ago

3.2.0

9 months ago

3.1.2

9 months ago

3.1.1

12 months ago

3.1.0

1 year ago

3.0.1

1 year ago

3.0.0

1 year ago

2.2.0

2 years ago

2.1.2

2 years ago

2.0.3

2 years ago

2.1.1

2 years ago

2.0.2

2 years ago

2.1.3

2 years ago

2.1.0

2 years ago

1.9.4

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.9.3

2 years ago

1.9.2

2 years ago

1.9.1

2 years ago

1.9.0

2 years ago

1.8.4

3 years ago

1.8.3

3 years ago

1.8.2

3 years ago

1.8.1

3 years ago

1.8.0

3 years ago

1.7.1

3 years ago

1.7.0

3 years ago

1.6.5

3 years ago

1.6.4

3 years ago

1.6.3

3 years ago

1.6.2

3 years ago

1.6.1

3 years ago

1.6.0

3 years ago