fix: change the way goldgorilla reconnection to greatape was handled

pull/1/head
Benyamin Azarkhazin 2023-10-16 17:38:11 +03:30
parent e85a01b809
commit 2261bf55f4
Signed by: benyamin
GPG Key ID: 3AE44F5623C70269
4 changed files with 53 additions and 38 deletions

37
app.go
View File

@ -36,6 +36,7 @@ func (a *App) Init(srcListenAddr string, svcAddr string, logjamBaseUrl string, t
panic("[E] can't parse ice.servers.json: " + err.Error()) panic("[E] can't parse ice.servers.json: " + err.Error())
} }
} }
startRejoinCH := make(chan bool, 2)
a.conf = &models.ConfigModel{ a.conf = &models.ConfigModel{
LogjamBaseUrl: logjamBaseUrl + "/auxiliary-node", LogjamBaseUrl: logjamBaseUrl + "/auxiliary-node",
TargetRoom: targetRoom, TargetRoom: targetRoom,
@ -43,6 +44,7 @@ func (a *App) Init(srcListenAddr string, svcAddr string, logjamBaseUrl string, t
ICEServers: iceServers, ICEServers: iceServers,
ICETCPMUXListenPort: iceTCPMUXListenPort, ICETCPMUXListenPort: iceTCPMUXListenPort,
CustomICEHostCandidateIP: customICEHostCandidateIP, CustomICEHostCandidateIP: customICEHostCandidateIP,
StartRejoinCH: &startRejoinCH,
} }
roomRepo := repositories.NewRoomRepository(a.conf) roomRepo := repositories.NewRoomRepository(a.conf)
a.router = &routers.Router{} a.router = &routers.Router{}
@ -63,7 +65,9 @@ func (a *App) Init(srcListenAddr string, svcAddr string, logjamBaseUrl string, t
func (a *App) Run() { func (a *App) Run() {
go func() { go func() {
start: *a.conf.StartRejoinCH <- true
for simplyJoin := range *a.conf.StartRejoinCH {
if simplyJoin {
buffer, _ := json.Marshal(map[string]any{"roomId": a.conf.TargetRoom, "svcAddr": a.conf.ServiceAddress}) buffer, _ := json.Marshal(map[string]any{"roomId": a.conf.TargetRoom, "svcAddr": a.conf.ServiceAddress})
body := bytes.NewReader(buffer) body := bytes.NewReader(buffer)
c := &http.Client{ c := &http.Client{
@ -73,13 +77,40 @@ func (a *App) Run() {
if err != nil { if err != nil {
println(err.Error()) println(err.Error())
time.Sleep(4 * time.Second) time.Sleep(4 * time.Second)
goto start *a.conf.StartRejoinCH <- true
continue
} }
if res.StatusCode > 204 { if res.StatusCode > 204 {
resbody, _ := io.ReadAll(res.Body) resbody, _ := io.ReadAll(res.Body)
println("get /join "+res.Status, string(resbody)) println("get /join "+res.Status, string(resbody))
time.Sleep(4 * time.Second) time.Sleep(4 * time.Second)
goto start *a.conf.StartRejoinCH <- true
continue
}
} else {
reqModel := struct {
RoomId string `json:"roomId"`
}{
RoomId: a.conf.TargetRoom,
}
serializedReqBody, err := json.Marshal(reqModel)
if err != nil {
println(err.Error())
*a.conf.StartRejoinCH <- true
continue
}
resp, err := http.Post(a.conf.LogjamBaseUrl+"/rejoin", "application/json", bytes.NewReader(serializedReqBody))
if err != nil {
println(err.Error())
*a.conf.StartRejoinCH <- true
continue
}
if resp.StatusCode > 204 {
println("/rejoin", resp.Status)
*a.conf.StartRejoinCH <- true
}
}
} }
}() }()
err := a.router.Serve(a.src) err := a.router.Serve(a.src)

View File

@ -9,4 +9,5 @@ type ConfigModel struct {
ICETCPMUXListenPort uint `json:"ice_tcpmux_listenPort"` ICETCPMUXListenPort uint `json:"ice_tcpmux_listenPort"`
CustomICEHostCandidateIP string `json:"customICEHostCandidateIP"` CustomICEHostCandidateIP string `json:"customICEHostCandidateIP"`
ICEServers []webrtc.ICEServer `json:"iceServers"` ICEServers []webrtc.ICEServer `json:"iceServers"`
StartRejoinCH *chan bool
} }

View File

@ -18,7 +18,7 @@ func (err BigError) Meta() any {
return err.metaData return err.metaData
} }
func NewError(msg string, errCode int, meta any) BigError { func NewError(msg string, errCode int, meta any) error {
if meta == nil { if meta == nil {
meta = struct { meta = struct {
}{} }{}
@ -30,7 +30,7 @@ func NewError(msg string, errCode int, meta any) BigError {
} }
} }
func (BigError) FromErr(err error, errCode int, meta any) BigError { func (BigError) FromErr(err error, errCode int, meta any) error {
if meta == nil { if meta == nil {
meta = err meta = err
} }

View File

@ -209,28 +209,11 @@ func (r *RoomRepository) CreatePeer(roomId string, id uint64, canPublish bool, i
} }
func (r *RoomRepository) onCallerDisconnected(roomId string) { func (r *RoomRepository) onCallerDisconnected(roomId string) {
reqModel := struct { if err := r.ResetRoom(roomId); err != nil {
RoomId string `json:"roomId"`
}{
RoomId: roomId,
}
serializedReqBody, err := json.Marshal(reqModel)
if err != nil {
println(err.Error()) println(err.Error())
return return
} }
if err = r.ResetRoom(roomId); err != nil { *r.conf.StartRejoinCH <- false
println(err.Error())
return
}
resp, err := http.Post(r.conf.LogjamBaseUrl+"/rejoin", "application/json", bytes.NewReader(serializedReqBody))
if err != nil {
println(err.Error())
return
}
if resp.StatusCode > 204 {
println("/rejoin", resp.Status)
}
} }
func (r *RoomRepository) onPeerICECandidate(roomId string, id uint64, ic *webrtc.ICECandidate) { func (r *RoomRepository) onPeerICECandidate(roomId string, id uint64, ic *webrtc.ICECandidate) {