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

Add support for websockets #678

Closed
1 task done
tobiasdiez opened this issue Nov 20, 2022 · 13 comments
Closed
1 task done

Add support for websockets #678

tobiasdiez opened this issue Nov 20, 2022 · 13 comments
Labels
enhancement New feature or request

Comments

@tobiasdiez
Copy link
Contributor

Describe the feature

There are a few instances were support for websocket was wished for, or workarounds were discussed (see references below), but no I couldn't find a proper issue.

I would volunteer to help implementing websocket support, and formulate a proper RFC. But for this I first need a general direction and scope for this feature. @pi0 @danielroe
Questions to be clarified are: Do you want to implement this at h3, or only at the level of nitro? Should the presets handle ws support? How to include vendor-specific implementations like fastify-websocket?

References:

Additional information

  • Would you be willing to help implement this feature?
@marshallswain
Copy link
Contributor

WebSocket support would be really nice, and more especially useful if it were implemented similar to what we've done with FeathersJS. We've created "transport" plugins that adapt requests from each transport into the same routes/functions on the backend. You also still have access to create custom entries that only work with a specific transport.

Here are examples of the three primary transports that we bundle with FeathersJS Dove:

There's also a community-built adapter for Fastify, somewhere out there. It seems like a pretty unjs-like approach to implementing multi-transport support. We had to standardize on a socket API that's based around the Feathers Service interface. You can see the client message format for each method (find, get, create, update, patch, remove, and custom methods), here: https://dove.feathersjs.com/api/client/socketio.html#find.

Maybe it's worthwhile to create a @feathersjs/nitro adapter for Feathers.

Anyway, those are my thoughts. Use them as you wish, or not. 😁

@genu
Copy link
Contributor

genu commented Feb 20, 2023

Is this more feasable now with the release of Nuxt 3 stable?

@bf
Copy link

bf commented Feb 22, 2023

I'd also be interested in this. I want to use socket.io with nuxt3 and I'm struggling to make socket-io server work as nitroApp plugin.

@Hebilicious Hebilicious added enhancement New feature or request and removed feature request labels Jul 17, 2023
@NoeReverse
Copy link

So, is it possible to somehow use Socket.io with Nitro?

@gitFoxCode
Copy link

@NoeReverse I use it like this:
server/plugins/socket.io.server.ts

import { Server } from 'socket.io'
export default defineNitroPlugin((nitroApp) => {
    const socketServer = new Server(3001, {
        serveClient: false,
        cors: {
            origin: '*'
        }
    })
    socketServer.on('connection', (socket) => {
        socket.on("message", async (message)=>{
            socketServer.emit("message", {
                    type: "user",
                    author: message.author,
                    content: message.content
            })
         })
     })
})

@SebbeJohansson
Copy link

We are using ngrok and have not been able to get a solution for this.

@francisashley
Copy link

+1

@septatrix
Copy link
Contributor

The groundwork is currently being done in h3: unjs/h3#544

@grokpot
Copy link

grokpot commented Dec 12, 2023

I played around with a few configurations of sockets in Nitro last week.
Here's a nice state of the art, current as of now:
https://stackoverflow.com/questions/75970500/how-to-use-socket-io-with-nuxt-3

But there's a bigger discussion to be had - Nitro is mean to "run anywhere".
For those of us using serverless, or Serverless-as-a-Service (e.g. Vercel), I don't think sockets would work even if Nitro contained them, because the functions spin up and spin down.

So, what would sockets look like on Nitro deployed to serverless?

P.S. - my solution?
I ended up using Supabase's realtime service since I was using Supabase anyways.

@septatrix
Copy link
Contributor

So, what would sockets look like on Nitro deployed to serverless?

I guess at first they would simply not be supported on most providers. However, some edge runtimes such as cloudflare workers do support websockets so this could become supported for them in the future.

@pi0
Copy link
Member

pi0 commented Dec 12, 2023

spoiler

@GaborTorma
Copy link

Maybe it's worthwhile to create a @feathersjs/nitro adapter for Feathers.

@marshallswain Do you have a plan to make @feathersjs/nitro adapter?

It would be great. ;)

@pi0
Copy link
Member

pi0 commented May 16, 2024

https://nitro.unjs.io/guide/websocket

@pi0 pi0 closed this as completed May 16, 2024
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