z***@outlook.com
z***@outlook.com
  • 发布:2024-07-02 21:54
  • 更新:2024-07-03 14:24
  • 阅读:33

channel使用没反应

分类:uniCloud

客户端的消息监听始终没反应

客户端

async testSSE() {
const channel = new uniCloud.SSEChannel() // 创建消息通道
channel.on('message', (message) => { // 监听message事件
console.log('on message', message);
})
channel.on('end', (message) => { // 监听end事件,如果云端执行end时传了message,会在客户端end事件内收到传递的消息
console.log('on end', message);
})
await channel.open() // 等待通道开启
const res = await llm.testPush({
channel: channel
})
console.log(res)
},

服务端

async testPush(data){  
    console.log(data.channel)  
    channel = uniCloud.deserializeSSEChannel(data.channel)  

    await channel.write({  
          a: 1  
        })  
    console.log("发送1")  
    await channel.write({  
      a: 2  
    })  
    console.log("发送2")  
    await channel.write({  
      a: 3  
    })  
    console.log("发送3")  
    await channel.write({  
      a: 4  
    })  

    // await channel.end({  
    //   a: 5  
    // })  
    return {hello:1}  
},
2024-07-02 21:54 负责人:无 分享
已邀请:
DCloud_uniCloud_CRL

DCloud_uniCloud_CRL

uni-push 开通了吗?

  • z***@outlook.com (作者)

    开了,目前是正常了,第一web是不行的会显示没开,第二真机是可以不报错正常发送但是客户端收不到,第三打包之后就可以了,但是即使只是改云函数也要打包一次否则还是收不到

    2024-07-03 15:54

要回复问题请先登录注册