2024-03-31 05:04:48 +00:00
|
|
|
package services
|
|
|
|
|
|
|
|
import (
|
2024-05-27 15:00:49 +00:00
|
|
|
"sync"
|
|
|
|
|
2024-04-13 05:48:19 +00:00
|
|
|
"git.solsynth.dev/hydrogen/passport/pkg/models"
|
2024-03-31 05:04:48 +00:00
|
|
|
"github.com/gofiber/contrib/websocket"
|
|
|
|
)
|
|
|
|
|
2024-05-27 15:00:49 +00:00
|
|
|
var (
|
|
|
|
wsMutex sync.Mutex
|
|
|
|
wsConn = make(map[uint]map[*websocket.Conn]bool)
|
|
|
|
)
|
2024-03-31 08:03:59 +00:00
|
|
|
|
2024-05-07 12:54:01 +00:00
|
|
|
func ClientRegister(user models.Account, conn *websocket.Conn) {
|
2024-05-27 15:00:49 +00:00
|
|
|
wsMutex.Lock()
|
2024-05-07 12:54:01 +00:00
|
|
|
if wsConn[user.ID] == nil {
|
|
|
|
wsConn[user.ID] = make(map[*websocket.Conn]bool)
|
|
|
|
}
|
|
|
|
wsConn[user.ID][conn] = true
|
2024-05-27 15:00:49 +00:00
|
|
|
wsMutex.Unlock()
|
2024-05-07 12:54:01 +00:00
|
|
|
}
|
2024-03-31 05:04:48 +00:00
|
|
|
|
2024-05-07 12:54:01 +00:00
|
|
|
func ClientUnregister(user models.Account, conn *websocket.Conn) {
|
2024-05-27 15:00:49 +00:00
|
|
|
wsMutex.Lock()
|
2024-05-07 12:54:01 +00:00
|
|
|
if wsConn[user.ID] == nil {
|
|
|
|
wsConn[user.ID] = make(map[*websocket.Conn]bool)
|
|
|
|
}
|
|
|
|
delete(wsConn[user.ID], conn)
|
2024-05-27 15:00:49 +00:00
|
|
|
wsMutex.Unlock()
|
2024-03-31 05:04:48 +00:00
|
|
|
}
|