2024-02-03 10:34:26 +00:00
|
|
|
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
package websocket
|
|
|
|
|
|
|
|
import (
|
|
|
|
"code.gitea.io/gitea/modules/context"
|
2024-02-03 21:13:32 +00:00
|
|
|
|
2024-02-03 10:34:26 +00:00
|
|
|
"github.com/olahol/melody"
|
|
|
|
)
|
|
|
|
|
|
|
|
func HandleConnect(s *melody.Session) {
|
|
|
|
ctx := context.GetWebContext(s.Request)
|
|
|
|
|
2024-02-11 13:11:51 +00:00
|
|
|
data := &sessionData{}
|
2024-02-03 10:34:26 +00:00
|
|
|
|
2024-02-11 13:11:51 +00:00
|
|
|
if ctx.IsSigned {
|
|
|
|
data.isSigned = true
|
|
|
|
data.userID = ctx.Doer.ID
|
2024-02-03 10:34:26 +00:00
|
|
|
}
|
2024-02-11 13:11:51 +00:00
|
|
|
|
|
|
|
s.Set("data", data)
|
2024-02-03 19:30:04 +00:00
|
|
|
|
|
|
|
// TODO: handle logouts
|
2024-02-03 10:34:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func HandleMessage(s *melody.Session, msg []byte) {
|
2024-02-11 13:11:51 +00:00
|
|
|
data, err := getSessionData(s)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: only handle specific url message
|
|
|
|
data.onURL = string(msg)
|
2024-02-03 10:34:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func HandleDisconnect(s *melody.Session) {
|
2024-02-03 15:41:20 +00:00
|
|
|
// TODO: Handle disconnect
|
2024-02-03 10:34:26 +00:00
|
|
|
}
|