Show HN: Socket-call – Call socket.io events like normal JavaScript functions

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

https://github.com/bperel/socket-call

Vytvořeno 8h | 16. 6. 2025 15:10:13


Chcete-li přidat komentář, přihlaste se

Ostatní příspěvky v této skupině

Show HN: Nexus.js - Fabric.js for 3D

I was looking for a tiny library to easily transform both 2D & 3D objects with simple mouse / touch controls and a fixed camera, in the browser.

Like a simple 3D editor but without requiring the

16. 6. 2025 22:10:10 | Hacker news
Show HN: Chawan TUI web browser

A terminal-based web browser in Nim.[1] Has acceptable (YMMV) CSS rendering, some JS support, and inline images (sixel/kitty). It can also use various protocols other than http(s) such as (s)ftp

16. 6. 2025 22:10:09 | Hacker news