1 | const PubSub = require('pubsub-js');
|
2 |
|
3 | module.exports = () => {
|
4 | let currentGameId = null;
|
5 |
|
6 | function lookingAtGame(gameId) {
|
7 | currentGameId = gameId;
|
8 | }
|
9 |
|
10 | function notLookingAtGame() {
|
11 | currentGameId = null;
|
12 | }
|
13 |
|
14 | PubSub.subscribe('viewing_game', (msg, data) => {
|
15 | lookingAtGame(data.gameId);
|
16 | });
|
17 |
|
18 | PubSub.subscribe('exited_game', () => {
|
19 | notLookingAtGame();
|
20 | });
|
21 |
|
22 | return {
|
23 | getCurrentGame: () => currentGameId,
|
24 | };
|
25 | };
|