0.0.3 • Published 2 years ago
@xkit-yx/call-kit-wx-ui v0.0.3
使用介绍
安装
npm install @xkit-yx/call-kit-wx-ui @xkit-yx/call-kit
// or
yarn add @xkit-yx/call-kit-wx-ui @xkit-yx/call-kit
安装后 点击开发者工具中的菜单栏:工具 --> 构建 npm,具体参照:https://developers.weixin.qq.com/miniprogram/dev/devtools/npm.html
初始化
// app.js
// 全局 globalData 定义 neCall 跟 nim 对象
App({
onLaunch() {
// 用户需要在初始化nim的逻辑后,初始化neCall对象,并绑定到全局对象上
const nim = NIM.getInstance({
appKey: 'xxxxx',
token: 'xxxxx',
account: 'xxxxx',
debugLevel: 'debug',
lbsUrls: ['xxxxx'],
linkUrl: 'weblink.netease.im',
onconnect: () => {
this.globalData.nim = nim
this.globalData.neCall = new NECall({
nim,
appKey,
currentUserInfo: { accId: 'xxxxx' },
debug: true,
})
this.globalData.neCall.on('onReceiveInvited', () => {
// 接收到邀请后跳转到呼叫页面,路由用户可以自定义,该页面下需要包含 `@xkit-yx/call-kit-wx-ui` 相关的 UI 组件
wx.navigateTo({
url: '/pages/call/index',
})
})
},
})
},
globalData: {
neCall: null,
nim: null,
},
})
发起呼叫
// xxx.js
// 任意页面
const app = getApp()
Page({
startCall() {
const imAccid = 'xxx' // 被叫的im id
const callType = '1' // 呼叫类型 1: 单呼 2: 群呼, 字符串
app.globalData.neCall
.call({ callType, accId: imAccid })
.then(() => {
// 成功呼叫后跳转到呼叫页面,路由用户可以自定义,该页面下需要包含 `@xkit-yx/call-kit-wx-ui` 相关的 UI 组件
wx.navigateTo({
url: '/pages/call/index',
})
})
.catch((err) => {
console.log(err)
})
},
})
呼叫页面
// call.json
{
"usingComponents": {
"call-view": "@xkit-yx/call-kit-wx-ui/call-view"
}
}
// call.wxml
<view>
<call-view />
</view>
// call.js
const app = getApp()
Page({
onUnload() {
const neCall = app.globalData.neCall
neCall.hangup()
},
})