I am building an app with Next.JS and tRPC. As I need real-time communication inside my app, I want to use Websockets, which are nicely integrated into rRPC as subscriptions. (See https://trpc.io/docs/subscriptions)
In the documentation of tRPC they are creating a ws Server, however it is not documented for Next.
My questions is: How can I integrate Websocktes in this use case into Next, as I cannot find a way to run the ws Server with Next. I tried to import the file wsServer.ts
in _app.tsx
or in api/trpc/[trpc].ts
without getting it to work. When doing so I always get errors of some node libraries like fs
are not found even when ensuring that the code is run on the server side.