syntaxlexx / nextjs-socketio-colyseus-gameserver-testing

A repo showcasing how one would go about creating a game or managing websockets via a Nextjs app and a backend on socket.io, colyseus, e.t.c.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Next13 + WebSockets + TypeScript

A sample implementation of how to handle Websockets with Nextjs 13 app dir, socket.io and colyseus.

This is a playground to quickly figure out Nextjs stuff

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

Pointers

  • Make use of React's ContextApi
  • To avoid duplicate events on socket.io, always socket.off() on the useEffect() cleanup section (return). That prevents memory leaks.
  • To avoid duplicate events/memory leakage on colyseus, refactor the onJoin so it can be run on the cleanup part in useEffect

Setup

  • Run pnpm i on all 3 projects (i.e.colyseus,nextjs,socketio)
  • Open 3 terminals, run npm run dev on all of them.

License

  • MIT
  • DBAD -> Don't Be A D*ck!

About

A repo showcasing how one would go about creating a game or managing websockets via a Nextjs app and a backend on socket.io, colyseus, e.t.c.

License:MIT License


Languages

Language:TypeScript 91.8%Language:JavaScript 5.3%Language:CSS 2.9%