neko/pkg/types/session.go

116 lines
3.3 KiB
Go
Raw Normal View History

package types
2021-08-30 03:09:13 +12:00
import (
"errors"
"net/http"
2023-05-15 10:28:45 +12:00
"time"
2021-08-30 03:09:13 +12:00
)
var (
ErrSessionNotFound = errors.New("session not found")
ErrSessionAlreadyExists = errors.New("session already exists")
ErrSessionAlreadyConnected = errors.New("session is already connected")
ErrSessionLoginDisabled = errors.New("session login disabled")
2024-04-21 00:27:15 +12:00
ErrSessionLoginsLocked = errors.New("session logins locked")
2021-08-30 03:09:13 +12:00
)
2020-11-02 06:39:12 +13:00
2021-10-24 12:09:41 +13:00
type Cursor struct {
2021-11-13 04:27:05 +13:00
X int `json:"x"`
Y int `json:"y"`
2021-10-24 12:09:41 +13:00
}
2023-03-28 05:33:51 +13:00
type SessionProfile struct {
Id string
Token string
Profile MemberProfile
}
2021-03-14 11:42:16 +13:00
type SessionState struct {
2020-12-09 03:14:20 +13:00
IsConnected bool `json:"is_connected"`
2023-05-15 10:28:45 +12:00
// when the session was last connected
ConnectedSince *time.Time `json:"connected_since,omitempty"`
// when the session was last not connected
NotConnectedSince *time.Time `json:"not_connected_since,omitempty"`
IsWatching bool `json:"is_watching"`
// when the session was last watching
WatchingSince *time.Time `json:"watching_since,omitempty"`
// when the session was last not watching
NotWatchingSince *time.Time `json:"not_watching_since,omitempty"`
}
2022-03-27 12:08:06 +13:00
type Settings struct {
PrivateMode bool `json:"private_mode"`
2024-04-21 00:27:15 +12:00
LockedLogins bool `json:"locked_logins"`
2023-05-15 08:41:32 +12:00
LockedControls bool `json:"locked_controls"`
2024-04-22 06:10:16 +12:00
ControlProtection bool `json:"control_protection"`
2022-03-27 12:08:06 +13:00
ImplicitHosting bool `json:"implicit_hosting"`
InactiveCursors bool `json:"inactive_cursors"`
MercifulReconnect bool `json:"merciful_reconnect"`
2023-04-29 08:53:41 +12:00
// plugin scope
2024-06-17 02:42:32 +12:00
Plugins PluginSettings `json:"plugins"`
2022-03-27 12:08:06 +13:00
}
type Session interface {
ID() string
2021-03-14 12:45:51 +13:00
Profile() MemberProfile
State() SessionState
2021-03-14 12:50:08 +13:00
IsHost() bool
2024-05-07 09:47:13 +12:00
SetAsHost()
SetAsHostBy(session Session)
ClearHost()
2022-03-27 11:20:38 +13:00
PrivateModeEnabled() bool
2020-12-03 05:29:38 +13:00
2021-10-24 12:09:41 +13:00
// cursor
2021-11-02 05:31:00 +13:00
SetCursor(cursor Cursor)
2021-10-24 07:25:18 +13:00
2020-12-09 03:37:48 +13:00
// websocket
ConnectWebSocketPeer(websocketPeer WebSocketPeer)
DisconnectWebSocketPeer(websocketPeer WebSocketPeer, delayed bool)
DestroyWebSocketPeer(reason string)
Send(event string, payload any)
2020-12-03 05:29:38 +13:00
2020-12-09 03:37:48 +13:00
// webrtc
2021-02-15 05:11:21 +13:00
SetWebRTCPeer(webrtcPeer WebRTCPeer)
SetWebRTCConnected(webrtcPeer WebRTCPeer, connected bool)
2021-02-06 06:14:45 +13:00
GetWebRTCPeer() WebRTCPeer
}
type SessionManager interface {
2021-03-14 10:54:34 +13:00
Create(id string, profile MemberProfile) (Session, string, error)
2020-12-06 10:18:45 +13:00
Update(id string, profile MemberProfile) error
2020-11-26 10:06:13 +13:00
Delete(id string) error
Disconnect(id string) error
Get(id string) (Session, bool)
2021-03-14 10:54:34 +13:00
GetByToken(token string) (Session, bool)
2021-03-14 09:11:48 +13:00
List() []Session
2024-04-22 06:10:16 +12:00
Range(func(Session) bool)
2020-11-02 04:09:48 +13:00
GetHost() (Session, bool)
2020-11-02 04:09:48 +13:00
2021-11-02 05:31:00 +13:00
SetCursor(cursor Cursor, session Session)
2021-11-13 04:27:05 +13:00
PopCursors() map[Session][]Cursor
2021-10-24 12:09:41 +13:00
Broadcast(event string, payload any, exclude ...string)
AdminBroadcast(event string, payload any, exclude ...string)
InactiveCursorsBroadcast(event string, payload any, exclude ...string)
2020-11-02 04:09:48 +13:00
2020-12-03 06:59:32 +13:00
OnCreated(listener func(session Session))
OnDeleted(listener func(session Session))
2020-11-01 11:03:37 +13:00
OnConnected(listener func(session Session))
2020-11-02 08:53:25 +13:00
OnDisconnected(listener func(session Session))
OnProfileChanged(listener func(session Session, new, old MemberProfile))
2020-12-04 04:10:52 +13:00
OnStateChanged(listener func(session Session))
2024-05-07 09:47:13 +12:00
OnHostChanged(listener func(session, host Session))
OnSettingsChanged(listener func(session Session, new, old Settings))
2020-12-03 05:29:38 +13:00
2024-05-05 10:03:32 +12:00
UpdateSettingsFunc(session Session, f func(settings *Settings) bool)
2022-03-27 12:08:06 +13:00
Settings() Settings
2021-04-25 06:53:37 +12:00
CookieEnabled() bool
2020-11-02 06:39:12 +13:00
2021-03-18 02:09:10 +13:00
CookieSetToken(w http.ResponseWriter, token string)
2021-03-25 22:29:28 +13:00
CookieClearToken(w http.ResponseWriter, r *http.Request)
2021-03-14 09:11:48 +13:00
Authenticate(r *http.Request) (Session, error)
}