yinxin630 / fiora

An interesting open source chat application. Developed with node.js, mongoDB, socket.io and react
https://fiora.suisuijiang.com
MIT License
6.57k stars 1.31k forks source link

请教:ctx.socket.emit的第一个参数只能是字符串,为啥代码能用数组? #470

Closed mofan20 closed 2 years ago

mofan20 commented 2 years ago

const targetSockets = await Socket.find({ user: toUser?._id }); const targetSocketIdList = targetSockets?.map((socket) => socket.id) || []; if (targetSocketIdList.length) { ctx.socket.emit(targetSocketIdList, 'message', messageData); }

请教这里为啥能用数组? ctx.socket.emit(targetSocketIdList, 'message', messageData);

mofan20 commented 2 years ago

看懂了。。。tx

yinxin630 commented 2 years ago

是支持的, 可以看下官方文档