在调试uniCloud.SSEChannel过程中(已开通unipush2)遇到报错:{"code":"FUNCTION_EXCUTE_ERROR","message":"not found collection"}
求大佬解答 。
客户端代码:
async function testSSE() {
const sseChannel = new uniCloud.SSEChannel(); // 创建消息通道
console.log(sseChannel);
await sseChannel.open(); // 等待通道开启
sseChannel.on("message", (message) => {
// 监听message事件
console.log("on message", message);
list.value.push(JSON.stringify(e.data));
});
sseChannel.on("end", (message) => {
// 监听end事件,如果云端执行end时传了message,会在客户端end事件内收到传递的消息
console.log("on end", message);
sseChannel.close();
});
const myTestObj = uniCloud.importObject("myTest");
await myTestObj
.testSSE({
messages: "123",
sseChannel, // 调用云对象时传入通道对象
})
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
});
}
云对象代码:
async testSSE({
messages,
sseChannel,
}) {
return new Promise(async (resolve, reject) => {
try {
console.log(messages, sseChannel);
const channel = uniCloud.deserializeSSEChannel(sseChannel);
console.log(channel);
await channel.write({
a: 1,
});
await channel.write({
a: 2,
});
await channel.write({
a: 3,
});
await channel.write({
a: 4,
});
console.log(res);
await channel.end({
a: 5,
});
resolve({
errCode: 0,
});
} catch (e) {
reject(e);
}
});
},
云对象配置信息:
{
"name": "myTest",
"dependencies": {},
"extensions": {
"uni-cloud-jql": {},
"uni-cloud-push": {}
}
}