-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add types to Socket.io Server and Socket
- Loading branch information
1 parent
1f05dd8
commit 63cffa3
Showing
12 changed files
with
157 additions
and
61 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
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,8 @@ | ||
import { Server, Socket } from 'socket.io'; | ||
import { registerRoomHandlers } from './roomHandlers'; | ||
import { registerGameHandlers } from './gameHandlers'; | ||
import { TypedServer, TypedSocket } from '../types/socketServerTypes'; | ||
|
||
export function registerHandlers(io: Server, socket: Socket) { | ||
export function registerHandlers(io: TypedServer, socket: TypedSocket) { | ||
registerRoomHandlers(io, socket); | ||
registerGameHandlers(io, socket); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { Server, Socket } from 'socket.io'; | ||
import { ConfigurableOptions } from '../state/options'; | ||
import { PollName } from '../state/pollService'; | ||
import { Match, MidgameConnectData, Responses, SelectionType } from './stateTypes'; | ||
import { ApiResult } from './result'; | ||
import { Player } from '../state/rooms'; | ||
|
||
interface ServerToClientRoomEvents { | ||
joinRoom(args: { error: string } | { success: boolean; roomName: string }): void; | ||
|
||
updatePlayers(args: { modifies: Player[]; deletes: Player[] }): void; | ||
} | ||
|
||
interface ClientToServerRoomEvents { | ||
createRoom(name: string, roomName: string, langs?: string[]): void; | ||
|
||
joinRoom(name: string, roomName: string): void; | ||
} | ||
|
||
interface ServerToClientGameEvents { | ||
setOptions(options: ConfigurableOptions): void; | ||
|
||
beginPrompt(prompt: string): void; | ||
|
||
promptResponse(response: string): void; | ||
|
||
nextSelection(args: { selector: string; selectionType: SelectionType }): void; | ||
|
||
setVoteCount(args: { pollName: PollName; count: number; next: boolean }): void; | ||
|
||
selectionTypeChosen(selectionType: SelectionType): void; | ||
|
||
beginMatching(selectedResponse: string): void; | ||
|
||
matchesFound(matches: Match[]): void; | ||
|
||
endRound(args: { hasNextRound: boolean }): void; | ||
|
||
gameOver(results: { player: string; points: number }[]): void; | ||
|
||
midgameConnect(reconnect: MidgameConnectData): void; | ||
} | ||
|
||
interface ClientToServerGameEvents { | ||
setOptions(options: ConfigurableOptions, callback?: (p: { success: boolean }) => void): void; | ||
|
||
startGame(): void; | ||
|
||
pollVote(pollName: PollName): void; | ||
|
||
promptResponse(response: string): void; | ||
|
||
selectSelectionType(isStrike: boolean): void; | ||
|
||
selectResponse(response: string): void; | ||
|
||
selectMatch(match: string): void; | ||
|
||
selectionComplete(): void; | ||
|
||
getResponses(id: string, callback: (result: ApiResult<Responses>) => void): void; | ||
} | ||
|
||
type ServerToClientEvents = ServerToClientRoomEvents & ServerToClientGameEvents; | ||
type ClientToServerEvents = ClientToServerRoomEvents & ClientToServerGameEvents; | ||
|
||
export class TypedServer extends Server<ClientToServerEvents, ServerToClientEvents> {} | ||
|
||
export class TypedSocket extends Socket<ClientToServerEvents, ServerToClientEvents> {} |
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,43 @@ | ||
import { ConfigurableOptions } from '../state/options'; | ||
import { PollName } from '../state/pollService'; | ||
|
||
export enum Stage { | ||
Lobby, | ||
Response, | ||
Selection, | ||
Matching, | ||
EndRound | ||
} | ||
|
||
export enum SelectionType { | ||
Strike = 'strike', | ||
Sike = 'sike', | ||
Choice = 'choice' | ||
} | ||
|
||
export type Match = { | ||
player: string; | ||
response: string; | ||
exact: boolean; | ||
}; | ||
|
||
export type Responses = { | ||
id: string; | ||
all: string[]; | ||
used: string[]; | ||
selectedStrike: string; | ||
selectedSike: string; | ||
}; | ||
|
||
export type MidgameConnectData = { | ||
stage: Stage; | ||
selectionType: SelectionType; | ||
responses: Responses; | ||
selector: string; | ||
selectedResponse: string; | ||
prompt: string; | ||
options: ConfigurableOptions; | ||
timer: number; | ||
matches: Match[]; | ||
voteCounts: Record<PollName, { count: number; next: boolean }>; | ||
}; |
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.