fix: change the way goldgorilla reconnection to greatape was handled
parent
e85a01b809
commit
2261bf55f4
37
app.go
37
app.go
|
@ -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())
|
||||
}
|
||||
}
|
||||
startRejoinCH := make(chan bool, 2)
|
||||
a.conf = &models.ConfigModel{
|
||||
LogjamBaseUrl: logjamBaseUrl + "/auxiliary-node",
|
||||
TargetRoom: targetRoom,
|
||||
|
@ -43,6 +44,7 @@ func (a *App) Init(srcListenAddr string, svcAddr string, logjamBaseUrl string, t
|
|||
ICEServers: iceServers,
|
||||
ICETCPMUXListenPort: iceTCPMUXListenPort,
|
||||
CustomICEHostCandidateIP: customICEHostCandidateIP,
|
||||
StartRejoinCH: &startRejoinCH,
|
||||
}
|
||||
roomRepo := repositories.NewRoomRepository(a.conf)
|
||||
a.router = &routers.Router{}
|
||||
|
@ -63,7 +65,9 @@ func (a *App) Init(srcListenAddr string, svcAddr string, logjamBaseUrl string, t
|
|||
|
||||
func (a *App) Run() {
|
||||
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})
|
||||
body := bytes.NewReader(buffer)
|
||||
c := &http.Client{
|
||||
|
@ -73,13 +77,40 @@ func (a *App) Run() {
|
|||
if err != nil {
|
||||
println(err.Error())
|
||||
time.Sleep(4 * time.Second)
|
||||
goto start
|
||||
*a.conf.StartRejoinCH <- true
|
||||
continue
|
||||
}
|
||||
if res.StatusCode > 204 {
|
||||
resbody, _ := io.ReadAll(res.Body)
|
||||
println("get /join "+res.Status, string(resbody))
|
||||
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)
|
||||
|
|
|
@ -9,4 +9,5 @@ type ConfigModel struct {
|
|||
ICETCPMUXListenPort uint `json:"ice_tcpmux_listenPort"`
|
||||
CustomICEHostCandidateIP string `json:"customICEHostCandidateIP"`
|
||||
ICEServers []webrtc.ICEServer `json:"iceServers"`
|
||||
StartRejoinCH *chan bool
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ func (err BigError) Meta() any {
|
|||
return err.metaData
|
||||
}
|
||||
|
||||
func NewError(msg string, errCode int, meta any) BigError {
|
||||
func NewError(msg string, errCode int, meta any) error {
|
||||
if meta == nil {
|
||||
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 {
|
||||
meta = err
|
||||
}
|
||||
|
|
|
@ -209,28 +209,11 @@ func (r *RoomRepository) CreatePeer(roomId string, id uint64, canPublish bool, i
|
|||
}
|
||||
|
||||
func (r *RoomRepository) onCallerDisconnected(roomId string) {
|
||||
reqModel := struct {
|
||||
RoomId string `json:"roomId"`
|
||||
}{
|
||||
RoomId: roomId,
|
||||
}
|
||||
serializedReqBody, err := json.Marshal(reqModel)
|
||||
if err != nil {
|
||||
if err := r.ResetRoom(roomId); err != nil {
|
||||
println(err.Error())
|
||||
return
|
||||
}
|
||||
if err = r.ResetRoom(roomId); err != nil {
|
||||
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)
|
||||
}
|
||||
*r.conf.StartRejoinCH <- false
|
||||
}
|
||||
|
||||
func (r *RoomRepository) onPeerICECandidate(roomId string, id uint64, ic *webrtc.ICECandidate) {
|
||||
|
|
Loading…
Reference in New Issue