No overview comment at the top of the file.
- Imports
- EventBus.serverProducer
- Used by
- 4 loaders3 actions2 routes2 other
Types
What a scene set registers into the hub: how it builds a broadcast's state and how its producer moves between its scenes. Every broadcast shows one scene set, passed along with its key.
export interface Layout<State extends BroadcastState = BroadcastState> {
producer: Producer.Rules<State["live"]>;
/** Freshly built state of the broadcast, `null` when the tournament has no broadcast by the key. */
build: (key: HubKey) => Promise<BroadcastSnapshot.Built<State> | null>;
}Functions & values
Connects a client to the broadcast: it gets the current state right away (once built) and every change after, until the signal aborts. One hub per broadcast rebuilds the state on the tournament's events and fans it out to all clients.
export function connect<State extends BroadcastState>({
layout,
role,
send,
close,
signal,
isClipSender,
programId,
...key
}: HubKey & {
layout: Layout<State>;
role: BroadcastStreamRole;
send: Client["send"];
close: Client["close"];
signal: AbortSignal;
isClipSender: boolean;
programId: Client["programId"];
})Unit tests (4)
Passes a WebRTC session description from the client the token belongs to on to the peer, when one of them is a clip sender and the other is not. Returns whether it was passed on.
export function relaySignal({
token,
to,
description,
...key
}: HubKey & {
token: string;
to: string;
description: BroadcastSessionDescription;
})functionconnectStandby
:200 Keeps a connection through a user's OBS URL while it isn't pointed at a broadcast, see {@link reloadProgram}.
export function connectStandby({
signal,
...client
}: StandbyClient & { signal: AbortSignal })functionreloadProgram
:216 Tells the pages connected through a user's OBS URL to load again, e.g. after it was pointed at another broadcast. Ones already showing the broadcast of except are left as they are.
export function reloadProgram({
programId,
except,
}: {
programId: number;
except?: HubKey;
})Unit tests (2)
Closes the connections through a user's OBS URL, e.g. after its key was regenerated.
export function closeProgram(programId: number)
Unit tests (2)
Rebuilds the broadcast's state for its clients, e.g. after the producer changed it.
export function refresh(key: HubKey)
functionapplyGameSignal
:246 Applies what the scanner saw to the broadcast, see Producer.applyGameSignal.
export async function applyGameSignal<State extends BroadcastState>({
layout,
signal,
...key
}: HubKey & { layout: Layout<State>; signal: BroadcastGameSignal })Freshly built state of the broadcast with its current connection counts, null when the tournament has no broadcast by the key.
export async function buildState<State extends BroadcastState>({
layout,
...key
}: HubKey & { layout: Layout<State> })Unit tests not about one export (6)
No overview comment at the top of the file.
- Imports
- ProducerSetProgress
- Used by
- 2 modules
Types
Broadcast state minus the connection counts, which the hub adds.
export type Snapshot<State extends BroadcastState = BroadcastState> = Omit<
State,
"health"
>;
A scene set's freshly built state of a broadcast, see BroadcastHub.Layout.
export interface Built<State extends BroadcastState = BroadcastState> {
snapshot: Snapshot<State>;
channel: BroadcastChannel;
/** Event channels whose events change the state. */
eventChannels: string[];
}Functions & values
The channel's broadcast's producer state and settings as stored, settings and producer fields added after it was written filled in with their defaults (a broadcast nothing has been written to yet gets them all).
export async function stored<
Item extends ProducerState,
Settings extends BroadcastSettings,
>({
tournamentId,
channel,
rules,
defaultSettings,
}: {
tournamentId: number;
channel: BroadcastChannel;
rules: Producer.Rules<Item>;
defaultSettings: Settings;
}): Promise<{ state: BroadcastStoredState<Item>; settings: Settings }>The match the broadcast features, as on air (the first liveResults.count of its results, see SetProgress.liveResultCount) and as reported. null when it is not the tournament's.
export async function featuredMatch({
tournament,
matchId,
liveResults,
}: {
tournament: Tournament;
matchId: number;
liveResults: LiveResults | null;
}): Promise<BroadcastMatch | null>functiontoBroadcastTeam
:152 The tournament team as the overlays show it, with its active roster.
export function toBroadcastTeam({
tournament,
tournamentTeam,
players,
}: {
tournament: Tournament;
tournamentTeam: Tournament["ctx"]["teams"][number];
players: PlayerRow[];
}): BroadcastTeamNo overview comment at the top of the file.
- Imports
- no other modules
- Used by
- 1 route1 other
Types
interfaceClipSource
no JSDoc:29 export interface ClipSource {
id: string;
url: string;
}interfaceClipPeerStatus
:35 How sending the clips to one overlay is going.
export interface ClipPeerStatus {
peer: BroadcastPeer;
connectionState: RTCPeerConnectionState;
/** Clips the overlay was missing as the channel opened, `null` before that. */
missingCount: number | null;
receivedCount: number;
/** From the channel opening to the overlay having the last missing clip. */
transferMs: number | null;
}typeClipSender
no JSDoc:45 export type ClipSender = ReturnType<typeof createSender>;
typeClipReceiver
no JSDoc:47 export type ClipReceiver = ReturnType<typeof createReceiver>;
Functions & values
Sends the clips to every overlay connected to the broadcast's stream (the dashboard's previews included), each over a WebRTC data channel of its own. The stream's messages are fed to handleMessage: they tell who the overlays are and carry their answers.
export function createSender({
signalUrl,
clips,
onChange,
}: {
signalUrl: string;
clips: ReadonlyArray<ClipSource>;
onChange: (statuses: ClipPeerStatus[]) => void;
})functioncreateReceiver
:276 Receives clips from the dashboards sending them, answering their offers. onChange gets the object URLs of every clip received so far by clip id, kept over reconnects until close.
export function createReceiver({
signalUrl,
onChange,
}: {
signalUrl: string;
onChange: (urls: ReadonlyMap<string, string>) => void;
})Unit tests not about one export (5)
No overview comment at the top of the file.
- Imports
- no other modules
- Used by
- 2 modules
Functions & values
The ink color pair of the two teams' colors read off the game's HUD, in either order, by their perceptual (CIEDE2000) distance to how each pair renders there. null when no pair is close, e.g. a pair not in {@link BROADCAST_INK_COLORS}, or when another pair is about as close, rather than guess.
previous is the pair the broadcast showed last: Color Lock is the viewing console's setting, so after a Color Lock pair the same one stays as long as the read fits it, and after any other pair Color Lock pairs are out.
export function closestPair(
inks: [BroadcastInkRgb, BroadcastInkRgb],
previous: BroadcastInkColorKey | null,
): BroadcastInkColorKey | null
Unit tests (2)
Whether the two teams' colors are in the pair's order, the first one closer to the pair's first color than the second one is (e.g. minimap reads, which render a bit off the HUD's colors). null when neither was read.
export function isInPairOrder(
inks: [BroadcastInkRgb | null, BroadcastInkRgb | null],
key: BroadcastInkColorKey,
): boolean | null
Unit tests (1)
No overview comment at the top of the file.
- Imports
- InkColor
- Used by
- 1 action1 route1 repository3 modules2 components3 other
Types
How a scene set's producer moves between its scenes, which the producer functions take first. Its items are the scene set's ProducerState, with the fields its scenes are set up with.
export interface Rules<Item extends ProducerState> {
/** What is on air (`live`) and staged (`next`) on a broadcast nothing has been written to yet. */
initial: { live: Omit<Item, "id">; next: Omit<Item, "id"> };
/** The scene that logically follows each scene, staged after it when nothing is queued (e.g. rosters → game). */
sceneAfter: Record<Item["scene"], Item["scene"]>;
/** The scene showing the game itself: goes on air as the scanner sees the game start, the scene after it as the game ends. */
gameScene: Item["scene"];
/** Duration a scene gets when picked, `null` runs until a Take. */
defaultDurationMs(scene: Item["scene"]): number | null;
/** How long the item's scene runs, when some scenes last as long as their footage instead of a given duration. */
lengthMs?(item: Item): number | null;
/** The item without what doesn't carry over to the item following it (e.g. a clip picked for it). */
followedBy?(item: Item): Item;
/** Whether the item's scene shows the featured match, so it can't go on air without one. */
needsMatch?(item: Item): boolean;
/** Staged instead of the scene that logically follows when that one needs the featured match and there is none. */
sceneWithoutMatch?: Item["scene"];
/**
* Whether the scene stays on air until a Take, whatever happens meanwhile (e.g. technical difficulties): what is
* staged after it waits for a Take unless the producer sets it otherwise.
*/
staysUntilTake?(scene: Item["scene"]): boolean;
}Fields of a staged item the producer edits, see {@link editItem}.
export type ItemPatch<Item extends ProducerState> = Partial<Omit<Item, "id">>;
Functions & values
State of a broadcast nothing has been written to yet, see Rules.initial.
export function initialState<Item extends ProducerState>(
rules: Rules<Item>,
): BroadcastStoredState<Item>
Stored state with the producer fields added after it was written filled in with their defaults. The state is the one the scene set of the rules wrote.
export function withDefaults<Item extends ProducerState>(
rules: Rules<Item>,
state: BroadcastStoredState,
): BroadcastStoredState<Item>
Unit tests (1)
Puts the staged state on air, along with the match results next showed. The first queued item gets staged, or without one the scene that logically follows (e.g. rosters → game → rosters, see Rules.sceneWithoutMatch).
export function take<Item extends ProducerState>(
rules: Rules<Item>,
state: BroadcastStoredState<Item>,
{
liveResults,
now,
hasMatch,
}: { liveResults: LiveResults | null; now: number; hasMatch: boolean },
): BroadcastStoredState<Item>Unit tests (5)
Whether a Take can put the staged item on air: one showing the featured match (see Rules.needsMatch) only with one.
export function canTake<Item extends ProducerState>(
rules: Rules<Item>,
state: BroadcastStoredState<Item>,
{ hasMatch }: { hasMatch: boolean },
)Unit tests (2)
How long the item's scene runs before the item after it can go on air by itself: the duration it was given, unless the scene lasts as long as its footage (see Rules.lengthMs). null runs until a Take.
export function lengthMs<Item extends ProducerState>(
rules: Rules<Item>,
item: Item,
)
Unit tests (1)
functionliveStartedAt
:138 When the scene on air started (epoch ms): once the transition of the Take that put it on air revealed it.
export function liveStartedAt(state: BroadcastStoredState)
When the scene on air has run its length (epoch ms), null when it runs until a Take.
export function liveEndsAt<Item extends ProducerState>(
rules: Rules<Item>,
state: BroadcastStoredState<Item>,
)
When the staged item goes on air by itself (epoch ms): its transition timed to hide the scene on air as that one ends. null when it waits for a Take or a game event (see {@link applyGameSignal}), or can't go on air (see {@link canTake}).
export function autoTakeAt<Item extends ProducerState>(
rules: Rules<Item>,
state: BroadcastStoredState<Item>,
{ hasMatch }: { hasMatch: boolean },
)Unit tests (3)
Which game event the scanner reporting puts the item on air, given the item before it: the game scene (see Rules.gameScene) goes on air as the game starts, the scene after it as the game ends. null between two scenes without a game.
export function gameCue<Item extends ProducerState>(
rules: Rules<Item>,
before: Pick<Item, "scene">,
item: Pick<Item, "scene">,
): "start" | "end" | null
Unit tests (1)
functioneffectiveAdvance
:205 What puts the item on air besides a Take, given the item before it. An advance that can't happen there waits for a Take: a timer after a scene running until a Take, a game event between scenes without a game.
export function effectiveAdvance<Item extends ProducerState>(
rules: Rules<Item>,
before: Item,
item: Item,
): BroadcastAdvance
Unit tests (1)
functionadvanceOptions
:224 The advances the item can be set to after the item before it, in {@link BROADCAST_ADVANCES} order: a Take always, a timer after a scene with a length, a game event where a game starts or ends between them.
export function advanceOptions<Item extends ProducerState>(
rules: Rules<Item>,
before: Item,
item: Item,
): BroadcastAdvance[]
Unit tests (1)
functionapplyGameSignal
:244 What the scanner seeing a game start or end changes. The ink read (with the start or after it) colors the game (Color Lock carrying over from the broadcast's previous game, see InkColor.closestPair), the teams keeping the sides they had earlier in the set (the pair's first color always goes to the same lobby team). A start or end the staged item waits for puts it on air right away, not when the item can't go on air (see {@link canTake}). A game ending cuts only along with what the scanner read of it, which is kept as scannedGame with the game's ink colors. null when nothing changes.
export function applyGameSignal<Item extends ProducerState>(
rules: Rules<Item>,
state: BroadcastStoredState<Item>,
{
signal,
liveResults,
now,
}: {
signal: BroadcastGameSignal;
/** The featured match and how many of its results are reported, `null` without one. */
liveResults: LiveResults | null;
now: number;
},
): BroadcastStoredState<Item> | nullUnit tests (12)
The staged items in the order they go on air: next then the queue.
export function stagedItems<Item extends ProducerState>(
state: BroadcastStoredState<Item>,
)
Changes a staged item, null when it is not staged anymore (e.g. a Take put it on air). Picking another scene gives the item that scene's default duration and advance, and one staying on air until a Take (see Rules.staysUntilTake) makes the item staged after it wait for a Take.
export function editItem<Item extends ProducerState>(
rules: Rules<Item>,
state: BroadcastStoredState<Item>,
itemId: number,
patch: ItemPatch<Item>,
)
Unit tests (5)
Queues the scene that logically follows the last staged item (see Rules.sceneWithoutMatch), with that item's settings. The new item's id is lastItemId + 1 of the state given.
export function enqueue<Item extends ProducerState>(
rules: Rules<Item>,
state: BroadcastStoredState<Item>,
{ hasMatch }: { hasMatch: boolean },
): BroadcastStoredState<Item>Unit tests (3)
Takes an item out of the staged ones, the first queued one getting staged when it was next. null when it is not staged anymore or is the only one, there always being something staged.
export function removeItem<Item extends ProducerState>(
state: BroadcastStoredState<Item>,
itemId: number,
)
Unit tests (2)
Moves a staged item to toIndex of the staged items (0 = next), null when it is not staged anymore, already there or the index is out of range.
export function moveItem<Item extends ProducerState>(
state: BroadcastStoredState<Item>,
itemId: number,
toIndex: number,
)
Unit tests (1)
No overview comment at the top of the file.
- Imports
- no other modules
- Used by
- 2 modules1 component1 other
Functions & values
How far the set is after its first resultCount results (capped to the reported ones). A game already reported shows the map it was played on, the ones after the last report the map list's maps.
export function atResultCount({
results,
resultCount,
teamIds,
bracketScores,
isSetOver,
plannedMaps,
gameCount,
}: {
/** In playing order. */
results: Result[];
resultCount: number;
/** In bracket order. */
teamIds: [number | null, number | null];
/** As the bracket has them, used once every result is counted (an admin can end a set with a score of their own). */
bracketScores: [number, number];
isSetOver: boolean;
/** The set's map list without the banned maps, in playing order, as far as it is known. */
plannedMaps: BroadcastMap[];
/** How many games the set can have at most, e.g. 5 for a Bo5. */
gameCount: number;
}): MatchProgressUnit tests (6)
functiongamesUntilDecided
:90 The set's games without the ones it ended before: those after the game a team clinched it in, or every unplayed one once the set is over (an admin can end it early). The game being played counts as won by currentWinner, its result being known before it is reported.
export function gamesUntilDecided({
progress,
match,
currentWinner,
}: {
progress: MatchProgress;
match: Pick<BroadcastMatch, "count" | "countType">;
currentWinner: 0 | 1 | null;
}): BroadcastGame[]Unit tests (2)
functionliveResultCount
:124 How many of the match's results are on air: what the last Take or "show now" put there, all of them for a match not taken yet.
export function liveResultCount({
liveResults,
matchId,
resultCount,
}: {
liveResults: LiveResults | null;
matchId: number;
resultCount: number;
})Unit tests (1)
Index of the team (in bracket order) that won the set, null while it is going.
export function winner(progress: Pick<MatchProgress, "scores" | "isOver">)
Unit tests (1)
No overview comment at the top of the file.
- Imports
- no other modules
- Used by
- 1 component1 other
Types
Where CSS fails to parse and why.
export interface CssError {
line: number;
reason: string;
}interfaceCustomPropertyDeclaration
:75 A custom property declared in CSS, start and end being where its value is in the text.
export interface CustomPropertyDeclaration {
name: string;
value: string;
start: number;
end: number;
}Only used inside the module
interfaceVariableReference
:103 A var() in CSS, start and end being where the whole var(...) is in the text.
export interface VariableReference {
name: string;
start: number;
end: number;
}Functions & values
functionfromModuleSource
:31 The CSS module source of an overlay stylesheet as theme CSS: its classes named .{stylesheet}-{class} (e.g. .GameScene-infoCard), which the overlay resolves to the module's classes, and :global() unwrapped.
export function fromModuleSource({
source,
stylesheet,
}: {
source: string;
stylesheet: string;
})Unit tests (2)
Why the CSS doesn't parse, null when it does.
export function syntaxError(css: string): CssError | null
Unit tests (2)
functioncustomPropertyDeclarations
:83 The custom properties declared in the CSS in order, read off the text so also of CSS that doesn't parse.
export function customPropertyDeclarations(
css: string,
): CustomPropertyDeclaration[]
Unit tests (1)
functionvariableReferences
:110 The var()s of the text in order, a fallback included in its var().
export function variableReferences(text: string): VariableReference[]
Unit tests (1)
The rules of edited that differ from base: changed and added declarations, unset for the removed ones and whole at-rules like @keyframes that changed. Nested rules stay nested in their parents. Empty when nothing changed. Throws a CssSyntaxError when edited doesn't parse.
export function diff(base: string, edited: string)
Unit tests (7)
The CSS saved for the overlays: the edits of each stylesheet (see {@link diff}) in {@link THEME_EDITS_LAYER}, then the custom CSS as is, unlayered. The custom CSS' @imports (web fonts) stay first, where they have to be to load. Without edits it is the custom CSS alone.
export function compose({
edits,
custom,
}: {
edits: string[];
custom: string;
})Unit tests (4)
Splits saved CSS (see {@link compose}) back to the stylesheets it edits: each stylesheet with its edits applied, and what is left as the custom CSS (anything outside the edits layer, or edits of rules no stylesheet has anymore). Unparseable CSS is left whole as the custom CSS.
export function merge<Name extends string>({
bases,
css,
}: {
bases: Record<Name, string>;
css: string;
}): { stylesheets: Record<Name, string>; custom: string }Unit tests (6)