Quick docs for livestream since they're more internal.

main
Zed A. Shaw 2 years ago
parent 861f24b2c2
commit 208568c662
  1. 15
      client/livestreams.js

@ -1,11 +1,18 @@
/*
Mostly just code used in the `client/pages/Live.svelte` and `client/pages/LiveIndex.svelte`
to list and report the available livestreams. It does some caching and normalizes how the
streams are loaded.
*/
import api from "$/client/api.js"; import api from "$/client/api.js";
import { user } from "$/client/stores.js"; import { user } from "$/client/stores.js";
import { get as get_store} from "svelte/store"; import { get as get_store} from "svelte/store";
let livestreams = {}; let livestreams = {};
/* Reset the cache. */
export const reset_cache = () => livestreams = {}; export const reset_cache = () => livestreams = {};
/* Load the available streams and cache them. */
export const load_past_streams = async () => { export const load_past_streams = async () => {
if(!livestreams.index) { if(!livestreams.index) {
const [status, data] = await api.get("/api/livestream"); const [status, data] = await api.get("/api/livestream");
@ -20,6 +27,10 @@ export const load_past_streams = async () => {
return livestreams.index; return livestreams.index;
} }
/*
Load a specific stream, with `cached` set to false it will bypass
the cache when loading it.
*/
export const load_stream = async (livestream_id, cached=true) => { export const load_stream = async (livestream_id, cached=true) => {
if(!cached || !livestreams[livestream_id]) { if(!cached || !livestreams[livestream_id]) {
const [status, data] = await api.get("/api/livestream", {livestream_id}); const [status, data] = await api.get("/api/livestream", {livestream_id});
@ -34,6 +45,10 @@ export const load_stream = async (livestream_id, cached=true) => {
return livestreams[livestream_id]; return livestreams[livestream_id];
} }
/*
Changes the state of the given stream, which is an administrator only
operation that moves it through the visual states.
*/
export const change_stream = async (livestream_id) => { export const change_stream = async (livestream_id) => {
if(get_store(user).admin) { if(get_store(user).admin) {
const [status, data] = await api.post("/api/livestream", { livestream_id}); const [status, data] = await api.post("/api/livestream", { livestream_id});

Loading…
Cancel
Save