nitrojs / nitrojs/nitro

feature: Access Crossws publish and peers via useNitroApp / useNuxtApp

Open
#3,537 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement nuxt v2
Dominant language
TypeScript
Stars
11.2k
Forks
899
Avg merge
2d 24m
Merged PRs (30d)
40

Description

Describe the feature

I reading through the Nitro source code and noticed the following snippet in nitro-dev.ts:

if (import.meta._websocket) {
  const { handleUpgrade } = wsAdapter(nitroApp.h3App.websocket);
  server.on("upgrade", handleUpgrade);
}

Similar code exists in other runtimes as well. Of course, other V2 and V3 versions have such code.

Previously, I [mentioned](https://github.com/unjs/community/discussions/65#discussioncomment-12440854) that I’d like Nuxt to support Crossws adapters.
My main goal is to access peers and be able to publish to any channel.

I also noticed that Crossws retrieves hooks dynamically, but the peers are still stored in the same Set.

Would it make sense to inject the publish and peers from wsAdapter into the event context, or alternatively make them accessible via useNitroApp?
And in the case of Nuxt, ideally via useNuxtApp.

I’d be happy to help with implementing this, but I’m not sure where to start.
Thanks!

I use translation software for communication.

Additional information
  • Would you be willing to help implement this feature?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/presets/_nitro/runtime/nitro-dev.ts and compare the other runtimes that call wsAdapter with nitroApp.h3App.websocket. Investigate whether publish and peers should be exposed through the event context, useNitroApp, or useNuxtApp. Done means the chosen interface provides access to peers and publishing to any channel.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.