Compare commits

...

2 Commits

Author SHA1 Message Date
Mehrdad Mirsamie d4281c3265 retry failed ICE for 3 times 2023-08-14 13:55:26 +03:30
Mehrdad Mirsamie 2366c32298 small tweaks 2023-08-14 13:55:09 +03:30
2 changed files with 82 additions and 9 deletions

View File

@ -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)
} }

View File

@ -6,10 +6,10 @@ import (
) )
func main() { func main() {
svcAddr := flag.String("svc-addr", "", "service baseurl to register in logjam ( shoudln't end with / )") svcAddr := flag.String("svc-addr", "http://localhost:8080", "service baseurl to register in logjam ( shouldn't end with / )")
src := flag.String("src", ":8080", "listenhost:listenPort") src := flag.String("src", "localhost:8080", "listenHost:listenPort")
logjamBaseUrl := flag.String("logjam-base-url", "https://example.com", "logjam base url(shouldn't end with /)") logjamBaseUrl := flag.String("logjam-base-url", "http://localhost:8090", "logjam base url(shouldn't end with /)")
targetRoom := flag.String("targetRoom", "testyroom", "target room") targetRoom := flag.String("targetRoom", "test-room", "target room")
flag.Parse() flag.Parse()