From 0c1c30d6dadf323f96779e76d73ecef0ca21ee37 Mon Sep 17 00:00:00 2001 From: kanade <3136520963@qq.com> Date: Mon, 2 Nov 2020 14:18:16 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9B=B4=E6=92=AD=E7=9A=84=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/callback/live.go | 127 ++++++++++++++++++++++++++------ app/logic/live/im.go | 1 + app/logic/live/live.go | 13 ++-- app/model/live/liveItem.go | 4 +- app/task/live.go | 17 ++++- 5 files changed, 127 insertions(+), 35 deletions(-) diff --git a/app/controller/callback/live.go b/app/controller/callback/live.go index 619dc2d..f40fdfc 100644 --- a/app/controller/callback/live.go +++ b/app/controller/callback/live.go @@ -14,22 +14,103 @@ import ( type Live struct { } +type argsPush struct { + App string `json:"app"` + Appid int64 `json:"appid"` + Appname string `json:"appname"` + ChannelID string `json:"channel_id"` + Errcode int64 `json:"errcode"` + Errmsg string `json:"errmsg"` + EventTime int64 `json:"event_time"` + EventType int64 `json:"event_type"` + Height int64 `json:"height"` + IdcID int64 `json:"idc_id"` + Node string `json:"node"` + Sequence string `json:"sequence"` + SetID int64 `json:"set_id"` + Sign string `json:"sign"` + StreamID string `json:"stream_id"` + StreamParam string `json:"stream_param"` + T int64 `json:"t"` + UserIP string `json:"user_ip"` + Width int64 `json:"width"` +} + 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") + data, _ := ioutil.ReadAll(c.Request.Body) + log.Println("直播开始/继续:", string(data)) + //args := argsPush{} + //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 + //} + //live2.ImLogic.SendLiveGroupMessage(liveItemInfo.RoomId, live2.LiveGroupMsgTypePlay, gin.H{ + // "type": "play", + // "time": time.Now().UnixNano(), + //}) +} + +type argsCutout struct { + App string `json:"app"` + Appid int64 `json:"appid"` + Appname string `json:"appname"` + ChannelID string `json:"channel_id"` + Errcode int64 `json:"errcode"` + Errmsg string `json:"errmsg"` + EventTime int64 `json:"event_time"` + EventType int64 `json:"event_type"` + Height int64 `json:"height"` + IdcID int64 `json:"idc_id"` + Node string `json:"node"` + PushDuration string `json:"push_duration"` + Sequence string `json:"sequence"` + SetID int64 `json:"set_id"` + Sign string `json:"sign"` + StreamID string `json:"stream_id"` + StreamParam string `json:"stream_param"` + T int64 `json:"t"` + UserIP string `json:"user_ip"` + Width int64 `json:"width"` } 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") + data, _ := ioutil.ReadAll(c.Request.Body) + log.Println("直播暂停:", string(data)) + //args := argsCutout{} + //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 + //} + //live2.ImLogic.SendLiveGroupMessage(liveItemInfo.RoomId, live2.LiveGroupMsgTypePlay, gin.H{ + // "type": "pause", + // "time": time.Now().UnixNano(), + //}) } type argsTranscribe struct { @@ -79,10 +160,18 @@ func (l *Live) Transcribe(c *gin.Context) { log.Println("直播场次获取失败,err:", err) return } - liveItemModel.UpdateById(liveItemInfo.Id, map[string]interface{}{ - "file_id": args.FileID, - "video_url": args.VideoURL, - }) + if liveItemInfo.TranscribeType == live.LIVE_Transcribe_Type_ing { + liveItemModel.UpdateById(liveItemInfo.Id, map[string]interface{}{ + "file_id": args.FileID, + "video_url": args.VideoURL, + "transcribe_type": live.LIVE_Transcribe_Type_finish, + }) + } else { + 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 { @@ -93,12 +182,6 @@ func (l *Live) Transcribe(c *gin.Context) { } 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) { diff --git a/app/logic/live/im.go b/app/logic/live/im.go index 1cf6642..67404a5 100644 --- a/app/logic/live/im.go +++ b/app/logic/live/im.go @@ -21,6 +21,7 @@ const ( LiveGroupMsgTypeBuyGoods = "BuyGoods" LiveGroupMsgTypeNotice = "Notice" LiveGroupMsgTypePraise = "Praise" + LiveGroupMsgTypePlay = "Play" ) var ImLogic = &im{} diff --git a/app/logic/live/live.go b/app/logic/live/live.go index 3773c8f..8ce813f 100644 --- a/app/logic/live/live.go +++ b/app/logic/live/live.go @@ -152,13 +152,6 @@ func (l *live) Stop(userId, liveItemId uint) error { liveDataModel := &live2.LiveData{} liveData := liveDataModel.GetByLiveItemId(liveItemId) - // 解散直播群 - liveRoom := live2.LiveRoom{} - userLiveRoom := liveRoom.GetLiveById(liveItem.RoomId) - if err := tencent.Im.DelLiveGroup(userLiveRoom.GroupId); err != nil { - log.Println(err) - } - return liveItemModel.Transaction(func(tx *gorm.DB) error { // 完成直播 liveItemModel.SetDb(tx) @@ -182,6 +175,12 @@ func (l *live) Stop(userId, liveItemId uint) error { "praise": liveData.Praise, "look": liveData.Look, }) + // 解散直播群 + liveRoom := live2.LiveRoom{} + userLiveRoom := liveRoom.GetLiveById(liveItem.RoomId) + if err := tencent.Im.DelLiveGroup(userLiveRoom.GroupId); err != nil { + log.Println(err) + } return nil }) } diff --git a/app/model/live/liveItem.go b/app/model/live/liveItem.go index c95bace..76e37a3 100644 --- a/app/model/live/liveItem.go +++ b/app/model/live/liveItem.go @@ -76,13 +76,13 @@ func (l *LiveItem) GetUserListFinish(userId uint, start, limit int) (result []Li // @Title 当前直播场次信息 func (l *LiveItem) GetUserListTotal(userId uint) (result int64) { - l.GetDb().Model(&LiveItem{}).Where("user_id = ?", userId).Count(&result) + l.GetDb().Model(&LiveItem{}).Where("user_id = ? and (`status` = ? or `transcribe_type` = ?) ", userId, LIVE_STATUS_finish, LIVE_Transcribe_Type_finish).Count(&result) return } // @Title 当前直播场次信息 func (l *LiveItem) GetUserList(userId uint, start, limit int) (result []LiveItem) { - l.GetDb().Model(&LiveItem{}).Order("id desc").Find(&result, "user_id = ?", userId) + l.GetDb().Model(&LiveItem{}).Order("id desc").Offset(start).Limit(limit).Find(&result, "user_id = ? and (`status` = ? or `transcribe_type` = ?) ", userId, LIVE_STATUS_finish, LIVE_Transcribe_Type_finish) return } diff --git a/app/task/live.go b/app/task/live.go index 685b019..f3e15de 100644 --- a/app/task/live.go +++ b/app/task/live.go @@ -44,6 +44,7 @@ func (live *Live) Run() { case "NewFileUpload": live.upSuc(event) } + log.Println(event) } request1.EventHandles = common.StringPtrs(handle) client.ConfirmEvents(request1) @@ -72,10 +73,18 @@ func (live *Live) record(event *vod.EventContent) { log.Println("直播场次获取失败,err:", liveItemId) return } - liveItemModel.UpdateById(liveItemInfo.Id, map[string]interface{}{ - "file_id": event.FileUploadEvent.FileId, - "video_url": event.FileUploadEvent.MediaBasicInfo.MediaUrl, - }) + if liveItemInfo.TranscribeType == live3.LIVE_Transcribe_Type_ing { + liveItemModel.UpdateById(liveItemInfo.Id, map[string]interface{}{ + "file_id": event.FileUploadEvent.FileId, + "video_url": event.FileUploadEvent.MediaBasicInfo.MediaUrl, + "transcribe_type": live3.LIVE_Transcribe_Type_finish, + }) + } else { + liveItemModel.UpdateById(liveItemInfo.Id, map[string]interface{}{ + "file_id": event.FileUploadEvent.FileId, + "video_url": event.FileUploadEvent.MediaBasicInfo.MediaUrl, + }) + } if liveItemInfo.Status == live3.LIVE_STATUS_ing { // 尚未结束直播 if err := live2.LiveLogic.Stop(liveItemInfo.UserId, liveItemInfo.Id); err != nil {