generated from hatchways/express-starter
-
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.
Merge pull request #21 from hatchways/setup-socketio_tony_16
Setup Socket.io
- Loading branch information
Showing
8 changed files
with
834 additions
and
204 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import socketIO from "socket.io-client"; | ||
|
||
const NAMESPACE = "/game"; | ||
|
||
const ACTION_TYPE = { | ||
START: "START", | ||
SHUTDOWN: "SHUTDOWN", | ||
}; | ||
|
||
const initialState = { | ||
io: null, | ||
}; | ||
|
||
const reducer = (state, action) => { | ||
switch (action.type) { | ||
case ACTION_TYPE.START: | ||
if (!state.io) { | ||
state.io = socketIO(NAMESPACE); | ||
} | ||
return state; | ||
case ACTION_TYPE.SHUTDOWN: | ||
if (state.io) { | ||
state.io.disconnect(); | ||
state.io = null; | ||
} | ||
return state; | ||
default: | ||
return state; | ||
} | ||
}; | ||
|
||
export default { ACTION_TYPE, initialState, reducer }; |
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.