我正在尝试将 socket.io 与 Strapi 集成。但不幸的是,如果没有涵盖这方面的任何适当的教程或文档,我一直无法做到这一点。
我跟着我在网上找到的唯一资源是:https : //medium.com/strapi/strapi-socket-io-a9c856e915a6 但我认为这篇文章已经过时了。我似乎无法在不遇到大量错误的情况下运行其中提到的代码。
下面是我实现它的尝试,我一直在尝试通过 chrome websocket 插件智能 websocket 客户端连接它但是当我尝试运行服务器时我没有得到任何响应。
我完全在黑暗中。任何帮助将不胜感激
module.exports = ()=> {
// import socket io
var io = require('socket.io')(strapi.server)
console.log(strapi.server) //undefined
// listen for user connection
io.on('connect', socket => {
socket.send('Hello!');
console.log("idit")
// or with emit() and custom event names
socket.emit('greetings', 'Hey!', { 'ms': 'jane' }, Buffer.from([4, 3, 3, 1]));
// handle the event sent with socket.send()
socket.on('message', (data) => {
console.log(data);
});
// handle the event sent …Run Code Online (Sandbox Code Playgroud)