http request대신 직접 호출

This commit is contained in:
2024-01-08 21:41:53 +09:00
parent e919473fa2
commit e03bf6e199
2 changed files with 14 additions and 35 deletions

View File

@ -78,7 +78,7 @@ type eosRoomParticipants struct {
Participants []eosRoomParticipantRequests `json:"participants"` Participants []eosRoomParticipantRequests `json:"participants"`
} }
func (gv *eosauth) joinVoiceChat(data joinVoiceChatRequst) map[string]any { func (gv *eosauth) joinVoiceChat(data JoinVoiceChatRequst) map[string]any {
// https://dev.epicgames.com/docs/web-api-ref/voice-web-api // https://dev.epicgames.com/docs/web-api-ref/voice-web-api
accessToken := gv.AccessToken accessToken := gv.AccessToken
if len(accessToken) == 0 { if len(accessToken) == 0 {
@ -125,7 +125,7 @@ func (gv *eosauth) joinVoiceChat(data joinVoiceChatRequst) map[string]any {
return result return result
} }
func (gv *eosauth) leaveVoiceChat(data leaveVoiceChatRequst) { func (gv *eosauth) leaveVoiceChat(data LeaveVoiceChatRequst) {
voiceendpoint := fmt.Sprintf("https://api.epicgames.dev/rtc/v1/%s/room/%s/participants/%s", config.EosDeploymentId, data.Gid, data.Mid) voiceendpoint := fmt.Sprintf("https://api.epicgames.dev/rtc/v1/%s/room/%s/participants/%s", config.EosDeploymentId, data.Gid, data.Mid)
accessToken := gv.AccessToken accessToken := gv.AccessToken

View File

@ -2,8 +2,6 @@ package voicechat
import ( import (
"context" "context"
"encoding/gob"
"net/http"
"sync/atomic" "sync/atomic"
"unsafe" "unsafe"
@ -11,24 +9,19 @@ import (
"repositories.action2quare.com/ayo/gocommon/logger" "repositories.action2quare.com/ayo/gocommon/logger"
) )
type joinVoiceChatRequst struct { type JoinVoiceChatRequst struct {
Gid string Gid string
Mid string Mid string
Service string Service string
Alias string Alias string
} }
type leaveVoiceChatRequst struct { type LeaveVoiceChatRequst struct {
Gid string Gid string
Mid string Mid string
Service string Service string
} }
func init() {
gob.Register(joinVoiceChatRequst{})
gob.Register(leaveVoiceChatRequst{})
}
type voiceChatConfig struct { type voiceChatConfig struct {
EosClientId string `json:"eos_client_id"` EosClientId string `json:"eos_client_id"`
EosClientSecret string `json:"eos_client_secret"` EosClientSecret string `json:"eos_client_secret"`
@ -36,8 +29,8 @@ type voiceChatConfig struct {
} }
type voiceServiceImpl interface { type voiceServiceImpl interface {
joinVoiceChat(joinVoiceChatRequst) map[string]any joinVoiceChat(JoinVoiceChatRequst) map[string]any
leaveVoiceChat(leaveVoiceChatRequst) leaveVoiceChat(LeaveVoiceChatRequst)
} }
var config voiceChatConfig var config voiceChatConfig
@ -74,32 +67,18 @@ func (gv *VoiceChatService) eos() voiceServiceImpl {
return (*eosauth)(ptr) return (*eosauth)(ptr)
} }
func (gv *VoiceChatService) JoinVoiceChat(w http.ResponseWriter, r *http.Request) { func (gv *VoiceChatService) JoinVoiceChat(req JoinVoiceChatRequst) map[string]any {
var data joinVoiceChatRequst switch req.Service {
if err := gocommon.MakeDecoder(r).Decode(&data); err != nil {
logger.Println("JoinVoiceChat failed. DecodeGob returns err :", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
switch data.Service {
case "eos": case "eos":
result := gv.eos().joinVoiceChat(data) return gv.eos().joinVoiceChat(req)
gocommon.MakeEncoder(w, r).Encode(result)
}
} }
func (gv *VoiceChatService) LeaveVoiceChat(w http.ResponseWriter, r *http.Request) { return nil
var data leaveVoiceChatRequst
if err := gocommon.MakeDecoder(r).Decode(&data); err != nil {
logger.Println("JoinVoiceChat failed. DecodeGob returns err :", err)
w.WriteHeader(http.StatusInternalServerError)
return
} }
switch data.Service { func (gv *VoiceChatService) LeaveVoiceChat(req LeaveVoiceChatRequst) {
switch req.Service {
case "eos": case "eos":
gv.eos().leaveVoiceChat(data) gv.eos().leaveVoiceChat(req)
} }
} }