You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
socket.io has an example(ish) about integrating with crossws (which only works within node.js + depending on _internal)
Made this issue also to think how better we can deal with this kind of integration...
We could have an integrations page in docs to list other integrations like y-crossws (there could be also socketio-crossws community package to at least have better internal conditional checks)
URLs
No response
Additional information
Would you be willing to help?
The text was updated successfully, but these errors were encountered:
I will share my attempt. Again, sorry if this is off-topic. With the code below, I could trigger the connect (Socket.IO connected) but not the message (Socket.IO message) event. If I add message crossws hook, I can see that the server receives the event but not Socket.IO.
At the moment I just want to better understand how engine.io works and how it can be integrated with crossws.
import { createServer } from "node:http";
import crossws from "crossws/adapters/node";
import { Server as Engine } from "engine.io";
import { Server } from "socket.io";
import * as url from "node:url";
const engine = new Engine();
const io = new Server();
io.bind(engine);
io.on("connection", (socket) => {
console.log(`Socket.IO connected: ${socket.id}`);
socket.on("message", (data) => {
console.log(`Socket.IO message: ${data}`);
})
socket.on("error", (err) => {
console.log(`Socket.IO error: ${err}`);
})
socket.on("disconnect", () => {
console.log(`Socket.IO disconnected`);
})
});
const ws = crossws({
hooks: {
open(peer) {
// @ts-expect-error private method and property
engine.prepare(peer._internal.nodeReq);
// @ts-expect-error private method and property
engine.onWebSocket(peer._internal.nodeReq, peer._internal.nodeReq.socket, peer.websocket);
}
},
});
const server = createServer().listen(3000);
server.on("request", (req, res) => {
const u = url.parse(req.url, true);
if (u.pathname === "/socket.io/") {
engine.handleRequest(req, res);
return
}
if (u.pathname === "/") {
res.end(
`<script src="https://cdn.socket.io/4.8.1/socket.io.min.js" integrity="sha384-mkQ3/7FUtcGyoppY6bz/PORYoGqOl7/aSUMn2ymDOJcapfS6PHqxhRTMh1RR0Q6+" crossorigin="anonymous"></script>
<script>
const socket = io('http://127.0.0.1:3000');
socket.on('connect', () => {
socket.emit('hello from client');
});
</script>`,
);
return;
}
res.statusCode = 404;
res.end(``)
})
server.on("upgrade", (req, socket, head) => {
if (req.headers.upgrade === "websocket") {
ws.handleUpgrade(req, socket, head);
}
});
Describe the change
Discussion from sveltejs/kit#1491 (comment)
socket.io has an example(ish) about integrating with crossws (which only works within node.js + depending on
_internal
)Made this issue also to think how better we can deal with this kind of integration...
We could have an integrations page in docs to list other integrations like y-crossws (there could be also
socketio-crossws
community package to at least have better internal conditional checks)URLs
No response
Additional information
The text was updated successfully, but these errors were encountered: