小程序sendDanmu方法频繁调用问题
发布于 6 年前 作者 pcai 4452 次浏览 来自 问答

在websocket中频繁调用sendDanmu时,数据没有问题,但是会重复显示第一条数据

wx.connectSocket({
      url: `wss://${domainName}.com/ws/live/ranks?cid=${options.cid}`,
      success: function(res) {
        wx.showToast({
          title: '连接服务器成功',
        })
        wx.onSocketMessage(function(res) {
          var resData = JSON.parse(res.data);
          if (resData.event == 'LIVE_MESSAGE') {
            var dataSource = resData.data.message;
            console.log(dataSource)
            that.setData({
              testData: dataSource
            })
            that.videoContext.sendDanmu({
              text: dataSource.value,
              color: dataSource.color
            })
 
          }
        })
      },
      fail: function(res) {
        wx.showToast({
          title: '连接服务器失败',
        })
      }
    })
1 回复

麻烦提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)

回到顶部