Deno support
- [x] request a feature
will there be official support for https://deno.land?
Any news about this feature?
Does anybody know what is needed for supporting deno?
Deno for client uses the web WebSocket API, whereas for server you could look at how it is done in https://deno.land/[email protected]/ws/mod.ts
Any update, does socket.io works with deno?
You ca try to use: http://esm.sh/socketio but I had a talk in the discord chan of deno and it seems that the node modules needs to be converted. I also wanted to use ws with deno but they don't have support for a socks proxy. So trying the package that I mentioned, wait for official support or helping by make the underlying network stuff of node compatible :).
Also if you haven't tried it yet: https://stackoverflow.com/questions/61821038/how-to-use-npm-module-in-deno/61821141#61821141
There's a pretty good tool called deno2node. It lets you write Deno modules in TS and then it can compile them to JS, just like tsc compiles TS to JS. Using it in a few dozen projects without problems. If there are things that work differently on both platforms (such as maybe sockets) you can provide two different source files for this part of the library. That way, you can basically provide the same module for both runtimes, and a tiny bit under the hood can vary.
Plan of attack would be:
- Port the code to Deno (sounds like more effort than it is, basically just adjust import statements)
- Along the way, extract Node-specific code into a Node-specific file
- Provide the Deno equivalent for this file
- Swap out
tscwithdeno2node - Probably some config is broken, but otherwise you are done now.
Would be awesome to have Deno support!
As a simpler alternative to the above mentioned solution, there is the official (experimental!) deno tool dnt, which allows you to create Node.js packages from deno ones.
If socket.io mantainers want to do this and want help to port socket.io to deno, feel free to contact me, i'd gladly help out.
What i forgot to mention above with my comment: that isnt a perfect solution. Deno does provide a --compat flag which allows one to use node packages, or one can use https://esm.sh/. these are more robust solutions, and are more recommended over using dnt (in the end, they are completely different things, and have different goals, for the case of socket.io, i would actually rather recommend one of the former solutions, not dnt).
I have tried dnt a lot and it forces you to completely change the project structure to become a Deno project. dnt is the right tool if you have a Deno project, and you want to create a new npm package from it. The other way around does not work well. I tried to provide feedback to the Deno team about this, but they deem this kind of compatibility out of scope. We are supposed to write custom build scripts which copy around all files for dnt to work, so I concluded that it is the wrong tool for when you already have an existing npm package and you want to have the least disruption.
In contrast, deno2node is literally meant to replace tsc, so it just fits in. Naturally, this comes at the cost that you now are responsible for the usual yada-yada with the Node config, so again, for fresh projects dnt is probably best.
But either way, I do agree that the compat mode would probably work, too, and it may be the easiest of all suggested solutions. Although it will of course not be as nice as having native Deno support.
Hello everyone!
I'm happy to announce that we have published a Socket.IO server implementation for Deno :rocket:
Usage:
import { serve } from "https://deno.land/[email protected]/http/server.ts";
import { Server } from "https://deno.land/x/[email protected]/mod.ts";
const io = new Server();
io.on("connection", (socket) => {
console.log(`socket ${socket.id} connected`);
socket.emit("hello", "world");
socket.on("disconnect", (reason) => {
console.log(`socket ${socket.id} disconnected due to ${reason}`);
});
});
await serve(io.handler(), {
port: 3000,
});
Link: https://deno.land/x/[email protected] Source: https://github.com/socketio/socket.io-deno Announcement: https://socket.io/blog/socket-io-deno/
Feedback is welcome!
Welcome to the future, Socket.io devs. I just can't wait to stop finding Node examples online forever.