This commit is contained in:
poiuty 2022-08-15 21:06:39 +03:00
parent ac13a3fab3
commit 1f059fad30

View file

@ -144,6 +144,15 @@ func getToken(room string) string {
return string(bytes.ReplaceAll(m[1], []byte(`\u002F`), []byte(`/`))) return string(bytes.ReplaceAll(m[1], []byte(`\u002F`), []byte(`/`)))
} }
func reconnectRoom(workerData Info) {
n := randInt(10, 30)
fmt.Printf("Sleeping %d seconds...\n", n)
time.Sleep(time.Duration(n) * time.Second)
fmt.Println("reconnect:", workerData.room, workerData.Id, workerData.Proxy)
workerData.Last = time.Now().Unix()
startRoom(workerData)
}
func xWorker(workerData Info) { func xWorker(workerData Info) {
fmt.Println("Start", workerData.room, "id", workerData.Id, "proxy", workerData.Proxy) fmt.Println("Start", workerData.room, "id", workerData.Id, "proxy", workerData.Proxy)
@ -153,16 +162,18 @@ func xWorker(workerData Info) {
rooms.Del <- workerData.room rooms.Del <- workerData.room
}() }()
xurl := workerData.Server if workerData.Server == "" {
workerData.Server = getToken(workerData.room)
if xurl == "" {
xurl = getToken(workerData.room)
workerData.Server = xurl
} }
u, err := url.Parse(xurl) if len(workerData.Server) < 50 {
fmt.Println(workerData.Server, workerData.room)
return
}
u, err := url.Parse(workerData.Server)
if err != nil { if err != nil {
fmt.Println(xurl, err, workerData.room) fmt.Println(err, workerData.room)
return return
} }
@ -198,6 +209,9 @@ func xWorker(workerData Info) {
_, message, err := c.ReadMessage() _, message, err := c.ReadMessage()
if err != nil { if err != nil {
fmt.Println(err.Error(), workerData.room) fmt.Println(err.Error(), workerData.room)
if workerData.Income > 1 && websocket.IsUnexpectedCloseError(err, websocket.CloseGoingAway) {
reconnectRoom(workerData)
}
return return
} }