-
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
1 parent
b9b1d50
commit ee6dadd
Showing
6 changed files
with
201 additions
and
6 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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
name: CI/CD | ||
run-name: '@${{ github.actor }} ( ${{ github.event_name }} ) : ${{ github.ref_name }}' | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
build: | ||
name: Deploy | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: [16.x] | ||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: set up node.js | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
|
||
- name: install | ||
run: npm install | ||
|
||
- name: build | ||
run: npm run build | ||
|
||
- name: deploy | ||
run: | | ||
git config --global user.name $user_name | ||
git config --global user.email $user_email | ||
git remote set-url origin https://${github_token}@github.com/${repository} | ||
yarn deploy | ||
env: | ||
user_name: 'github-actions[bot]' | ||
user_email: 'github-actions[bot]@users.noreply.github.com' | ||
github_token: ${{ secrets.ACTIONS_DEPLOY_ACCESS_TOKEN }} | ||
repository: ${{ github.repository }} |
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,44 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const socket_io_1 = require("socket.io"); | ||
const socketConfig = process.env.NODE_ENV === 'prod' | ||
? { | ||
path: '/socket.io', | ||
cors: { | ||
origin: ['https://jdshaeffer.github.io'], | ||
methods: ['GET', 'POST'], | ||
}, | ||
} | ||
: { | ||
cors: { | ||
origin: ['http://localhost:3000'], | ||
methods: ['GET', 'POST'], | ||
}, | ||
}; | ||
const io = new socket_io_1.Server(socketConfig); | ||
let playerCount = 0; | ||
// the Map object holds key-value pairs and remembers the original insertion order of the keys | ||
const socketToPlayerId = new Map(); | ||
io.on('connection', (socket) => { | ||
playerCount += 1; | ||
io.emit('playerCountUpdate', playerCount); | ||
if (playerCount < 3) { | ||
socketToPlayerId.set(playerCount, socket.id); | ||
// emit only back to sender to issue playerId | ||
socket.emit('assignPlayerId', playerCount); | ||
socket.on('updatePlayer1', (pos) => { | ||
socket.broadcast.emit('updatePlayer1', pos); | ||
}); | ||
socket.on('updatePlayer2', (pos) => { | ||
socket.broadcast.emit('updatePlayer2', pos); | ||
}); | ||
} | ||
socket.on('disconnect', () => { | ||
playerCount -= 1; | ||
socketToPlayerId.set(playerCount, socket.id); | ||
// need to emit to the remaining player that they're now player1 | ||
socket.broadcast.emit('assignPlayerId', playerCount); | ||
io.emit('playerCountUpdate', playerCount); | ||
}); | ||
}); | ||
io.listen(5000); |
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