This commit is contained in:
richboo111
2023-04-25 15:04:59 +08:00
parent 34637587d9
commit 472cb41ed5
2 changed files with 10 additions and 6 deletions

View File

@@ -20,15 +20,21 @@ type IMController struct {
// @Failure 200 {object} controllers.CallResult
// @router /StartWebSocket [get]
func (c *IMController) StartWebSocket() {
upgrader.CheckOrigin = func(r *http.Request) bool {
return true
}
ws, err := upgrader.Upgrade(c.Ctx.ResponseWriter, c.Ctx.Request, nil)
ws, err := upgrader.Upgrade(c.Ctx.ResponseWriter, &http.Request{
Method: "GET",
Header: http.Header{
"Upgrade": []string{"websocket"},
"Connection": []string{"upgrade"},
"Sec-Websocket-Key": []string{"dGhlIHNhbXBsZSBub25jZQ=="},
"Sec-Websocket-Version": []string{"13"},
}}, nil)
if err != nil {
globals.SugarLogger.Errorf("upgrade error: %v", err)
return
}
defer ws.Close()
clientID := c.GetString("clientID")
globals.SugarLogger.Debugf("clientID=%s", clientID)
im.StartWebSocket(ws, clientID, err)