/** Internal: send a single `session_status` frame to every OPEN client. */
function broadcastFrame(clients, msg) {
    const data = JSON.stringify(msg);
    for (const client of clients) {
        if (client.readyState !== 1)
            continue;
        try {
            client.send(data);
        }
        catch { /* per-client send failure is non-fatal */ }
    }
}
/**
 * Mutate `session.status`, bump `statusVersion`, and broadcast the new status
 * to every connected client.
 *
 * `extras` lets transition sites attach `streamingStartedAt` (only on the
 * "streaming" branch) and `archivedAt` (only on the "archived" branch).
 */
export function broadcastStatus(session, status, extras) {
    session.status = status;
    session.statusVersion = (session.statusVersion ?? 0) + 1;
    broadcastFrame(session.clients, {
        type: "session_status",
        status: status,
        statusVersion: session.statusVersion,
        ...(extras?.streamingStartedAt ? { streamingStartedAt: extras.streamingStartedAt } : {}),
        ...(extras?.archivedAt ? { archivedAt: extras.archivedAt } : {}),
    });
}
//# sourceMappingURL=session-status.js.map