Skip to content

Commit

Permalink
Merge pull request #9 from IgorBayerl/colyseus
Browse files Browse the repository at this point in the history
Colyseus
  • Loading branch information
IgorBayerl authored Sep 22, 2023
2 parents 34f452c + 187f9e7 commit b745ff2
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 20 deletions.
3 changes: 2 additions & 1 deletion client/src/components/GameContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ const GameContext = createContext<IGameContextValue>({
const useGameContext = () => useContext(GameContext)

// Initialize the Colyseus client
const client = new Client('ws://localhost:2567')
const URL = process.env.NEXT_PUBLIC_GAME_SOCKET_SERVER || 'ws://localhost:2567'
const client = new Client(URL)

const GameProvider: React.FC<IGameProviderProps> = ({ children }) => {
// const { socket } = useSocketContext()
Expand Down
16 changes: 0 additions & 16 deletions client/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,18 @@ import { ToastContainer } from 'react-toastify'
import { GameProvider } from '~/components/GameContext'

import Head from 'next/head'
import { useEffect } from 'react'
import { QueryClient, QueryClientProvider } from 'react-query'
import { NextSeo } from 'next-seo';

import 'react-toastify/dist/ReactToastify.css'
import '~/styles/globals.css'
import { AudioProvider } from '~/components/AudioContext'
import TrackingCode from '~/components/TrackingCode'
import { useRouter } from 'next/router'
import DevTools from '~/components/devTools'

// import * as gtag from '~/lib/gtag'

const url = process.env.NEXT_PUBLIC_GAME_SERVER || 'http://localhost:2567'

const queryClient = new QueryClient()

const MyApp: AppType = ({ Component, pageProps }) => {
const router = useRouter()
// useEffect(() => {
// const handleRouteChange = (url: string) => {
// gtag.pageview(url)
// }
// router.events.on('routeChangeComplete', handleRouteChange)
// return () => {
// router.events.off('routeChangeComplete', handleRouteChange)
// }
// }, [router.events])

return (
<>
Expand Down
2 changes: 2 additions & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"@prisma/client": "^5.2.0",
"better-sqlite3": "^8.5.1",
"colyseus": "^0.15.0",
"cors": "^2.8.5",
"drizzle-orm": "latest",
"express": "latest",
"pino": "^8.15.1",
Expand All @@ -47,6 +48,7 @@
"@colyseus/loadtest": "^0.15.0",
"@colyseus/testing": "^0.15.0",
"@types/better-sqlite3": "^7.6.4",
"@types/cors": "^2.8.14",
"@types/express": "^4.17.1",
"@types/mocha": "^10.0.1",
"@types/node": "^20.5.9",
Expand Down
6 changes: 3 additions & 3 deletions server/src/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import config from "@colyseus/tools";
import {monitor} from "@colyseus/monitor";
import {playground} from "@colyseus/playground";
import logger from "./lib/loggerConfig";
import cors from "cors";

/**
* Import your Room files
Expand All @@ -19,12 +20,11 @@ export default config({
* Define your room handlers:
*/
gameServer.define("my_room", MyRoom);

//@ts-ignore
global.gameServer = gameServer;
},

initializeExpress: app => {
app.use(cors());

app.get("/hello_world", (req, res) => {
res.send("Hello Cyber Chaos Cards!");
});
Expand Down
7 changes: 7 additions & 0 deletions server/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,13 @@
dependencies:
"@types/node" "*"

"@types/cors@^2.8.14":
version "2.8.14"
resolved "https://registry.yarnpkg.com/@types/cors/-/cors-2.8.14.tgz#94eeb1c95eda6a8ab54870a3bf88854512f43a92"
integrity sha512-RXHUvNWYICtbP6s18PnOCaqToK8y14DnLd75c6HfyKf228dxy7pHNOQkxPtvXKp/hINFMDjbYzsj63nnpPMSRQ==
dependencies:
"@types/node" "*"

"@types/express-serve-static-core@^4.17.33":
version "4.17.36"
resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-4.17.36.tgz#baa9022119bdc05a4adfe740ffc97b5f9360e545"
Expand Down

1 comment on commit b745ff2

@vercel
Copy link

@vercel vercel bot commented on b745ff2 Sep 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.