https://github.com/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.
https://github.com/syntaxlexx/nextjs-socketio-colyseus-gameserver-testing
Last synced: over 1 year ago
JSON representation
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.
- Host: GitHub
- URL: https://github.com/syntaxlexx/nextjs-socketio-colyseus-gameserver-testing
- Owner: syntaxlexx
- License: mit
- Created: 2023-09-13T19:45:15.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-09-24T21:55:50.000Z (over 2 years ago)
- Last Synced: 2025-01-10T07:54:28.078Z (over 1 year ago)
- Language: TypeScript
- Size: 18.3 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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
- [x] A central Typescript typings between all projects
- [x] A central database to be used between all projects
- [x] Handling of websockets in Nextjs
- [x] Handling of auth between Nextjs and Colyseus
- [ ] Handling of auth between Nextjs and Socket.io
- [ ] Room mgmt between Nextjs and Socket.io
- [x] 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!