Comments (9)
I am working with the nitro team on this. We already enabled websocket support for the dev server using @vinxi/listhen, a temporary fork of listhen that enables websocket support until unjs/listhen#128 lands.
We will then try to land APIs for h3
and nitro
that make it easy to write cross-platform websocket servers
from vinxi.
Now that the referenced PR is closed, is there any place to track the progress on WS support, h3/nitro API, etc.?
from vinxi.
So looks like unjs
has introduced crossws
package. This will be integrated in h3/nitro
soon. I don't think there is a tracking issue, but we should get this soon. @pi0 i don't know if we have a timeline yet right
from vinxi.
I guess the important part that is missing, is the hook to listen for the upgrade
event unjs/nitro#2041
Hopefully @pi0 will take a look at it soon.
from vinxi.
released in 0.3.6
from vinxi.
Thanks a lot! Is there a tracking issue for bringing this into start?
from vinxi.
Its immediately available in start. Set server.experimental.websocket: true
in config file.
You can then add a new router to your vinxi app, like this:
import { defineConfig } from "@solidjs/start/config";
const app = defineConfig({
server: {
experimental: {
websocket: true,
},
},
});
app.addRouter({
name: "websocket",
type: "http",
handler: "./src/websocket.ts",
target: "server",
base: "/_ws",
});
export default app;
src/websocket.ts
import { defineWebSocket, eventHandler } from "vinxi/http";
export default eventHandler({
handler: () => {},
websocket: defineWebSocket({
async open(event) {
console.log("WebSocket opened");
},
async message(peer, event) {
console.log("WebSocket message", event);
peer.send("YOOO");
},
async close(event) {
console.log("WebSocket closed 3");
},
}),
});
To connect to the websocket try,
const ws = new WebSocket('ws://localhost:3000/_ws')
from vinxi.
Is there a way to import WSRequest
, Peer
, Message
etc. types from vinxi?
defineWebSocket({
upgrade: (req: WSRequest) => MaybePromise<void | { headers?: HeadersInit }>;
message: (peer: Peer, message: Message) => MaybePromise<void>;
open: (peer: Peer) => MaybePromise<void>;
close: (peer: Peer, details: { code?: number; reason?: string }) => MaybePromise<void>;
error: (peer: Peer, error: WSError) => MaybePromise<void>;
})
from vinxi.
Thanks a lot! Is there a tracking issue for bringing this into start?
Maybe it should look something like this: solidjs/solid-start#1384
from vinxi.
Related Issues (20)
- Outer variables referenced inside "use server" get treeshaken away. HOT 4
- build continues after failure
- use with vite-env-only HOT 2
- How do I attach a debugger to a process running in `vinxi`? HOT 1
- Add mode flag HOT 1
- [Feature] ability to load multiple featureApps from separate host/sub-domain HOT 2
- exporting a `class` from `"use server"` results in a compile error. HOT 1
- Missing types for `https` object in `server` section. HOT 2
- Imports that should be server-only aren't removed in dev if `verbatimModuleSyntax: true`
- How to add instrumentation to vinxi powered app? HOT 1
- [Proposal] Bundle config file to some outdir
- [BUGS] Styles in prod are injected twice and have wrong order HOT 39
- Extra ./node_modules/ folder created just for .vinxi
- Unable to load static assets in AWS Lambda HOT 2
- Assets incorrectly loaded from unrelated page HOT 1
- Breaking bug in CSS handling in 0.13.3 HOT 3
- The function findAssetsInViteManifest can slow down SSR significantly HOT 11
- Consider adding a README.md to the main `vinxi` package HOT 2
- Some bug in Vite < 5.3.2 or lightnin/sass/... causes parsing exception during prod build
- WebSocket with fs router support
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vinxi.