-
Notifications
You must be signed in to change notification settings - Fork 63
/
recording.go
159 lines (127 loc) · 4.53 KB
/
recording.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package controllers
import (
"github.com/gofiber/fiber/v2"
"github.com/mynaparrot/plugnmeet-protocol/plugnmeet"
"github.com/mynaparrot/plugnmeet-protocol/utils"
"github.com/mynaparrot/plugnmeet-server/pkg/models"
log "github.com/sirupsen/logrus"
"google.golang.org/protobuf/proto"
)
func HandleRecording(c *fiber.Ctx) error {
isAdmin := c.Locals("isAdmin")
roomId := c.Locals("roomId")
if isAdmin != true {
return utils.SendCommonProtobufResponse(c, false, "only admin can start recording")
}
if roomId == "" {
return utils.SendCommonProtobufResponse(c, false, "no roomId in token")
}
req := new(plugnmeet.RecordingReq)
m := models.NewRecorderModel()
err := proto.Unmarshal(c.Body(), req)
if err != nil {
return utils.SendCommonProtobufResponse(c, false, err.Error())
}
err = req.Validate()
if err != nil {
return utils.SendCommonProtobufResponse(c, false, err.Error())
}
// now need to check if meeting is running or not
rm := models.NewRoomModel()
room, _ := rm.GetRoomInfo("", req.Sid, 1)
if room.Id == 0 {
return utils.SendCommonProtobufResponse(c, false, "notifications.room-not-active")
}
if room.RoomId != roomId {
return utils.SendCommonProtobufResponse(c, false, "roomId in token mismatched")
}
if room.IsRecording == 1 && req.Task == plugnmeet.RecordingTasks_START_RECORDING {
return utils.SendCommonProtobufResponse(c, false, "notifications.recording-already-running")
} else if room.IsRecording == 0 && req.Task == plugnmeet.RecordingTasks_STOP_RECORDING {
return utils.SendCommonProtobufResponse(c, false, "notifications.recording-not-running")
}
if room.IsActiveRTMP == 1 && req.Task == plugnmeet.RecordingTasks_START_RTMP {
return utils.SendCommonProtobufResponse(c, false, "notifications.rtmp-already-running")
} else if room.IsActiveRTMP == 0 && req.Task == plugnmeet.RecordingTasks_STOP_RTMP {
return utils.SendCommonProtobufResponse(c, false, "notifications.rtmp-not-running")
}
req.RoomId = room.RoomId
req.RoomTableId = room.Id
err = m.SendMsgToRecorder(req)
if err != nil {
return utils.SendCommonProtobufResponse(c, false, err.Error())
}
return utils.SendCommonProtobufResponse(c, true, "success")
}
func HandleRTMP(c *fiber.Ctx) error {
isAdmin := c.Locals("isAdmin")
roomId := c.Locals("roomId")
if isAdmin != true {
return utils.SendCommonProtobufResponse(c, false, "only admin can start recording")
}
if roomId == "" {
return utils.SendCommonProtobufResponse(c, false, "no roomId in token")
}
// we can use same as RecordingReq
req := new(plugnmeet.RecordingReq)
m := models.NewRecorderModel()
err := proto.Unmarshal(c.Body(), req)
if err != nil {
return utils.SendCommonProtobufResponse(c, false, err.Error())
}
err = req.Validate()
if err != nil {
return utils.SendCommonProtobufResponse(c, false, err.Error())
}
if req.Task == plugnmeet.RecordingTasks_START_RTMP {
if req.RtmpUrl == nil {
return utils.SendCommonProtobufResponse(c, false, "rtmp url require")
} else if *req.RtmpUrl == "" {
return utils.SendCommonProtobufResponse(c, false, "rtmp url require")
}
}
// now need to check if meeting is running or not
rm := models.NewRoomModel()
room, _ := rm.GetRoomInfo("", req.Sid, 1)
if room.Id == 0 {
return utils.SendCommonProtobufResponse(c, false, "room isn't running")
}
if room.RoomId != roomId {
return utils.SendCommonProtobufResponse(c, false, "roomId in token mismatched")
}
if room.IsActiveRTMP == 1 && req.Task == plugnmeet.RecordingTasks_START_RTMP {
return utils.SendCommonProtobufResponse(c, false, "RTMP broadcasting already running")
} else if room.IsActiveRTMP == 0 && req.Task == plugnmeet.RecordingTasks_STOP_RTMP {
return utils.SendCommonProtobufResponse(c, false, "RTMP broadcasting not running")
}
req.RoomId = room.RoomId
req.RoomTableId = room.Id
err = m.SendMsgToRecorder(req)
if err != nil {
return utils.SendCommonProtobufResponse(c, false, err.Error())
}
return utils.SendCommonProtobufResponse(c, true, "success")
}
func HandleRecorderEvents(c *fiber.Ctx) error {
req := new(plugnmeet.RecorderToPlugNmeet)
m := models.NewRecordingModel()
err := proto.Unmarshal(c.Body(), req)
if err != nil {
log.Errorln(err)
return c.JSON(fiber.Map{
"status": false,
"msg": err.Error(),
})
}
if req.From == "recorder" {
rm := models.NewRoomModel()
roomInfo, _ := rm.GetRoomInfoByTableId(req.RoomTableId)
if roomInfo == nil {
return c.SendStatus(fiber.StatusNotFound)
}
req.RoomId = roomInfo.RoomId
req.RoomSid = roomInfo.Sid
m.HandleRecorderResp(req, roomInfo)
}
return c.SendStatus(fiber.StatusOK)
}