-
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.
feat(app-load-balancing): update game handling for new connections logic
- Loading branch information
1 parent
efc295e
commit 56292ec
Showing
19 changed files
with
121 additions
and
142 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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
import { Game as InnerGame } from '@pipeline/common'; | ||
import { Game as InnerGame, GameEntity as InnerGameEntity } from '@pipeline/common'; | ||
import { FirebaseFieldValue, FirebaseTimestamp } from './FirebaseTypes'; | ||
|
||
export type Game = InnerGame<FirebaseTimestamp, FirebaseFieldValue>; | ||
|
||
export type GameEntity = InnerGameEntity<FirebaseTimestamp, FirebaseFieldValue>; |
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,4 +1,6 @@ | ||
import { Status as InnerStatus } from '@pipeline/common'; | ||
import { FirebaseFieldValue, FirebaseTimestamp } from './FirebaseTypes'; | ||
import { FirebaseTimestamp } from './FirebaseTypes'; | ||
|
||
export type Status = InnerStatus<FirebaseTimestamp, FirebaseFieldValue>; | ||
export type Status = { | ||
state: 'online' | 'offline'; | ||
updatedAt: FirebaseTimestamp; | ||
}; |
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,6 +1,6 @@ | ||
import { SelectOption } from './SelectOption'; | ||
import { FirebaseFieldValue, FirebaseTimestamp } from './FirebaseTypes'; | ||
import { Game } from './Game'; | ||
import { Game, GameEntity } from './Game'; | ||
import { Status } from './Status'; | ||
|
||
export type { SelectOption, FirebaseTimestamp, FirebaseFieldValue, Game, Status }; | ||
export type { SelectOption, FirebaseTimestamp, FirebaseFieldValue, Game, Status, GameEntity }; |
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,5 +1,8 @@ | ||
import { FirebaseTimestamp } from '@pipeline/models'; | ||
|
||
export interface GameCreationData { | ||
scenarioTitle: string; | ||
scenarioContent: string; | ||
createdAt?: FirebaseTimestamp; | ||
scenarioCardId?: string; | ||
} |
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,7 +1,7 @@ | ||
import { all } from 'redux-saga/effects'; | ||
import loadCards from './loadCards'; | ||
import loadGame from './loadGame'; | ||
import { loadGameSaga } from './loadGame'; | ||
|
||
export default function* gameSaga() { | ||
yield all([loadCards(), loadGame()]); | ||
yield all([loadCards(), loadGameSaga()]); | ||
} |
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
44 changes: 44 additions & 0 deletions
44
packages/game-app/src/userGameStatus/apis/callUpdateConnections.ts
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 @@ | ||
import firebase from 'firebase'; | ||
import { RTDBPaths } from '@pipeline/common'; | ||
import CONFIG from '@pipeline/app-config'; | ||
|
||
export function initializeRTDB(rtdbInstance: string, gameId: string) { | ||
const app = firebase.initializeApp( | ||
{ | ||
databaseURL: `https://${rtdbInstance}.firebasedatabase.app`, | ||
}, | ||
gameId, | ||
); | ||
CONFIG.REACT_APP_FIREBASE_USE_EMULATORS === 'true' && app.database().useEmulator('localhost', 9000); | ||
} | ||
|
||
export async function startListenToOnlineStatus( | ||
uid: string, | ||
gameId: string, | ||
onConnect: () => void, | ||
onDisconnect: () => void, | ||
) { | ||
const rtdb: firebase.database.Database = firebase.app(gameId).database(); | ||
const connectionsRef = rtdb.ref(`/${RTDBPaths.Connections}/${gameId}/${uid}`); | ||
const lastOnlineRef = rtdb.ref(`/${RTDBPaths.Statuses}/${uid}/lastOnline`); | ||
|
||
rtdb.ref('.info/connected').on('value', async snapshot => { | ||
if (snapshot.val() === true) { | ||
const con = connectionsRef.push(); | ||
await con.onDisconnect().remove(() => { | ||
onDisconnect(); | ||
}); | ||
await con.set({ updatedAt: firebase.database.ServerValue.TIMESTAMP }, () => { | ||
onConnect(); | ||
}); | ||
|
||
await lastOnlineRef.onDisconnect().set(firebase.database.ServerValue.TIMESTAMP); | ||
} | ||
}); | ||
} | ||
|
||
export async function stopListenToOnlineStatus(gameId: string) { | ||
const rtdb: firebase.database.Database = firebase.app(gameId).database(); | ||
rtdb.ref('.info/connected').off(); | ||
await firebase.app(gameId).delete(); | ||
} |
66 changes: 0 additions & 66 deletions
66
packages/game-app/src/userGameStatus/apis/callUpdateOnlineStatus.ts
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
packages/game-app/src/userGameStatus/apis/selectBestRTDBInstance.ts
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.