Skip to content

Commit 987e874

Browse files
committed
feat: can join game midway
1 parent 151afb6 commit 987e874

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/__tests__/js/networking.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,5 +289,23 @@ describe('networking as a hivemind', () => {
289289
lastUpdate.msg.users.every((u) => u.progress === null && !u.solved)
290290
).toBe(true);
291291
});
292+
293+
it('sends the game problem if it exists', () => {
294+
stores.gameProblem.set(testProblem);
295+
296+
// clear messages
297+
messagesTo.splice(0, messagesTo.length);
298+
299+
// have person connect
300+
networking.onData(testId1)({
301+
type: Messages.INIT_STATE,
302+
name: testName,
303+
});
304+
305+
expect(messagesTo.map(m => m.msg)).toContainEqual({
306+
type: Messages.NEW_PROBLEM,
307+
problem: testProblem
308+
});
309+
})
292310
});
293311
});

src/js/networking.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ const initializeRemotePlayer = (id, data) => {
5757
solved: false,
5858
},
5959
]);
60+
const $problem = get(gameProblem);
61+
if (!connections.has(id) || $problem === null) return;
62+
connections.get(id)?.send({
63+
type: Messages.NEW_PROBLEM,
64+
problem: $problem
65+
});
6066
};
6167

6268
/** @type {DataResponder<NEW_PROB_MSG>} */

0 commit comments

Comments
 (0)