Hello HN,
I built a Typescript library (named socket-call, for lack of a more sexy name) whose goal is to be able to call socket.io events as regular functions.
So you declare your server-side like so:
...
const listenEvents = (services: UserServices) => ({
// Add your events here, the name of the event is the name of the function
login: async (username: string) => {
services._socket.data.user = { username };
console.log(`User ${username} logged in`);
setInterval(() => {
// Calling an event that's handled client-side
services.showServerMessage(`You're still logged in ${username}!`)
}, 1000);
return `You are now logged in ${username}!`;
},
});
and then on the client side you call them like normal async Javascript functions (and you can also create client-side event handlers): ...
const user = socket.addNamespace
I use this library for my own projects and would be interested to receive feedback about it :-)
Comments URL: https://news.ycombinator.com/item?id=44288643
Points: 18
# Comments: 3
Ak chcete pridať komentár, prihláste sa
Ostatné príspevky v tejto skupine


Article URL: https://spectrum.ieee.org/ai-intersection-monitoring

Article URL: https://github.com/trknhr/ai-docs
Comments URL: https://news.ycombinator
Hello HN!
As a long term NYC resident, I have read countless articles on ideas tweaking subway services, but always found them hard to follow without visual aid. So over the long weekend I decid
Hey HN, I’m Tejas at Morph. We’ve built a blazing-fast model for applying AI-generated code edits directly into your files at 4,500+ tokens/sec. No more slow full-file rewrites or brittle search-a
Article URL: https://arachnoid.com/3D_Printing_Prusa_Core_One/