package voicechat import ( "context" "sync/atomic" "unsafe" "repositories.action2quare.com/ayo/gocommon" "repositories.action2quare.com/ayo/gocommon/logger" ) type JoinVoiceChatRequst struct { Gid string Mid string Service string Alias string } type LeaveVoiceChatRequst struct { Gid string Mid string Service string } type voiceChatConfig struct { EosClientId string `json:"eos_client_id"` EosClientSecret string `json:"eos_client_secret"` EosDeploymentId string `json:"eos_deployment_id"` } type voiceServiceImpl interface { joinVoiceChat(JoinVoiceChatRequst) map[string]any leaveVoiceChat(LeaveVoiceChatRequst) } var config voiceChatConfig type VoiceChatService struct { eosptr unsafe.Pointer } func (gv *VoiceChatService) Initialize(ctx context.Context) error { if err := gocommon.LoadConfig(&config); err != nil { return logger.ErrorWithCallStack(err) } if len(config.EosClientId) == 0 { logger.Println("eos voice chat is disabled. 'eos_client_id' is empty") } if len(config.EosClientSecret) == 0 { logger.Println("eos voice chat is disabled. 'eos_client_secret' is empty") } if len(config.EosDeploymentId) == 0 { logger.Println("eos voice chat is disabled. 'eos_deployment_id' is empty") } gv.eosptr = unsafe.Pointer(&eosauth{}) if len(config.EosClientId) > 0 && len(config.EosClientSecret) > 0 && len(config.EosDeploymentId) > 0 { go eosTokenRefresh(&gv.eosptr, ctx) } return nil } func (gv *VoiceChatService) eos() voiceServiceImpl { ptr := atomic.LoadPointer(&gv.eosptr) return (*eosauth)(ptr) } func (gv *VoiceChatService) JoinVoiceChat(req JoinVoiceChatRequst) map[string]any { switch req.Service { case "eos": return gv.eos().joinVoiceChat(req) } return nil } func (gv *VoiceChatService) LeaveVoiceChat(req LeaveVoiceChatRequst) { switch req.Service { case "eos": gv.eos().leaveVoiceChat(req) } }