2020-10-22 16:54:50 +02:00
|
|
|
package types
|
|
|
|
|
2021-08-29 17:09:13 +02:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"net/http"
|
2023-05-15 00:28:45 +02:00
|
|
|
"time"
|
2021-08-29 17:09:13 +02: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")
|
|
|
|
)
|
2020-11-01 18:39:12 +01:00
|
|
|
|
2021-10-24 01:09:41 +02:00
|
|
|
type Cursor struct {
|
2021-11-12 15:27:05 +00:00
|
|
|
X int `json:"x"`
|
|
|
|
Y int `json:"y"`
|
2021-10-24 01:09:41 +02:00
|
|
|
}
|
|
|
|
|
2023-03-27 18:33:51 +02:00
|
|
|
type SessionProfile struct {
|
|
|
|
Id string
|
|
|
|
Token string
|
|
|
|
Profile MemberProfile
|
|
|
|
}
|
|
|
|
|
2021-03-13 23:42:16 +01:00
|
|
|
type SessionState struct {
|
2020-12-08 15:14:20 +01:00
|
|
|
IsConnected bool `json:"is_connected"`
|
2023-05-15 00:28:45 +02: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"`
|
2020-11-25 22:07:05 +01:00
|
|
|
}
|
|
|
|
|
2022-03-27 00:08:06 +01:00
|
|
|
type Settings struct {
|
|
|
|
PrivateMode bool `json:"private_mode"`
|
2023-05-14 22:41:32 +02:00
|
|
|
LockedControls bool `json:"locked_controls"`
|
2022-03-27 00:08:06 +01:00
|
|
|
ImplicitHosting bool `json:"implicit_hosting"`
|
|
|
|
InactiveCursors bool `json:"inactive_cursors"`
|
|
|
|
MercifulReconnect bool `json:"merciful_reconnect"`
|
2023-04-28 22:53:41 +02:00
|
|
|
|
|
|
|
// plugin scope
|
|
|
|
Plugins map[string]any `json:"plugins"`
|
2022-03-27 00:08:06 +01:00
|
|
|
}
|
|
|
|
|
2020-10-22 16:54:50 +02:00
|
|
|
type Session interface {
|
|
|
|
ID() string
|
2021-03-14 00:45:51 +01:00
|
|
|
Profile() MemberProfile
|
|
|
|
State() SessionState
|
2021-03-14 00:50:08 +01:00
|
|
|
IsHost() bool
|
2022-03-26 23:20:38 +01:00
|
|
|
PrivateModeEnabled() bool
|
2020-12-02 17:29:38 +01:00
|
|
|
|
2021-10-24 01:09:41 +02:00
|
|
|
// cursor
|
2021-11-01 17:31:00 +01:00
|
|
|
SetCursor(cursor Cursor)
|
2021-10-23 20:25:18 +02:00
|
|
|
|
2020-12-08 15:37:48 +01:00
|
|
|
// websocket
|
2023-04-23 11:23:20 +02:00
|
|
|
ConnectWebSocketPeer(websocketPeer WebSocketPeer)
|
|
|
|
DisconnectWebSocketPeer(websocketPeer WebSocketPeer, delayed bool)
|
|
|
|
DestroyWebSocketPeer(reason string)
|
2022-07-28 12:20:20 +02:00
|
|
|
Send(event string, payload any)
|
2020-12-02 17:29:38 +01:00
|
|
|
|
2020-12-08 15:37:48 +01:00
|
|
|
// webrtc
|
2021-02-14 17:11:21 +01:00
|
|
|
SetWebRTCPeer(webrtcPeer WebRTCPeer)
|
2021-02-14 17:17:06 +01:00
|
|
|
SetWebRTCConnected(webrtcPeer WebRTCPeer, connected bool)
|
2021-02-05 18:14:45 +01:00
|
|
|
GetWebRTCPeer() WebRTCPeer
|
2020-10-22 16:54:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type SessionManager interface {
|
2021-03-13 22:54:34 +01:00
|
|
|
Create(id string, profile MemberProfile) (Session, string, error)
|
2020-12-05 22:18:45 +01:00
|
|
|
Update(id string, profile MemberProfile) error
|
2020-11-25 22:06:13 +01:00
|
|
|
Delete(id string) error
|
2021-03-13 22:17:49 +01:00
|
|
|
Get(id string) (Session, bool)
|
2021-03-13 22:54:34 +01:00
|
|
|
GetByToken(token string) (Session, bool)
|
2021-03-13 21:11:48 +01:00
|
|
|
List() []Session
|
2020-11-01 16:09:48 +01:00
|
|
|
|
|
|
|
SetHost(host Session)
|
2022-08-26 20:16:40 +02:00
|
|
|
GetHost() (Session, bool)
|
2020-10-22 16:54:50 +02:00
|
|
|
ClearHost()
|
2020-11-01 16:09:48 +01:00
|
|
|
|
2021-11-01 17:31:00 +01:00
|
|
|
SetCursor(cursor Cursor, session Session)
|
2021-11-12 15:27:05 +00:00
|
|
|
PopCursors() map[Session][]Cursor
|
2021-10-24 01:09:41 +02:00
|
|
|
|
2022-07-28 12:20:20 +02:00
|
|
|
Broadcast(event string, payload any, exclude ...string)
|
|
|
|
AdminBroadcast(event string, payload any, exclude ...string)
|
|
|
|
InactiveCursorsBroadcast(event string, payload any, exclude ...string)
|
2020-11-01 16:09:48 +01:00
|
|
|
|
2020-12-02 18:59:32 +01:00
|
|
|
OnCreated(listener func(session Session))
|
|
|
|
OnDeleted(listener func(session Session))
|
2020-10-31 23:03:37 +01:00
|
|
|
OnConnected(listener func(session Session))
|
2020-11-01 20:53:25 +01:00
|
|
|
OnDisconnected(listener func(session Session))
|
2020-12-03 16:10:52 +01:00
|
|
|
OnProfileChanged(listener func(session Session))
|
|
|
|
OnStateChanged(listener func(session Session))
|
2021-03-13 21:37:00 +01:00
|
|
|
OnHostChanged(listener func(session Session))
|
2022-03-27 00:08:06 +01:00
|
|
|
OnSettingsChanged(listener func(new Settings, old Settings))
|
2020-12-02 17:29:38 +01:00
|
|
|
|
2022-03-27 00:08:06 +01:00
|
|
|
UpdateSettings(Settings)
|
|
|
|
Settings() Settings
|
2021-04-24 20:53:37 +02:00
|
|
|
CookieEnabled() bool
|
2020-11-01 18:39:12 +01:00
|
|
|
|
2021-03-17 14:09:10 +01:00
|
|
|
CookieSetToken(w http.ResponseWriter, token string)
|
2021-03-25 10:29:28 +01:00
|
|
|
CookieClearToken(w http.ResponseWriter, r *http.Request)
|
2021-03-13 21:11:48 +01:00
|
|
|
Authenticate(r *http.Request) (Session, error)
|
2020-10-22 16:54:50 +02:00
|
|
|
}
|