You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using Fastify WebSocket plugin (@fastify/websocket) and I want to log a new WebSocket connection, how to do that?
With ws library I can do something like this
import{applyWSSHandler}from'@trpc/server/adapters/ws';importwsfrom'ws';import{appRouter}from'./routers/app';import{createContext}from'./trpc';constwss=newws.Server({port: 3001});consthandler=applyWSSHandler({ wss,router: appRouter, createContext });wss.on('connection',(ws)=>{// HERE I CAN LOG A NEW CONNECTIONconsole.log(`➕➕ Connection (${wss.clients.size})`);ws.once('close',()=>{console.log(`➖➖ Connection (${wss.clients.size})`);});});
...
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm using Fastify WebSocket plugin (
@fastify/websocket
) and I want to log a new WebSocket connection, how to do that?With
ws
library I can do something like thisCurrently, my code looks like this:
I'm not sure how to log a new socket connection when using the fastify websocket plugin, I tried to do something like this:
But I'm getting
undefined
error on accessingfastifyServer.websocketServer
, any help is appreciated 🙏Beta Was this translation helpful? Give feedback.
All reactions