Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deno support #3600

Closed
1 task done
ariesclark opened this issue May 21, 2020 · 11 comments
Closed
1 task done

Deno support #3600

ariesclark opened this issue May 21, 2020 · 11 comments
Labels
enhancement New feature or request

Comments

@ariesclark
Copy link

ariesclark commented May 21, 2020

  • request a feature

will there be official support for https://deno.land?

@lupodevelop
Copy link

Any news about this feature?

@darrachequesne
Copy link
Member

Does anybody know what is needed for supporting deno?

@darrachequesne darrachequesne added the enhancement New feature or request label Oct 6, 2020
@crowlKats
Copy link

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

@al6x
Copy link

al6x commented Apr 12, 2021

Any update, does socket.io works with deno?

@Chris2011
Copy link

Chris2011 commented Dec 7, 2021

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

@KnorpelSenf
Copy link

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:

  1. Port the code to Deno (sounds like more effort than it is, basically just adjust import statements)
  2. Along the way, extract Node-specific code into a Node-specific file
  3. Provide the Deno equivalent for this file
  4. Swap out tsc with deno2node
  5. Probably some config is broken, but otherwise you are done now.

Would be awesome to have Deno support!

@crowlKats
Copy link

crowlKats commented Jan 25, 2022

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.

@crowlKats
Copy link

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).

@KnorpelSenf
Copy link

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.

@darrachequesne
Copy link
Member

darrachequesne commented Sep 12, 2022

Hello everyone!

I'm happy to announce that we have published a Socket.IO server implementation for Deno 🚀

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!

darrachequesne added a commit to socketio/socket.io-website that referenced this issue Sep 13, 2022
@suchislife801
Copy link

Welcome to the future, Socket.io devs. I just can't wait to stop finding Node examples online forever.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

8 participants