From 0fc2ddbf236b13f9d683119f0f4608bdf541fd22 Mon Sep 17 00:00:00 2001 From: cottongin Date: Fri, 20 Mar 2026 11:04:54 -0400 Subject: [PATCH] feat: add getRoomInfo to jackbox-api for full room data including host Made-with: Cursor --- backend/utils/jackbox-api.js | 34 +++++++++++++++++++++++++++++++++- tests/api/jackbox-api.test.js | 11 +++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 tests/api/jackbox-api.test.js diff --git a/backend/utils/jackbox-api.js b/backend/utils/jackbox-api.js index ff17e8c..e15ee25 100644 --- a/backend/utils/jackbox-api.js +++ b/backend/utils/jackbox-api.js @@ -39,4 +39,36 @@ async function checkRoomStatus(roomCode) { } } -module.exports = { checkRoomStatus }; +async function getRoomInfo(roomCode) { + try { + const response = await fetch(`${JACKBOX_API_BASE}/rooms/${roomCode}`, { + headers: DEFAULT_HEADERS + }); + + if (!response.ok) { + return { exists: false }; + } + + const data = await response.json(); + const body = data.body || data; + + return { + exists: true, + host: body.host, + audienceHost: body.audienceHost, + appTag: body.appTag, + appId: body.appId, + code: body.code, + locked: body.locked || false, + full: body.full || false, + maxPlayers: body.maxPlayers || 8, + minPlayers: body.minPlayers || 0, + audienceEnabled: body.audienceEnabled || false, + }; + } catch (e) { + console.error(`[Jackbox API] Error getting room info for ${roomCode}:`, e.message); + return { exists: false }; + } +} + +module.exports = { checkRoomStatus, getRoomInfo }; diff --git a/tests/api/jackbox-api.test.js b/tests/api/jackbox-api.test.js new file mode 100644 index 0000000..72e34bb --- /dev/null +++ b/tests/api/jackbox-api.test.js @@ -0,0 +1,11 @@ +const { getRoomInfo, checkRoomStatus } = require('../../backend/utils/jackbox-api'); + +describe('jackbox-api exports', () => { + test('getRoomInfo is exported as a function', () => { + expect(typeof getRoomInfo).toBe('function'); + }); + + test('checkRoomStatus is still exported', () => { + expect(typeof checkRoomStatus).toBe('function'); + }); +});