You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
3.2 KiB

package callback
import (
"encoding/json"
"github.com/gin-gonic/gin"
"io/ioutil"
live2 "live/app/logic/live"
"live/app/model/live"
"log"
"net/url"
"strconv"
)
type Live struct {
}
func (l *Live) Push(c *gin.Context) {
log.Println("push:start")
log.Println("data:", c.Request.RequestURI)
log.Println("data:", c.Request.PostForm)
all, err := ioutil.ReadAll(c.Request.Body)
log.Println(string(all), err)
log.Println("push:end")
}
func (l *Live) Cutout(c *gin.Context) {
log.Println("cutout:start")
log.Println("data:", c.Request.RequestURI)
log.Println("data:", c.Request.PostForm)
all, err := ioutil.ReadAll(c.Request.Body)
log.Println(string(all), err)
log.Println("cutout:end")
}
type argsTranscribe struct {
App string `json:"app"`
Appid int64 `json:"appid"`
Appname string `json:"appname"`
ChannelID string `json:"channel_id"`
Duration int64 `json:"duration"`
EndTime int64 `json:"end_time"`
EndTimeUsec int64 `json:"end_time_usec"`
EventType int64 `json:"event_type"`
FileFormat string `json:"file_format"`
FileID string `json:"file_id"`
FileSize int64 `json:"file_size"`
MediaStartTime int64 `json:"media_start_time"`
RecordBps int64 `json:"record_bps"`
RecordFileID string `json:"record_file_id"`
Sign string `json:"sign"`
StartTime int64 `json:"start_time"`
StartTimeUsec int64 `json:"start_time_usec"`
StreamID string `json:"stream_id"`
StreamParam string `json:"stream_param"`
T int64 `json:"t"`
TaskID string `json:"task_id"`
VideoID string `json:"video_id"`
VideoURL string `json:"video_url"`
}
func (l *Live) Transcribe(c *gin.Context) {
data, _ := ioutil.ReadAll(c.Request.Body)
log.Println("录播完成:", string(data))
args := argsTranscribe{}
if err := json.Unmarshal(data, &args); err != nil {
log.Println("json序列化失败,err:", err)
return
}
query, err := url.ParseQuery(args.StreamParam)
if err != nil {
log.Println("参数序列化失败,err:", err)
return
}
liveItemId, _ := strconv.ParseUint(query.Get("liveItemId"), 10, 64)
liveItemModel := &live.LiveItem{}
liveItemInfo := liveItemModel.FindById(uint(liveItemId))
if liveItemInfo.Id <= 0 {
log.Println("直播场次获取失败,err:", err)
return
}
liveItemModel.UpdateById(liveItemInfo.Id, map[string]interface{}{
"file_id": args.FileID,
"video_url": args.VideoURL,
})
if liveItemInfo.Status == live.LIVE_STATUS_ing {
// 尚未结束直播
if err := live2.LiveLogic.Stop(liveItemInfo.UserId, liveItemInfo.Id); err != nil {
log.Println("直播结束失败err:", err)
return
}
}
}
func (l *Live) ScreenShot(c *gin.Context) {
log.Println("screenshot:start")
log.Println("data:", c.Request.RequestURI)
log.Println("data:", c.Request.PostForm)
all, err := ioutil.ReadAll(c.Request.Body)
log.Println(string(all), err)
log.Println("screenshot:end")
}
func (l *Live) Identify(c *gin.Context) {
log.Println("identify:start")
log.Println("data:", c.Request.RequestURI)
log.Println("data:", c.Request.PostForm)
all, err := ioutil.ReadAll(c.Request.Body)
log.Println(string(all), err)
log.Println("identify:end")
}