1.0.5 - added lal webhooks
parent
cba7f8ca13
commit
f7c5b43dce
|
|
@ -4,6 +4,6 @@ import "github.com/gofiber/fiber/v2"
|
||||||
|
|
||||||
func Version(c *fiber.Ctx) error {
|
func Version(c *fiber.Ctx) error {
|
||||||
return c.JSON(fiber.Map{
|
return c.JSON(fiber.Map{
|
||||||
"version": "1.0.4",
|
"version": "1.0.5",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,87 @@
|
||||||
|
package controllers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Pub struct {
|
||||||
|
Server string `json:"server_id"`
|
||||||
|
Protocol string `json:"protocol"`
|
||||||
|
Url string `json:"url"`
|
||||||
|
AppName string `json:"app_name"`
|
||||||
|
Channel string `json:"stream_name"`
|
||||||
|
UrlParam string `json:"url_param"`
|
||||||
|
RemoteAddress string `json:"remotet_addr"`
|
||||||
|
HasInSession bool `json:"has_in_session"`
|
||||||
|
HasOutSession bool `json:"has_out_session"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Update struct {
|
||||||
|
Server string `json:"server_id"`
|
||||||
|
Groups []Group `json:"groups"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Group struct {
|
||||||
|
Channel string `json:"stream_name"`
|
||||||
|
AudioCodec string `json:"audio_codec"`
|
||||||
|
VideoCodec string `json:"video_codec"`
|
||||||
|
VideoWidth int `json:"video_width"`
|
||||||
|
VideoHeight int `json:"video_height"`
|
||||||
|
UpdPub UpdPub `json:"pub"`
|
||||||
|
Subs string `json:"subs"`
|
||||||
|
UpdPull UpdPub `json:"pull"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UpdPub struct {
|
||||||
|
Protocol string `json:"protocol"`
|
||||||
|
SessionId string `json:"session_id"`
|
||||||
|
RemoteAddress string `json:"remote_addr"`
|
||||||
|
StartTime string `json:"start_time"`
|
||||||
|
ReadBytesSum int `json:"read_bytes_sum"`
|
||||||
|
WroteBytesSum int `json:"wrote_bytes_sum"`
|
||||||
|
Bitrate int `json:"bitrate"`
|
||||||
|
ReadBitrate int `json:"read_bitrate"`
|
||||||
|
WriteBitrate int `json:"write_bitrate"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func ServerStart(c *fiber.Ctx) error {
|
||||||
|
fmt.Println("Server started")
|
||||||
|
log.Println(string(c.Body()))
|
||||||
|
return c.SendString("Server started: " + string(c.Body()))
|
||||||
|
}
|
||||||
|
|
||||||
|
func OnUpdate(c *fiber.Ctx) error {
|
||||||
|
p := new(Update)
|
||||||
|
if err := c.BodyParser(p); err != nil {
|
||||||
|
log.Printf("Error Update: %s\n", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(p.Groups) > 0 {
|
||||||
|
for _, g := range p.Groups {
|
||||||
|
log.Printf("Update %s %s [(%dx%d) %d]\n", g.Channel, g.UpdPub.StartTime, g.VideoWidth, g.VideoHeight, g.UpdPub.ReadBytesSum)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return c.SendString("On_Update: " + string(c.Body()))
|
||||||
|
}
|
||||||
|
|
||||||
|
func OnPubStart(c *fiber.Ctx) error {
|
||||||
|
p := new(Pub)
|
||||||
|
if err := c.BodyParser(p); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
log.Printf("Start %s\n", p.Channel)
|
||||||
|
return c.SendString("On_Pub_Start: " + string(c.Body()))
|
||||||
|
}
|
||||||
|
|
||||||
|
func OnPubStop(c *fiber.Ctx) error {
|
||||||
|
p := new(Pub)
|
||||||
|
if err := c.BodyParser(p); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
log.Printf("Stop %s\n", p.Channel)
|
||||||
|
return c.SendString("On_Pub_Stop: " + string(c.Body()))
|
||||||
|
}
|
||||||
|
|
@ -19,6 +19,12 @@ func Setup(app *fiber.App) {
|
||||||
|
|
||||||
app.Post("/check", controllers.CheckStream)
|
app.Post("/check", controllers.CheckStream)
|
||||||
|
|
||||||
|
// Webhooks
|
||||||
|
app.Post("/on_server_start", controllers.ServerStart)
|
||||||
|
app.Post("/on_update", controllers.OnUpdate)
|
||||||
|
app.Post("/on_pub_start", controllers.OnPubStart)
|
||||||
|
app.Post("/on_pub_stop", controllers.OnPubStop)
|
||||||
|
|
||||||
// Protected routes. Needs login before.
|
// Protected routes. Needs login before.
|
||||||
protected := app.Group("/")
|
protected := app.Group("/")
|
||||||
protected.Use(jwtware.New(jwtware.Config{
|
protected.Use(jwtware.New(jwtware.Config{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue