diff --git a/voicechat/eos_impl.go b/voicechat/eos_impl.go index 91e8422..18fd78d 100644 --- a/voicechat/eos_impl.go +++ b/voicechat/eos_impl.go @@ -78,7 +78,7 @@ type eosRoomParticipants struct { 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 accessToken := gv.AccessToken if len(accessToken) == 0 { @@ -125,7 +125,7 @@ func (gv *eosauth) joinVoiceChat(data joinVoiceChatRequst) map[string]any { 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) accessToken := gv.AccessToken diff --git a/voicechat/voice_chat.go b/voicechat/voice_chat.go index de2e077..94abd0f 100644 --- a/voicechat/voice_chat.go +++ b/voicechat/voice_chat.go @@ -2,8 +2,6 @@ package voicechat import ( "context" - "encoding/gob" - "net/http" "sync/atomic" "unsafe" @@ -11,24 +9,19 @@ import ( "repositories.action2quare.com/ayo/gocommon/logger" ) -type joinVoiceChatRequst struct { +type JoinVoiceChatRequst struct { Gid string Mid string Service string Alias string } -type leaveVoiceChatRequst struct { +type LeaveVoiceChatRequst struct { Gid string Mid string Service string } -func init() { - gob.Register(joinVoiceChatRequst{}) - gob.Register(leaveVoiceChatRequst{}) -} - type voiceChatConfig struct { EosClientId string `json:"eos_client_id"` EosClientSecret string `json:"eos_client_secret"` @@ -36,8 +29,8 @@ type voiceChatConfig struct { } type voiceServiceImpl interface { - joinVoiceChat(joinVoiceChatRequst) map[string]any - leaveVoiceChat(leaveVoiceChatRequst) + joinVoiceChat(JoinVoiceChatRequst) map[string]any + leaveVoiceChat(LeaveVoiceChatRequst) } var config voiceChatConfig @@ -74,32 +67,18 @@ func (gv *VoiceChatService) eos() voiceServiceImpl { return (*eosauth)(ptr) } -func (gv *VoiceChatService) JoinVoiceChat(w http.ResponseWriter, r *http.Request) { - var data joinVoiceChatRequst - - 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) JoinVoiceChat(req JoinVoiceChatRequst) map[string]any { + switch req.Service { case "eos": - result := gv.eos().joinVoiceChat(data) - gocommon.MakeEncoder(w, r).Encode(result) + return gv.eos().joinVoiceChat(req) } + + return nil } -func (gv *VoiceChatService) LeaveVoiceChat(w http.ResponseWriter, r *http.Request) { - 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": - gv.eos().leaveVoiceChat(data) + gv.eos().leaveVoiceChat(req) } }