|
@@ -449,6 +449,7 @@ const miniprogramState = (() => {
|
|
|
serviceStatus: null,
|
|
serviceStatus: null,
|
|
|
inactivityTimer: null,
|
|
inactivityTimer: null,
|
|
|
inactivityTimeout: 180000,
|
|
inactivityTimeout: 180000,
|
|
|
|
|
+ isCalling: false,
|
|
|
modalVisible: false,
|
|
modalVisible: false,
|
|
|
modalTitle: '提示',
|
|
modalTitle: '提示',
|
|
|
modalContent: '',
|
|
modalContent: '',
|
|
@@ -586,7 +587,27 @@ const miniprogramState = (() => {
|
|
|
const snFromOption = String(options.sn || '').trim()
|
|
const snFromOption = String(options.sn || '').trim()
|
|
|
const cardNo = String(options.cardNo || '').trim()
|
|
const cardNo = String(options.cardNo || '').trim()
|
|
|
const sn = snFromOption || String(userInfo.devId || '').trim()
|
|
const sn = snFromOption || String(userInfo.devId || '').trim()
|
|
|
- if (!sn || !cardNo) return false
|
|
|
|
|
|
|
+ if (!sn) {
|
|
|
|
|
+ uni.showToast({ title: '缺少设备标识,请重新刷卡登录', icon: 'none' })
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
|
+ uni.reLaunch({ url: '/pages/device/notice' })
|
|
|
|
|
+ }, 1200)
|
|
|
|
|
+ return false
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!cardNo) {
|
|
|
|
|
+ const hasSession = !!(userInfo.yhsbToken || userInfo.onlineToken || userInfo.sessId)
|
|
|
|
|
+ if (!hasSession) {
|
|
|
|
|
+ uni.showToast({ title: '登录已失效,请重新刷卡登录', icon: 'none' })
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
|
+ uni.reLaunch({ url: '/pages/device/notice' })
|
|
|
|
|
+ }, 1200)
|
|
|
|
|
+ return false
|
|
|
|
|
+ }
|
|
|
|
|
+ this.refreshCurrentUserMeta()
|
|
|
|
|
+ this.resolveWsIdentity()
|
|
|
|
|
+ this.currentWsConfig = this.buildWsConnectOptions()
|
|
|
|
|
+ return true
|
|
|
|
|
+ }
|
|
|
try {
|
|
try {
|
|
|
const result = await deviceApi.login(sn, cardNo)
|
|
const result = await deviceApi.login(sn, cardNo)
|
|
|
const loginData = result?.data || {}
|
|
const loginData = result?.data || {}
|
|
@@ -602,6 +623,7 @@ const miniprogramState = (() => {
|
|
|
xm: loginData.xm || '',
|
|
xm: loginData.xm || '',
|
|
|
yhsbToken: loginData.yhsbToken || '',
|
|
yhsbToken: loginData.yhsbToken || '',
|
|
|
onlineToken: loginData.onlineToken || '',
|
|
onlineToken: loginData.onlineToken || '',
|
|
|
|
|
+ cardNo,
|
|
|
syList: loginData.sylist || loginData.syList || [],
|
|
syList: loginData.sylist || loginData.syList || [],
|
|
|
yhid: loginData.yhid || '',
|
|
yhid: loginData.yhid || '',
|
|
|
yhm: loginData.yhm || ''
|
|
yhm: loginData.yhm || ''
|
|
@@ -634,7 +656,7 @@ const miniprogramState = (() => {
|
|
|
},
|
|
},
|
|
|
async loadParentChatMembers() {
|
|
async loadParentChatMembers() {
|
|
|
try {
|
|
try {
|
|
|
- const result = await grfwApi.grfw_selChatMbr({})
|
|
|
|
|
|
|
+ const result = await grfwApi.btc_selChatMbr({})
|
|
|
const data = result?.data || {}
|
|
const data = result?.data || {}
|
|
|
const list = this.normalizeChatMemberList(data.chatMbrList)
|
|
const list = this.normalizeChatMemberList(data.chatMbrList)
|
|
|
this.parentChatMembers = list
|
|
this.parentChatMembers = list
|
|
@@ -660,7 +682,7 @@ const miniprogramState = (() => {
|
|
|
},
|
|
},
|
|
|
async loadDeviceChatMembers() {
|
|
async loadDeviceChatMembers() {
|
|
|
try {
|
|
try {
|
|
|
- const result = await deviceApi.grfw_selChatMbr()
|
|
|
|
|
|
|
+ const result = await deviceApi.mp_telHomep_load()
|
|
|
const data = result?.data || {}
|
|
const data = result?.data || {}
|
|
|
const list = this.normalizeChatMemberList(data.chatMbrList)
|
|
const list = this.normalizeChatMemberList(data.chatMbrList)
|
|
|
this.parentChatMembers = list
|
|
this.parentChatMembers = list
|
|
@@ -890,6 +912,11 @@ const miniprogramState = (() => {
|
|
|
uni.showToast({ title: '请让家长先关注公众号,登陆小程序后再发起', icon: 'none' })
|
|
uni.showToast({ title: '请让家长先关注公众号,登陆小程序后再发起', icon: 'none' })
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
+ this.isCalling = true
|
|
|
|
|
+ if (this.inactivityTimer) {
|
|
|
|
|
+ clearTimeout(this.inactivityTimer)
|
|
|
|
|
+ this.inactivityTimer = null
|
|
|
|
|
+ }
|
|
|
uni.showLoading({ title: '呼叫中...', mask: true })
|
|
uni.showLoading({ title: '呼叫中...', mask: true })
|
|
|
uni.setStorageSync(CALL_END_STORAGE_KEY, {
|
|
uni.setStorageSync(CALL_END_STORAGE_KEY, {
|
|
|
name: contact?.username || '家长',
|
|
name: contact?.username || '家长',
|
|
@@ -919,10 +946,14 @@ const miniprogramState = (() => {
|
|
|
uni.redirectTo({ url: wmpfVoip.CALL_PAGE_PATH })
|
|
uni.redirectTo({ url: wmpfVoip.CALL_PAGE_PATH })
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
+ this.isCalling = false
|
|
|
|
|
+ this.resetInactivityTimer()
|
|
|
uni.hideLoading()
|
|
uni.hideLoading()
|
|
|
uni.showToast({ title: '呼叫失败', icon: 'error' })
|
|
uni.showToast({ title: '呼叫失败', icon: 'error' })
|
|
|
return
|
|
return
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
|
|
+ this.isCalling = false
|
|
|
|
|
+ this.resetInactivityTimer()
|
|
|
uni.hideLoading()
|
|
uni.hideLoading()
|
|
|
console.error('设备端通话异常:', error)
|
|
console.error('设备端通话异常:', error)
|
|
|
uni.showToast({ title: '发起通话失败', icon: 'none' })
|
|
uni.showToast({ title: '发起通话失败', icon: 'none' })
|
|
@@ -1008,6 +1039,7 @@ const miniprogramState = (() => {
|
|
|
},
|
|
},
|
|
|
resetInactivityTimer() {
|
|
resetInactivityTimer() {
|
|
|
if (this.sessionRole !== 'device') return
|
|
if (this.sessionRole !== 'device') return
|
|
|
|
|
+ if (this.isCalling) return
|
|
|
if (this.inactivityTimer) {
|
|
if (this.inactivityTimer) {
|
|
|
clearTimeout(this.inactivityTimer)
|
|
clearTimeout(this.inactivityTimer)
|
|
|
}
|
|
}
|
|
@@ -1067,6 +1099,9 @@ const miniprogramState = (() => {
|
|
|
if (userInfo.devId) {
|
|
if (userInfo.devId) {
|
|
|
query.push(`sn=${encodeURIComponent(userInfo.devId)}`)
|
|
query.push(`sn=${encodeURIComponent(userInfo.devId)}`)
|
|
|
}
|
|
}
|
|
|
|
|
+ if (userInfo.cardNo) {
|
|
|
|
|
+ query.push(`cardNo=${encodeURIComponent(userInfo.cardNo)}`)
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
if (callInfo.name) {
|
|
if (callInfo.name) {
|
|
|
query.push(`name=${encodeURIComponent(callInfo.name)}`)
|
|
query.push(`name=${encodeURIComponent(callInfo.name)}`)
|
|
@@ -1087,6 +1122,14 @@ const miniprogramState = (() => {
|
|
|
if (this._voipEventRegistered || !wmpfVoip) return
|
|
if (this._voipEventRegistered || !wmpfVoip) return
|
|
|
wmpfVoip.onVoipEvent((event) => {
|
|
wmpfVoip.onVoipEvent((event) => {
|
|
|
const eventName = event.eventName
|
|
const eventName = event.eventName
|
|
|
|
|
+ console.log('[VoIP] event:', eventName, event.data || {})
|
|
|
|
|
+ if (eventName === 'startVoip') {
|
|
|
|
|
+ this.isCalling = true
|
|
|
|
|
+ if (this.inactivityTimer) {
|
|
|
|
|
+ clearTimeout(this.inactivityTimer)
|
|
|
|
|
+ this.inactivityTimer = null
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
const hangupEvent = ['hangUpVoip', 'endVoip']
|
|
const hangupEvent = ['hangUpVoip', 'endVoip']
|
|
|
const cancelEvent = ['cancelVoip']
|
|
const cancelEvent = ['cancelVoip']
|
|
|
const timeoutEvent = ['timeout']
|
|
const timeoutEvent = ['timeout']
|
|
@@ -1109,11 +1152,26 @@ const miniprogramState = (() => {
|
|
|
callInfo.status = '已拒绝'
|
|
callInfo.status = '已拒绝'
|
|
|
}
|
|
}
|
|
|
if ([...hangupEvent, ...cancelEvent, ...timeoutEvent, ...rejectEvent].includes(eventName)) {
|
|
if ([...hangupEvent, ...cancelEvent, ...timeoutEvent, ...rejectEvent].includes(eventName)) {
|
|
|
|
|
+ this.isCalling = false
|
|
|
callInfo.endType = eventName
|
|
callInfo.endType = eventName
|
|
|
callInfo.endTime = Date.now()
|
|
callInfo.endTime = Date.now()
|
|
|
uni.hideLoading()
|
|
uni.hideLoading()
|
|
|
uni.setStorageSync(CALL_END_STORAGE_KEY, callInfo)
|
|
uni.setStorageSync(CALL_END_STORAGE_KEY, callInfo)
|
|
|
this.setVoipEndPagePath(true)
|
|
this.setVoipEndPagePath(true)
|
|
|
|
|
+ if (this.sessionRole === 'device') {
|
|
|
|
|
+ let toastTitle = '通话已结束'
|
|
|
|
|
+ if (cancelEvent.includes(eventName)) {
|
|
|
|
|
+ toastTitle = '已取消呼叫'
|
|
|
|
|
+ } else if (timeoutEvent.includes(eventName)) {
|
|
|
|
|
+ toastTitle = '对方暂未接听'
|
|
|
|
|
+ } else if (rejectEvent.includes(eventName)) {
|
|
|
|
|
+ toastTitle = '对方已拒绝'
|
|
|
|
|
+ } else if (hangupEvent.includes(eventName)) {
|
|
|
|
|
+ const keepTime = Number(event?.data?.keepTime || 0)
|
|
|
|
|
+ toastTitle = keepTime > 0 ? '通话已结束' : '未接通已结束'
|
|
|
|
|
+ }
|
|
|
|
|
+ uni.showToast({ title: toastTitle, icon: 'none' })
|
|
|
|
|
+ }
|
|
|
if (this.sessionRole === 'device' && callInfo.needRecord && callInfo.duration > 0) {
|
|
if (this.sessionRole === 'device' && callInfo.needRecord && callInfo.duration > 0) {
|
|
|
this.recordCallAndRefresh({
|
|
this.recordCallAndRefresh({
|
|
|
duration: callInfo.duration,
|
|
duration: callInfo.duration,
|