Implement alarm sound
This commit is contained in:
parent
b7dbc597d8
commit
df31c4dcd1
15 changed files with 531 additions and 50 deletions
47
api/alarm.go
Normal file
47
api/alarm.go
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"git.nemunai.re/nemunaire/reveil/config"
|
||||
"git.nemunai.re/nemunaire/reveil/player"
|
||||
)
|
||||
|
||||
func declareAlarmRoutes(cfg *config.Config, router *gin.RouterGroup) {
|
||||
router.GET("/alarm", func(c *gin.Context) {
|
||||
if player.CommonPlayer == nil {
|
||||
c.JSON(http.StatusOK, false)
|
||||
} else {
|
||||
c.JSON(http.StatusOK, true)
|
||||
}
|
||||
})
|
||||
|
||||
router.POST("/alarm/run", func(c *gin.Context) {
|
||||
if player.CommonPlayer == nil {
|
||||
err := player.WakeUp(cfg)
|
||||
if err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": err.Error()})
|
||||
return
|
||||
}
|
||||
} else {
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": "Player already running"})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, true)
|
||||
})
|
||||
|
||||
router.DELETE("/alarm", func(c *gin.Context) {
|
||||
if player.CommonPlayer != nil {
|
||||
err := player.CommonPlayer.Stop()
|
||||
if err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": err.Error()})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, true)
|
||||
})
|
||||
}
|
||||
|
|
@ -11,6 +11,7 @@ func DeclareRoutes(router *gin.Engine, cfg *config.Config, db *reveil.LevelDBSto
|
|||
apiRoutes := router.Group("/api")
|
||||
|
||||
declareActionsRoutes(cfg, apiRoutes)
|
||||
declareAlarmRoutes(cfg, apiRoutes)
|
||||
declareAlarmsRoutes(cfg, db, resetTimer, apiRoutes)
|
||||
declareGongsRoutes(cfg, apiRoutes)
|
||||
declareHistoryRoutes(cfg, apiRoutes)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue