feat: add reconnection logic with exponential backoff to shard client
This commit is contained in:
@@ -354,4 +354,46 @@ describe('EcastShardClient', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('buildReconnectUrl', () => {
|
||||
test('uses stored secret and id', () => {
|
||||
const client = new EcastShardClient({
|
||||
sessionId: 1,
|
||||
gameId: 1,
|
||||
roomCode: 'TEST',
|
||||
maxPlayers: 8,
|
||||
onEvent: () => {},
|
||||
});
|
||||
client.secret = 'abc-123';
|
||||
client.shardId = 5;
|
||||
client.host = 'ecast-prod-use2.jackboxgames.com';
|
||||
|
||||
const url = client.buildReconnectUrl();
|
||||
expect(url).toContain('secret=abc-123');
|
||||
expect(url).toContain('id=5');
|
||||
expect(url).toContain('role=shard');
|
||||
expect(url).toContain('ecast-prod-use2.jackboxgames.com');
|
||||
});
|
||||
});
|
||||
|
||||
describe('handleError with code 2027', () => {
|
||||
test('marks game as finished and emits events on room-closed error', () => {
|
||||
const events = [];
|
||||
const client = new EcastShardClient({
|
||||
sessionId: 1,
|
||||
gameId: 5,
|
||||
roomCode: 'TEST',
|
||||
maxPlayers: 8,
|
||||
onEvent: (type, data) => events.push({ type, data }),
|
||||
});
|
||||
client.playerCount = 4;
|
||||
client.playerNames = ['A', 'B', 'C', 'D'];
|
||||
|
||||
client.handleError({ code: 2027, msg: 'the room has already been closed' });
|
||||
|
||||
expect(client.gameFinished).toBe(true);
|
||||
expect(events.some(e => e.type === 'game.ended')).toBe(true);
|
||||
expect(events.some(e => e.type === 'room.disconnected' && e.data.reason === 'room_closed')).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user