starting channel time limit verification
parent
46235de720
commit
9b2936c810
|
|
@ -24,12 +24,10 @@ func KickSession(stream_name, session_id string) {
|
|||
if err != nil {
|
||||
log.Printf("Error Marshall KickSession: %s\n", err)
|
||||
}
|
||||
resp, err := http.Post(url, "application/json", bytes.NewBuffer(jsonValue))
|
||||
_, err = http.Post(url, "application/json", bytes.NewBuffer(jsonValue))
|
||||
if err != nil {
|
||||
log.Printf("Error Post KickSession: %s\n", err)
|
||||
}
|
||||
|
||||
log.Printf("KickSession status code: %d\n", resp.StatusCode)
|
||||
}
|
||||
|
||||
func ServerStart(c *fiber.Ctx) error {
|
||||
|
|
@ -49,55 +47,56 @@ func ServerStart(c *fiber.Ctx) error {
|
|||
return c.SendString("Server started: " + string(c.Body()))
|
||||
}
|
||||
|
||||
func OnRtmpConnect(c *fiber.Ctx) error {
|
||||
// func OnRtmpConnect(c *fiber.Ctx) error {
|
||||
|
||||
body := new(models.Connect)
|
||||
// body := new(models.Connect)
|
||||
|
||||
if err := c.BodyParser(body); err != nil {
|
||||
log.Printf("Error Start: %s\n", err)
|
||||
return err
|
||||
}
|
||||
// if err := c.BodyParser(body); err != nil {
|
||||
// log.Printf("Error Start: %s\n", err)
|
||||
// return err
|
||||
// }
|
||||
|
||||
utils.PrettyPrintJson(body)
|
||||
return c.SendString("On_Rtmp_Connect: " + string(c.Body()))
|
||||
}
|
||||
// utils.PrettyPrintJson(body)
|
||||
// return c.SendString("On_Rtmp_Connect: " + string(c.Body()))
|
||||
// }
|
||||
|
||||
func OnUpdate(c *fiber.Ctx) error {
|
||||
p := new(models.Update)
|
||||
if err := c.BodyParser(p); err != nil {
|
||||
log.Printf("Error Update: %s\n", err)
|
||||
return err
|
||||
}
|
||||
// func OnUpdate(c *fiber.Ctx) error {
|
||||
// p := new(models.Update)
|
||||
// if err := c.BodyParser(p); err != nil {
|
||||
// log.Printf("Error Update: %s\n", err)
|
||||
// return err
|
||||
// }
|
||||
|
||||
log.Printf("======================== Update")
|
||||
utils.PrettyPrintJson(p)
|
||||
// log.Printf("======================== Update")
|
||||
// utils.PrettyPrintJson(p)
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
// 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 OnSubStart(c *fiber.Ctx) error {
|
||||
p := new(models.Update)
|
||||
if err := c.BodyParser(p); err != nil {
|
||||
log.Printf("Error SubStart: %s\n", err)
|
||||
return err
|
||||
}
|
||||
// return c.SendString("On_Update: " + string(c.Body()))
|
||||
// }
|
||||
|
||||
log.Printf("SubStart")
|
||||
utils.PrettyPrintJson(p)
|
||||
// func OnSubStart(c *fiber.Ctx) error {
|
||||
// p := new(models.Update)
|
||||
// if err := c.BodyParser(p); err != nil {
|
||||
// log.Printf("Error SubStart: %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)
|
||||
// }
|
||||
// }
|
||||
// log.Printf("SubStart")
|
||||
// utils.PrettyPrintJson(p)
|
||||
|
||||
return c.SendString("On_Substart: " + string(c.Body()))
|
||||
}
|
||||
// // 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_Substart: " + string(c.Body()))
|
||||
// }
|
||||
|
||||
func OnPubStart(c *fiber.Ctx) error {
|
||||
// ================================================================
|
||||
|
|
@ -115,8 +114,9 @@ func OnPubStart(c *fiber.Ctx) error {
|
|||
log.Printf("======================== Start StreamName %s, Transmission Key %s, PlayerKey %s, SessionId %s\n", p.StreamName, transmissionkey, playerkey, p.SessionId)
|
||||
|
||||
// Get the channel from the database
|
||||
channel := services.GetChannelByName(p.StreamName)
|
||||
log.Printf("======================== %v\n", channel)
|
||||
channel, currentTransmission := services.GetChannelByName(p.StreamName)
|
||||
|
||||
log.Printf("%v\n", currentTransmission)
|
||||
|
||||
// If the channel is not found, kick the session
|
||||
if channel.ID == 0 {
|
||||
|
|
@ -141,9 +141,6 @@ func OnPubStart(c *fiber.Ctx) error {
|
|||
|
||||
// Check if the channel has authorized time to transmit
|
||||
|
||||
// KickSession(p.StreamName, p.SessionId)
|
||||
// return fiber.ErrForbidden
|
||||
|
||||
services.AddTransmissionlog(p.StreamName, "Transmissão iniciada")
|
||||
return c.SendString("On_Pub_Start: " + string(c.Body()))
|
||||
}
|
||||
|
|
@ -156,7 +153,8 @@ func OnPubStop(c *fiber.Ctx) error {
|
|||
if err := c.BodyParser(p); err != nil {
|
||||
return err
|
||||
}
|
||||
log.Printf("======================== Stop Channel %s\n", p.StreamName)
|
||||
|
||||
services.AddTransmissionlog(p.StreamName, "Transmissão encerrada")
|
||||
return c.SendString("On_Pub_Stop: " + string(c.Body()))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -228,3 +228,9 @@ type TransmissionLog struct {
|
|||
func (TransmissionLog) TableName() string {
|
||||
return "transmissionlog"
|
||||
}
|
||||
|
||||
type CurrentTransmission struct {
|
||||
Channel string
|
||||
StartTime time.Time
|
||||
Limit time.Time
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,9 +23,9 @@ func Setup(app *fiber.App) {
|
|||
|
||||
// Webhooks
|
||||
app.Post("/on_server_start", controllers.ServerStart)
|
||||
app.Post("/on_rtmp_connect", controllers.OnRtmpConnect)
|
||||
app.Post("/on_update", controllers.OnUpdate)
|
||||
// app.Post("/on_rtmp_connect", controllers.OnRtmpConnect)
|
||||
// app.Post("/on_update", controllers.OnUpdate)
|
||||
app.Post("/on_pub_start", controllers.OnPubStart)
|
||||
app.Post("/on_pub_stop", controllers.OnPubStop)
|
||||
app.Post("/on_sub_start", controllers.OnSubStart)
|
||||
// app.Post("/on_sub_start", controllers.OnSubStart)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,12 +3,23 @@ package services
|
|||
import (
|
||||
"api/globals"
|
||||
"api/models"
|
||||
"time"
|
||||
)
|
||||
|
||||
func GetChannelByName(channelname string) models.Channel {
|
||||
var channel models.Channel
|
||||
func GetChannelByName(channelname string) (models.Channel, models.CurrentTransmission) {
|
||||
var (
|
||||
channel models.Channel
|
||||
plan models.Plan
|
||||
|
||||
globals.DB.Debug().Where("name = ?", channelname).First(&channel)
|
||||
currentTransmission models.CurrentTransmission
|
||||
)
|
||||
|
||||
return channel
|
||||
globals.DB.Where("name = ?", channelname).First(&channel)
|
||||
globals.DB.First(&plan, channel.PlanID)
|
||||
|
||||
currentTransmission.Channel = channel.Name
|
||||
currentTransmission.StartTime = time.Now()
|
||||
currentTransmission.Limit = currentTransmission.StartTime.Add(time.Duration(plan.DailyLimitTransmission) * time.Minute)
|
||||
|
||||
return channel, currentTransmission
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue