anear-js-api 0.6.2 → 0.6.4
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.
|
@@ -346,18 +346,12 @@ class DisplayEventProcessor {
|
|
|
346
346
|
const participantStruct = this.participantsIndex.get(participantId)
|
|
347
347
|
const appCtx = templateRenderContext.app || {}
|
|
348
348
|
|
|
349
|
-
// Determine which participant (if any) is currently timed according to
|
|
350
|
-
// the AppM context (e.g., Tic-Tac-Toe currentPlayerToken).
|
|
351
|
-
const currentToken = appCtx.currentPlayerToken
|
|
352
|
-
const currentPlayerId = currentToken && appCtx.playerIds ? appCtx.playerIds[currentToken] : null
|
|
353
|
-
const isCurrentPlayer = currentPlayerId && participantId === currentPlayerId
|
|
354
|
-
|
|
355
349
|
if (timeoutFn) {
|
|
356
|
-
//
|
|
357
|
-
//
|
|
358
|
-
|
|
359
|
-
if (
|
|
360
|
-
timeout =
|
|
350
|
+
// For participant displays, any non-null / positive timeout value should
|
|
351
|
+
// start a real per-participant timer on that participant's APM.
|
|
352
|
+
const msecs = timeoutFn(appCtx, participantStruct)
|
|
353
|
+
if (typeof msecs === 'number' && msecs > 0) {
|
|
354
|
+
timeout = msecs
|
|
361
355
|
}
|
|
362
356
|
}
|
|
363
357
|
const privateRenderContext = {
|
|
@@ -366,41 +360,36 @@ class DisplayEventProcessor {
|
|
|
366
360
|
}
|
|
367
361
|
|
|
368
362
|
// Build visual timeout (meta.timeout) used by the countdown bar.
|
|
369
|
-
// For
|
|
370
|
-
//
|
|
371
|
-
// so
|
|
363
|
+
// For participant displays we support two patterns:
|
|
364
|
+
// 1) Global participants timeout (allParticipants flow) – mirror the
|
|
365
|
+
// shared participantsActionTimeout so EVERYONE sees the same bar,
|
|
366
|
+
// regardless of whether their own APM is timed.
|
|
367
|
+
// 2) Per-participant timeout (eachParticipant flow) – no global timeout;
|
|
368
|
+
// only the timed participant gets a bar, derived from their own APM.
|
|
372
369
|
let visualTimeout = null
|
|
373
370
|
try {
|
|
374
|
-
//
|
|
375
|
-
const
|
|
376
|
-
|
|
377
|
-
const ctx = state?.context
|
|
378
|
-
if (!ctx || !ctx.actionTimeoutStart || ctx.actionTimeoutMsecs == null) return null
|
|
371
|
+
// First, prefer a shared participants timeout if one exists (e.g., move timer).
|
|
372
|
+
const pat = this.precomputedParticipantsTimeout || this.participantsActionTimeout
|
|
373
|
+
if (pat && typeof pat.msecs === 'number') {
|
|
379
374
|
const now = Date.now()
|
|
380
|
-
const
|
|
381
|
-
const
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
375
|
+
const start = pat.startedAt || Date.now()
|
|
376
|
+
const remainingMsecs = Math.max(0, pat.msecs - (now - start))
|
|
377
|
+
visualTimeout = { msecs: pat.msecs, remainingMsecs }
|
|
378
|
+
} else if (timeout !== null) {
|
|
379
|
+
// Fallback: no global timeout; if this participant has a real timer,
|
|
380
|
+
// show a bar based on their own APM state.
|
|
381
|
+
const state = participantMachine?.state
|
|
382
|
+
const ctx = state?.context
|
|
383
|
+
let remainingMsecs = null
|
|
384
|
+
if (ctx && ctx.actionTimeoutStart && ctx.actionTimeoutMsecs != null) {
|
|
385
|
+
const now = Date.now()
|
|
386
|
+
const elapsed = now - ctx.actionTimeoutStart
|
|
387
|
+
const remaining = ctx.actionTimeoutMsecs - elapsed
|
|
388
|
+
remainingMsecs = remaining > 0 ? remaining : 0
|
|
390
389
|
}
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
const remainingMsecs = computeRemainingFromMachine(currentPm)
|
|
395
|
-
|
|
396
|
-
if (remainingMsecs != null) {
|
|
397
|
-
// Prefer the app-configured move timeout if available; otherwise
|
|
398
|
-
// fall back to the remaining time as the total for visuals.
|
|
399
|
-
const moveTimeout =
|
|
400
|
-
(appCtx.C && typeof appCtx.C.MOVE_TIMEOUT_MSECS === 'number' && appCtx.C.MOVE_TIMEOUT_MSECS > 0)
|
|
401
|
-
? appCtx.C.MOVE_TIMEOUT_MSECS
|
|
402
|
-
: remainingMsecs
|
|
403
|
-
visualTimeout = { msecs: moveTimeout, remainingMsecs }
|
|
390
|
+
visualTimeout = {
|
|
391
|
+
msecs: timeout,
|
|
392
|
+
remainingMsecs: remainingMsecs ?? timeout
|
|
404
393
|
}
|
|
405
394
|
}
|
|
406
395
|
} catch (_e) {
|