From 8e948fc451c86cba94921f36ffafffe7efbeeaf5 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Tue, 14 Nov 2023 11:17:54 +0100 Subject: [PATCH] Introduce streams --- api/inputs.go | 4 +-- ui/src/lib/components/Inputs.svelte | 45 ++++++++++++++++------------- ui/src/lib/input.js | 8 ++--- ui/src/routes/+page.svelte | 10 +++++-- 4 files changed, 38 insertions(+), 29 deletions(-) diff --git a/api/inputs.go b/api/inputs.go index 554a7f7..76302e1 100644 --- a/api/inputs.go +++ b/api/inputs.go @@ -47,7 +47,7 @@ func declareInputsRoutes(cfg *config.Config, router *gin.RouterGroup) { inputsRoutes.GET("/settings", func(c *gin.Context) { c.JSON(http.StatusOK, c.MustGet("input")) }) - inputsRoutes.GET("/currently", func(c *gin.Context) { + inputsRoutes.GET("/streams", func(c *gin.Context) { src := c.MustGet("input").(inputs.SoundInput) if !src.IsActive() { @@ -58,7 +58,7 @@ func declareInputsRoutes(cfg *config.Config, router *gin.RouterGroup) { c.JSON(http.StatusOK, src.CurrentlyPlaying()) }) - streamRoutes := inputsRoutes.Group("/stream/:stream") + streamRoutes := inputsRoutes.Group("/streams/:stream") streamRoutes.Use(StreamHandler) streamRoutes.POST("/pause", func(c *gin.Context) { diff --git a/ui/src/lib/components/Inputs.svelte b/ui/src/lib/components/Inputs.svelte index b49b664..12895cc 100644 --- a/ui/src/lib/components/Inputs.svelte +++ b/ui/src/lib/components/Inputs.svelte @@ -39,27 +39,32 @@ {/each} {#each $inputsList as input} {#if showInactives || input.active} -
  • -
    - {input.name} - {#await input.currently()} -
    - Loading... -
    - {:then title} - {title} - {/await} -
    - {#if input.controlable} -
    - +
  • + {input.name} + {#await input.streams()} +
    + Loading...
    - {/if} + {:then streams} + {#each Object.keys(streams) as idstream} + {@const title = streams[idstream]} +
    +
    + {title} +
    + {#if input.controlable} +
    + +
    + {/if} +
    + {/each} + {/await}
  • {/if} {/each} diff --git a/ui/src/lib/input.js b/ui/src/lib/input.js index 1a458b6..1635b82 100644 --- a/ui/src/lib/input.js +++ b/ui/src/lib/input.js @@ -12,8 +12,8 @@ export class Input { this.controlable = controlable; } - async currently() { - const data = await fetch(`api/inputs/${this.id}/currently`, {headers: {'Accept': 'application/json'}}); + async streams() { + const data = await fetch(`api/inputs/${this.id}/streams`, {headers: {'Accept': 'application/json'}}); if (data.status == 200) { return await data.json(); } else { @@ -21,8 +21,8 @@ export class Input { } } - async playpause() { - const data = await fetch(`api/inputs/${this.id}/pause`, {headers: {'Accept': 'application/json'}, method: 'POST'}); + async playpause(idstream) { + const data = await fetch(`api/inputs/${this.id}/streams/${idstream}/pause`, {headers: {'Accept': 'application/json'}, method: 'POST'}); if (data.status != 200) { throw new Error((await res.json()).errmsg); } diff --git a/ui/src/routes/+page.svelte b/ui/src/routes/+page.svelte index 2d94ab7..9bc014b 100644 --- a/ui/src/routes/+page.svelte +++ b/ui/src/routes/+page.svelte @@ -40,12 +40,16 @@
    - {#await input.currently()} + {#await input.streams()}
    Loading...
    @ {input.name} - {:then title} - {title} @ {input.name} + {:then streams} + {#each Object.keys(streams) as idstream} + {@const title = streams[idstream]} + {title} + {/each} + @ {input.name} {:catch error} {input.name} activée {/await}