@dimcool/dimclaw 0.1.28 → 0.1.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +45 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -37376,16 +37376,56 @@ async function joinQueue(client, args) {
|
|
|
37376
37376
|
try {
|
|
37377
37377
|
await client.ensureConnected();
|
|
37378
37378
|
const lobby = await client.sdk.lobbies.joinQueue(args.lobbyId);
|
|
37379
|
-
|
|
37379
|
+
let matched = !!(lobby.status === "active" && lobby.gameId);
|
|
37380
|
+
let gameId = lobby.gameId || null;
|
|
37381
|
+
if (!matched) {
|
|
37382
|
+
const lobbyStore = client.sdk.lobbyStore;
|
|
37383
|
+
lobbyStore.joinLobby(args.lobbyId);
|
|
37384
|
+
const timeout = 3e5;
|
|
37385
|
+
const start = Date.now();
|
|
37386
|
+
let lastRefresh = Date.now();
|
|
37387
|
+
while (Date.now() - start < timeout) {
|
|
37388
|
+
const matchedEvent = lobbyStore.store.getState().matchedEvent;
|
|
37389
|
+
if (matchedEvent?.gameId) {
|
|
37390
|
+
gameId = matchedEvent.gameId;
|
|
37391
|
+
matched = true;
|
|
37392
|
+
break;
|
|
37393
|
+
}
|
|
37394
|
+
if (Date.now() - lastRefresh > 2e3) {
|
|
37395
|
+
try {
|
|
37396
|
+
const fresh = await client.sdk.lobbies.getLobby(args.lobbyId);
|
|
37397
|
+
if (fresh.status === "active" && fresh.gameId) {
|
|
37398
|
+
gameId = fresh.gameId;
|
|
37399
|
+
matched = true;
|
|
37400
|
+
break;
|
|
37401
|
+
}
|
|
37402
|
+
} catch {
|
|
37403
|
+
}
|
|
37404
|
+
lastRefresh = Date.now();
|
|
37405
|
+
}
|
|
37406
|
+
await raceTimeout(
|
|
37407
|
+
new Promise((resolve2) => {
|
|
37408
|
+
const unsub = lobbyStore.store.subscribeSelector(
|
|
37409
|
+
(s) => s.matchedEvent,
|
|
37410
|
+
() => {
|
|
37411
|
+
unsub();
|
|
37412
|
+
resolve2();
|
|
37413
|
+
}
|
|
37414
|
+
);
|
|
37415
|
+
}),
|
|
37416
|
+
1e3
|
|
37417
|
+
);
|
|
37418
|
+
}
|
|
37419
|
+
}
|
|
37380
37420
|
const spectateUrl = matched ? await getSpectateUrl(client) : null;
|
|
37381
37421
|
return {
|
|
37382
37422
|
data: {
|
|
37383
37423
|
lobbyId: lobby.id,
|
|
37384
|
-
status: lobby.status,
|
|
37385
|
-
gameId
|
|
37424
|
+
status: matched ? "active" : lobby.status,
|
|
37425
|
+
gameId,
|
|
37386
37426
|
matched: !!matched,
|
|
37387
37427
|
...spectateUrl && { spectateUrl },
|
|
37388
|
-
hint: matched ? `Game started! Call dim_game_loop with gameId "${
|
|
37428
|
+
hint: matched ? `Game started! Call dim_game_loop with gameId "${gameId}" to play.${spectateUrl ? ` Tell the user they can spectate at ${spectateUrl}` : ""}` : "No match found within timeout. Call dim_join_queue again to resume waiting."
|
|
37389
37429
|
}
|
|
37390
37430
|
};
|
|
37391
37431
|
} catch (error) {
|
|
@@ -37526,7 +37566,7 @@ async function gameLoop(client, args) {
|
|
|
37526
37566
|
}),
|
|
37527
37567
|
1e3
|
|
37528
37568
|
);
|
|
37529
|
-
if (Date.now() - lastRefresh >
|
|
37569
|
+
if (Date.now() - lastRefresh > 2e3) {
|
|
37530
37570
|
const fresh = await client.sdk.games.getGameState(gameId);
|
|
37531
37571
|
store.setBaseState(gameId, fresh);
|
|
37532
37572
|
lastRefresh = Date.now();
|
package/package.json
CHANGED