Support Pulseaudio sink-inputs

This commit is contained in:
nemunaire 2023-11-13 20:00:28 +01:00
commit bbde2299fe
8 changed files with 145 additions and 10 deletions

View file

@ -57,14 +57,18 @@ func declareInputsRoutes(cfg *config.Config, router *gin.RouterGroup) {
c.JSON(http.StatusOK, src.CurrentlyPlaying())
})
inputsRoutes.POST("/pause", func(c *gin.Context) {
streamRoutes := inputsRoutes.Group("/stream/:stream")
streamRoutes.Use(StreamHandler)
streamRoutes.POST("/pause", func(c *gin.Context) {
input, ok := c.MustGet("input").(inputs.ControlableInput)
if !ok {
c.AbortWithStatusJSON(http.StatusMethodNotAllowed, gin.H{"errmsg": "The source doesn't support that"})
return
}
err := input.TogglePause()
err := input.TogglePause(c.MustGet("streamid").(string))
if err != nil {
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": fmt.Sprintf("Unable to pause the input: %s", err.Error())})
return
@ -85,3 +89,20 @@ func InputHandler(c *gin.Context) {
c.Next()
}
func StreamHandler(c *gin.Context) {
input := c.MustGet("input").(inputs.SoundInput)
streams := input.CurrentlyPlaying()
stream, ok := streams[c.Param("stream")]
if !ok {
c.AbortWithStatusJSON(http.StatusNotFound, gin.H{"errmsg": fmt.Sprintf("Stream not found: %s", c.Param("stream"))})
return
}
c.Set("streamid", c.Param("stream"))
c.Set("stream", stream)
c.Next()
}

View file

@ -122,7 +122,7 @@ func declareSourcesRoutes(cfg *config.Config, router *gin.RouterGroup) {
return
}
c.JSON(http.StatusOK, s.TogglePause())
c.JSON(http.StatusOK, s.TogglePause("default"))
})
}