generated from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
135 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,44 @@ | ||
import { FC } from 'react' | ||
import { FC, useEffect, useState } from 'react' | ||
import io from 'socket.io-client'; | ||
|
||
interface GameMultiPlayerProps { | ||
|
||
} | ||
|
||
interface SocketProps { | ||
emit: (event: string, ...args: any[]) => void; | ||
close: () => void; | ||
} | ||
|
||
const GameMultiPlayer: FC<GameMultiPlayerProps> = ({}) => { | ||
return <div>GameMultiPlayer</div> | ||
|
||
const SERVER_URL = 'http://localhost:8006'; | ||
const [socket, setSocket] = useState<SocketProps | null>(null); | ||
|
||
useEffect(() => { | ||
const newSocket = io(SERVER_URL); | ||
setSocket(newSocket); | ||
|
||
newSocket.on('partyCreated', (partyCode: string) => { | ||
console.log(`Party created: ${partyCode}`); | ||
// Handle the party creation, e.g., store the party code in the state | ||
}); | ||
|
||
return () => { | ||
newSocket.close(); | ||
}; | ||
}, []); | ||
|
||
const createParty = () => { | ||
socket.emit('createParty'); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<h1>Multiplayer Game</h1> | ||
<button onClick={createParty}>Create Party</button> | ||
</div> | ||
) | ||
} | ||
|
||
export default GameMultiPlayer |