Introduce streams
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/tag Build is failing

This commit is contained in:
nemunaire 2023-11-14 11:17:54 +01:00
parent bbde2299fe
commit 8e948fc451
4 changed files with 38 additions and 29 deletions

View File

@ -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) {

View File

@ -39,27 +39,32 @@
{/each}
{#each $inputsList as input}
{#if showInactives || input.active}
<li class="list-group-item py-3 d-flex justify-content-between">
<div>
<strong>{input.name}</strong>
{#await input.currently()}
<div class="spinner-border spinner-border-sm" role="status">
<span class="visually-hidden">Loading...</span>
</div>
{:then title}
<span class="text-muted">{title}</span>
{/await}
</div>
{#if input.controlable}
<div>
<button
class="btn btn-sm btn-primary"
on:click={() => input.playpause()}
>
<i class="bi bi-pause"></i>
</button>
<li class="list-group-item py-3 d-flex flex-column">
<strong>{input.name}</strong>
{#await input.streams()}
<div class="spinner-border spinner-border-sm" role="status">
<span class="visually-hidden">Loading...</span>
</div>
{/if}
{:then streams}
{#each Object.keys(streams) as idstream}
{@const title = streams[idstream]}
<div class="d-flex justify-content-between">
<div>
<span class="text-muted">{title}</span>
</div>
{#if input.controlable}
<div>
<button
class="btn btn-sm btn-primary"
on:click={() => input.playpause(idstream)}
>
<i class="bi bi-pause"></i>
</button>
</div>
{/if}
</div>
{/each}
{/await}
</li>
{/if}
{/each}

View File

@ -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);
}

View File

@ -40,12 +40,16 @@
<div class="d-inline-block me-3">
<div class="d-flex justify-content-between align-items-center">
<div>
{#await input.currently()}
{#await input.streams()}
<div class="spinner-border spinner-border-sm" role="status">
<span class="visually-hidden">Loading...</span>
</div> <span class="text-muted">@ {input.name}</span>
{:then title}
<strong>{title}</strong> <span class="text-muted">@ {input.name}</span>
{:then streams}
{#each Object.keys(streams) as idstream}
{@const title = streams[idstream]}
<strong>{title}</strong>
{/each}
<span class="text-muted">@ {input.name}</span>
{:catch error}
{input.name} activée
{/await}