-
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.
Merge pull request #1 from jannes-io/feature/socket-reconnection
Feature/socket reconnection
- Loading branch information
Showing
21 changed files
with
336 additions
and
426 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ root = true | |
indent_style = space | ||
indent_size = 2 | ||
insert_final_newline = true | ||
end_of_line = lf |
Large diffs are not rendered by default.
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
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
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,8 +1,39 @@ | ||
// FIXME this is really disgusting state management | ||
import { IAppState } from './types'; | ||
import * as R from 'ramda'; | ||
import { Socket } from 'socket.io'; | ||
import { IAppState, IServerRoom, IServerUser } from './types'; | ||
|
||
const appState: IAppState = { | ||
rooms: [], | ||
}; | ||
|
||
export const findRoom = (roomId: string): IServerRoom | undefined => appState.rooms | ||
.find(R.propEq('id', roomId)); | ||
|
||
export const findUser = (room: IServerRoom, socket: Socket): IServerUser | undefined => room.users | ||
.find((user) => user.socket.id === socket.id); | ||
|
||
export interface IGameInfo { | ||
user: IServerUser; | ||
room: IServerRoom; | ||
} | ||
|
||
export const findGameInfo = (roomId: string, socket: Socket): IGameInfo | undefined => { | ||
const room = findRoom(roomId); | ||
if (room === undefined) { | ||
return undefined; | ||
} | ||
const user = findUser(room, socket); | ||
if (user === undefined) { | ||
return undefined; | ||
} | ||
|
||
return { room, user }; | ||
}; | ||
|
||
export const findGameInfoBySocket = (socket: Socket): IGameInfo | undefined => { | ||
const userRoom = appState.rooms.find((room) => findUser(room, socket) !== undefined); | ||
return userRoom !== undefined ? findGameInfo(userRoom.id, socket) : undefined; | ||
}; | ||
|
||
export default appState; |
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
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React from 'react'; | ||
import { Dialog, DialogContent, DialogContentText, DialogTitle, LinearProgress } from '@material-ui/core'; | ||
import useSocket from '../Hooks/Socket'; | ||
|
||
const DisconnectAlert: React.FC = () => { | ||
const { connected } = useSocket(); | ||
|
||
if (connected) { | ||
return null; | ||
} | ||
|
||
return <Dialog open> | ||
<DialogTitle>Connection lost!</DialogTitle> | ||
<DialogContent> | ||
<DialogContentText> | ||
Oh no! We are trying to reconnect you with the game server. | ||
</DialogContentText> | ||
<LinearProgress /> | ||
</DialogContent> | ||
</Dialog>; | ||
}; | ||
|
||
export default DisconnectAlert; |
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
Oops, something went wrong.