88 lines
2.2 KiB
Go
88 lines
2.2 KiB
Go
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()))
|
|
}
|