retry failed ICE for 3 times
parent
2366c32298
commit
d4281c3265
|
@ -3,13 +3,15 @@ package controllers
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/gin-gonic/gin"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
"sourcecode.social/greatape/goldgorilla/models"
|
"sourcecode.social/greatape/goldgorilla/models"
|
||||||
"sourcecode.social/greatape/goldgorilla/models/dto"
|
"sourcecode.social/greatape/goldgorilla/models/dto"
|
||||||
"sourcecode.social/greatape/goldgorilla/repositories"
|
"sourcecode.social/greatape/goldgorilla/repositories"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type RoomController struct {
|
type RoomController struct {
|
||||||
|
@ -43,20 +45,91 @@ func (c *RoomController) CreatePeer(ctx *gin.Context) {
|
||||||
c.helper.Response(ctx, struct{}{}, http.StatusNoContent)
|
c.helper.Response(ctx, struct{}{}, http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *RoomController) AddICECandidate(ctx *gin.Context) {
|
func (c *RoomController) RetryAddICECandidate(ctx *gin.Context, tries int) {
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
tries++
|
||||||
|
fmt.Println("----RetryAddICECandidate----")
|
||||||
var reqModel dto.AddPeerICECandidateReqModel
|
var reqModel dto.AddPeerICECandidateReqModel
|
||||||
badReqSt := 400
|
badReqSt := 400
|
||||||
if err := ctx.ShouldBindJSON(&reqModel); c.helper.HandleIfErr(ctx, err, &badReqSt) {
|
err1 := ctx.ShouldBindJSON(&reqModel)
|
||||||
|
// if err1 != nil && tries < 3 {
|
||||||
|
// // var reqGlobal interface{}
|
||||||
|
|
||||||
|
// // err2 := ctx.ShouldBindJSON(&reqGlobal)
|
||||||
|
// // fmt.Println("Err2: ", err2)
|
||||||
|
// // fmt.Println("reqGlobal: ", reqGlobal)
|
||||||
|
// c.RetryAddICECandidate(ctx, tries)
|
||||||
|
// return
|
||||||
|
|
||||||
|
// }
|
||||||
|
if err1 != nil {
|
||||||
|
c.helper.HandleIfErr(ctx, err1, &badReqSt)
|
||||||
|
fmt.Println("Err1: ", err1)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// if err := ctx.ShouldBindJSON(&reqModel); c.helper.HandleIfErr(ctx, err, &badReqSt) {
|
||||||
|
// fmt.Println("Err1: ", err)
|
||||||
|
// time.Sleep(1 * time.Second)
|
||||||
|
// c.RetryAddICECandidate(ctx, tries)
|
||||||
|
// return
|
||||||
|
// }
|
||||||
if !reqModel.Validate() {
|
if !reqModel.Validate() {
|
||||||
c.helper.ResponseUnprocessableEntity(ctx)
|
c.helper.ResponseUnprocessableEntity(ctx)
|
||||||
|
fmt.Println("Validate")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err := c.repo.AddPeerIceCandidate(reqModel.RoomId, reqModel.ID, reqModel.ICECandidate)
|
err := c.repo.AddPeerIceCandidate(reqModel.RoomId, reqModel.ID, reqModel.ICECandidate)
|
||||||
if c.helper.HandleIfErr(ctx, err, nil) {
|
if err != nil && tries < 3 {
|
||||||
|
c.RetryAddICECandidate(ctx, tries)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if err != nil {
|
||||||
|
c.helper.HandleIfErr(ctx, err, &badReqSt)
|
||||||
|
fmt.Println("Err: ", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// if c.helper.HandleIfErr(ctx, err, nil) {
|
||||||
|
// fmt.Println("Err2: ", err)
|
||||||
|
// time.Sleep(1 * time.Second)
|
||||||
|
// c.RetryAddICECandidate(ctx, tries)
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
c.helper.Response(ctx, struct{}{}, http.StatusNoContent)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *RoomController) AddICECandidate(ctx *gin.Context) {
|
||||||
|
fmt.Println("----AddICECandidate----")
|
||||||
|
// bd, _ := io.ReadAll(ctx.Request.Body)
|
||||||
|
// fmt.Println("bd: ", string(bd))
|
||||||
|
var reqModel dto.AddPeerICECandidateReqModel
|
||||||
|
// badReqSt := 400
|
||||||
|
err1 := ctx.ShouldBindJSON(&reqModel)
|
||||||
|
if err1 != nil {
|
||||||
|
// c.RetryAddICECandidate(ctx, 0)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// if err := ctx.ShouldBindJSON(&reqModel); c.helper.HandleIfErr(ctx, err, &badReqSt) {
|
||||||
|
// fmt.Println("Err1: ", err)
|
||||||
|
// time.Sleep(1 * time.Second)
|
||||||
|
// c.AddICECandidate(ctx)
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
if !reqModel.Validate() {
|
||||||
|
c.helper.ResponseUnprocessableEntity(ctx)
|
||||||
|
fmt.Println("Validate")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err := c.repo.AddPeerIceCandidate(reqModel.RoomId, reqModel.ID, reqModel.ICECandidate)
|
||||||
|
if err != nil {
|
||||||
|
c.RetryAddICECandidate(ctx, 0)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// if c.helper.HandleIfErr(ctx, err, nil) {
|
||||||
|
// fmt.Println("Err2: ", err)
|
||||||
|
// time.Sleep(1 * time.Second)
|
||||||
|
// c.AddICECandidate(ctx)
|
||||||
|
// return
|
||||||
|
// }
|
||||||
c.helper.Response(ctx, struct{}{}, http.StatusNoContent)
|
c.helper.Response(ctx, struct{}{}, http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue