diff --git a/src/pkjs/index.js b/src/pkjs/index.js index 8312e59..0071e55 100644 --- a/src/pkjs/index.js +++ b/src/pkjs/index.js @@ -222,6 +222,13 @@ function payloadGet(payload, name) { return undefined; } +function ringSlice(arr, start, end) { + const n = arr.length; + if (n === 0) return []; + const count = Math.max(0, end + 1 - start); + return Array.from({ length: count }, (_, k) => arr[(((start + k) % n) + n) % n]); +} + Pebble.addEventListener("appmessage", function (dict) { //console.log("payload", JSON.stringify(dict.payload)); //console.log("expected NAV_SCOPE key", keys.BIDIR_MENU_NAV_SCOPE); @@ -231,7 +238,7 @@ Pebble.addEventListener("appmessage", function (dict) { const seqId = payloadGet(dict.payload, "OUT_PLAY_SEQ_ID"); if (seqId !== undefined) { - callAPI("POST", cfg.PRIV_BASE_URL + "/Sessions/" + jfSessionId + "/Playing?playCommand=PlayNow&itemIds=" + allJfIds[seqId], null); + callAPI("POST", cfg.PRIV_BASE_URL + "/Sessions/" + jfSessionId + "/Playing?playCommand=PlayNow&itemIds=" + ringSlice(allJfIds, seqId, seqId+99), null); } if (scope !== undefined) {