-
Notifications
You must be signed in to change notification settings - Fork 63
/
speech_services.go
97 lines (79 loc) · 2.71 KB
/
speech_services.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
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 HandleSpeechToTextTranslationServiceStatus(c *fiber.Ctx) error {
isAdmin := c.Locals("isAdmin")
roomId := c.Locals("roomId")
if isAdmin != true {
return utils.SendCommonProtobufResponse(c, false, "only admin can perform this task")
}
req := new(plugnmeet.SpeechToTextTranslationReq)
err := proto.Unmarshal(c.Body(), req)
if err != nil {
return utils.SendCommonProtobufResponse(c, false, err.Error())
}
req.RoomId = roomId.(string)
m := models.NewSpeechServices()
err = m.SpeechToTextTranslationServiceStatus(req)
if err != nil {
return utils.SendCommonProtobufResponse(c, false, err.Error())
}
return utils.SendCommonProtobufResponse(c, true, "success")
}
func HandleGenerateAzureToken(c *fiber.Ctx) error {
roomId := c.Locals("roomId")
requestedUserId := c.Locals("requestedUserId")
req := new(plugnmeet.GenerateAzureTokenReq)
err := proto.Unmarshal(c.Body(), req)
if err != nil {
return utils.SendCommonProtobufResponse(c, false, err.Error())
}
req.RoomId = roomId.(string)
m := models.NewSpeechServices()
err = m.GenerateAzureToken(req, requestedUserId.(string))
if err != nil {
return utils.SendCommonProtobufResponse(c, false, err.Error())
}
return utils.SendCommonProtobufResponse(c, true, "success")
}
func HandleSpeechServiceUserStatus(c *fiber.Ctx) error {
roomId := c.Locals("roomId")
requestedUserId := c.Locals("requestedUserId")
req := new(plugnmeet.SpeechServiceUserStatusReq)
err := proto.Unmarshal(c.Body(), req)
if err != nil {
return utils.SendCommonProtobufResponse(c, false, err.Error())
}
if req.KeyId == "" {
return utils.SendCommonProtobufResponse(c, false, "key_id required")
}
req.RoomId = roomId.(string)
req.UserId = requestedUserId.(string)
m := models.NewSpeechServices()
err = m.SpeechServiceUserStatus(req)
if err != nil {
return utils.SendCommonProtobufResponse(c, false, err.Error())
}
return utils.SendCommonProtobufResponse(c, true, "success")
}
func HandleRenewAzureToken(c *fiber.Ctx) error {
roomId := c.Locals("roomId")
requestedUserId := c.Locals("requestedUserId")
req := new(plugnmeet.AzureTokenRenewReq)
err := proto.Unmarshal(c.Body(), req)
if err != nil {
return utils.SendCommonProtobufResponse(c, false, err.Error())
}
req.RoomId = roomId.(string)
m := models.NewSpeechServices()
err = m.RenewAzureToken(req, requestedUserId.(string))
if err != nil {
return utils.SendCommonProtobufResponse(c, false, err.Error())
}
return utils.SendCommonProtobufResponse(c, true, "success")
}