A sample implementation of how to handle Websockets with Nextjs 13 app dir
, socket.io
and colyseus
.
Testing out these ideas
- A central Typescript typings between all projects
- A central database to be used between all projects
- Handling of websockets in Nextjs
- Handling of auth between Nextjs and Colyseus
- Handling of auth between Nextjs and Socket.io
- Room mgmt between Nextjs and Socket.io
- Room mgmt between Nextjs and Colyseus
- Make use of React's
ContextApi
- To avoid duplicate events on
socket.io
, alwayssocket.off()
on theuseEffect()
cleanup section (return). That prevents memory leaks. - To avoid duplicate events/memory leakage on
colyseus
, refactor theonJoin
so it can be run on thecleanup
part inuseEffect
- Run
pnpm i
on all 3 projects (i.e.colyseus
,nextjs
,socketio
) - Open 3 terminals, run
npm run dev
on all of them.
- MIT
- DBAD -> Don't Be A D*ck!