|
[App引擎]
一次点击触发两次sendevent事件导致异常的情况
[复制链接]
本帖最后由 David六六 于 2022-9-17 19:45 编辑
BUG说明:在页面A,点击接听按钮后打开页面B,在B页面成功打开后向服务端发送sendevent事件时,连续发送了两次。不是必现的
Bug出现后,第一时间考虑在A页面给按钮加锁,代码如下
- async onAccept() {
- if (this.callCancel) {
- return
- }
- if(this.answerLock){
- console.log(this.answerLock+"接听锁开启中")
- return
- }
- //防止锁未关闭
- this.answerLock = true
- this.lockTimer = setTimeout(() => {
- if (this.answerLock) {
- this.answerLock = false
- }
- }, 2000)
- const videoCallInfo = await Api.get(`video_calls/${this.videoCallId}`)
- if (videoCallInfo.status === 'canceled') {
- toast('对方已取消通话')
- this.pageExit()
- return
- }
- clearInterval(this.callTimer)
- window.api.stopPlay()
- window.api.openWin({
- name: 'video-call',
- url: './call-index.html',
- slidBackEnabled: false,
- pageParam: {
- target: {
- id: this.fromUser.id,
- name: this.fromUser.name,
- avatar_url: this.fromUser.avatar_url,
- is_anchor: this.fromUser.is_anchor,
- type: 'receive',
- },
- video_call_id: this.videoCallId,
- },
- })
复制代码 实际测试,连续点击,加锁也是成功了
- [2022-9-17 19:32:16][INFO] true接听锁开启中
- [2022-9-17 19:32:16][INFO] true接听锁开启中
- [2022-9-17 19:32:16][INFO] true接听锁开启中
复制代码
但是后续在用户使用过程中还是有出现同时收到两条消息
- [2022-08-08 21:01:42][123253637]Action: accept-video-call
- [2022-08-08 21:01:42][123253637]Action: accept-video-call
- [2022-08-08 21:01:43][123253637]Push message video_call_accepted success.
- [2022-08-08 21:01:44][123253637]Push message video_call_stopped success.
复制代码
B页面打开后只是简单的执行了
- window.api.sendEvent({
- name: 'sendActionEvent',
- extra: {
- action: 'accept-video-call',
- video_call_id: this.videoCallId,
- },
- })
复制代码
这个是对sendActionEvent的监听
- initSendActionEventListener() {
- window.api.addEventListener(
- {
- name: 'sendActionEvent',
- },
- (ret) => {
- const data = ret.value
- this.send(data)
- }
- )
- }
复制代码
这个是this.send方法
- // 发送数据
- send(data) {
- let message = typeof data === 'object' ? JSON.stringify(data) : data
- let res =**.**monWebSocket.send({
- msg: message,
- })
- if (res) {
- log('commonWebSocket 发送成功:' + message)
- // 重置重试次数
- if (this.sendRetryCount < 3) {
- this.sendRetryCount = 3
- }
- } else {
- log('commonWebSocket 发送失败:' + message)
- // 发送失败重试
- if (this.sendRetryCount > 0) {
- this.sendRetryCount--
- setTimeout(() => {
- this.send(data)
- }, 1000)
- }
- }
- }
复制代码
后续应该怎么优化,或者问题出现在哪里,求大佬们解答一下
|
|