/
data_message.go
47 lines (38 loc) · 1.28 KB
/
data_message.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
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"
"google.golang.org/protobuf/proto"
)
func HandleDataMessage(c *fiber.Ctx) error {
roomId := c.Locals("roomId")
requestedUserId := c.Locals("requestedUserId")
isAdmin := c.Locals("isAdmin")
if roomId == "" {
return utils.SendCommonProtobufResponse(c, false, "no roomId in token")
}
req := new(plugnmeet.DataMessageReq)
err := proto.Unmarshal(c.Body(), req)
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.RoomId, req.RoomSid, 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")
}
req.RequestedUserId = requestedUserId.(string)
req.IsAdmin = isAdmin.(bool)
m := models.NewDataMessageModel()
err = m.SendDataMessage(req)
if err != nil {
return utils.SendCommonProtobufResponse(c, false, err.Error())
}
return utils.SendCommonProtobufResponse(c, true, "success")
}