cat / goq
clone

turns a linux box into a private steam streaming appliance: plug in, tap your key, play from another computer

fix/release-manifest-language
goq / portal / frame-session.mjs
frame-session.mjs 1.8K
1export const FRAME_CHANNEL_CAPACITY = 4;23function validGeneration(value) {4 return Number.isSafeInteger(value) && value > 0;5}67export function newFrameSession() {8 return {9 expectedGeneration: null,10 pendingAcknowledgments: [],11 pendingFrameErrors: [],12 failed: false,13 failureDetail: null,14 closing: false,15 };16}1718// Before connect returns, a binary channel delivery has no generation in its19// envelope. Keep only the Rust channel's maximum outstanding acknowledgments;20// this is enough to release every permit once the connect result identifies21// the session, without allowing an unbounded callback backlog.22export function stageFrameAcknowledgment(session, generation = null) {23 if (!session || session.closing) return null;24 if (generation !== null && !validGeneration(generation)) {25 throw new TypeError('invalid frame generation');26 }27 if (session.expectedGeneration !== null) {28 return generation ?? session.expectedGeneration;29 }30 if (session.pendingAcknowledgments.length >= FRAME_CHANNEL_CAPACITY) {31 throw new Error('pre-connect frame acknowledgment capacity exceeded');32 }33 session.pendingAcknowledgments.push(generation);34 return null;35}3637export function activateFrameSession(session, generation) {38 if (!session || session.closing || !validGeneration(generation)) {39 throw new TypeError('invalid active frame generation');40 }41 if (session.expectedGeneration !== null) {42 throw new Error('frame session is already active');43 }44 session.expectedGeneration = generation;45 const acknowledgments = session.pendingAcknowledgments.map(46 (pendingGeneration) => pendingGeneration ?? generation,47 );48 session.pendingAcknowledgments.length = 0;49 return { acknowledgments };50}5152export function isActiveFrameSession(session, activeSession) {53 return session !== null && session === activeSession && !session.closing;54}