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

2 bperel 4 6/15/2025, 12:52:01 PM github.com ↗
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) => ({ login: async (username: string) => { services._socket.data.user = { username }; console.log(`User ${username} logged in`); setInterval(() => { 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<UserEmitEvents, UserListenEvents>( '/user' );

user.login(username.value).then((message) => { console.log('Server acked with', message); });

user.showServerMessage = (message) => { console.log('Server sent us the message', message); }

I use this library for my own projects and would be interested to receive feedback about it :-)

Comments (4)

jqpabc123 · 18h ago
404 - Page not found

The link should be:

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

bperel · 11h ago
Indeed the link is wrong, thanks for the correction :-) Unfortunately I can't update my post
klabb3 · 18h ago
This link 404s for me. Is the repo public?
bperel · 11h ago
Yes, the link is wrong. The correct URL is https://github.com/bperel/socket-call