fix: change the way goldgorilla reconnection to greatape was handled
parent
e85a01b809
commit
2261bf55f4
65
app.go
65
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())
|
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,23 +65,52 @@ 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
|
||||||
buffer, _ := json.Marshal(map[string]any{"roomId": a.conf.TargetRoom, "svcAddr": a.conf.ServiceAddress})
|
for simplyJoin := range *a.conf.StartRejoinCH {
|
||||||
body := bytes.NewReader(buffer)
|
if simplyJoin {
|
||||||
c := &http.Client{
|
buffer, _ := json.Marshal(map[string]any{"roomId": a.conf.TargetRoom, "svcAddr": a.conf.ServiceAddress})
|
||||||
Timeout: 8 * time.Second,
|
body := bytes.NewReader(buffer)
|
||||||
}
|
c := &http.Client{
|
||||||
res, err := c.Post(a.conf.LogjamBaseUrl+"/join", "application/json", body)
|
Timeout: 8 * time.Second,
|
||||||
if err != nil {
|
}
|
||||||
println(err.Error())
|
res, err := c.Post(a.conf.LogjamBaseUrl+"/join", "application/json", body)
|
||||||
time.Sleep(4 * time.Second)
|
if err != nil {
|
||||||
goto start
|
println(err.Error())
|
||||||
}
|
time.Sleep(4 * time.Second)
|
||||||
if res.StatusCode > 204 {
|
*a.conf.StartRejoinCH <- true
|
||||||
resbody, _ := io.ReadAll(res.Body)
|
continue
|
||||||
println("get /join "+res.Status, string(resbody))
|
}
|
||||||
time.Sleep(4 * time.Second)
|
if res.StatusCode > 204 {
|
||||||
goto start
|
resbody, _ := io.ReadAll(res.Body)
|
||||||
|
println("get /join "+res.Status, string(resbody))
|
||||||
|
time.Sleep(4 * time.Second)
|
||||||
|
*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)
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
Loading…
Reference in New Issue