2020-10-23 03:54:50 +13:00
|
|
|
package types
|
|
|
|
|
2021-08-30 03:09:13 +12:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
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-02 06:39:12 +13:00
|
|
|
|
2021-10-24 12:09:41 +13:00
|
|
|
type Cursor struct {
|
|
|
|
X int
|
|
|
|
Y int
|
|
|
|
}
|
|
|
|
|
2021-03-14 11:42:16 +13:00
|
|
|
type SessionState struct {
|
2020-12-09 03:14:20 +13:00
|
|
|
IsConnected bool `json:"is_connected"`
|
|
|
|
IsWatching bool `json:"is_watching"`
|
2020-11-26 10:07:05 +13:00
|
|
|
}
|
|
|
|
|
2020-10-23 03:54:50 +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
|
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
|
2021-02-15 05:11:21 +13:00
|
|
|
SetWebSocketPeer(websocketPeer WebSocketPeer)
|
2021-03-24 03:38:37 +13:00
|
|
|
SetWebSocketConnected(websocketPeer WebSocketPeer, connected bool)
|
2021-03-30 11:37:06 +13:00
|
|
|
GetWebSocketPeer() WebSocketPeer
|
2021-09-02 07:16:36 +12:00
|
|
|
Send(event string, payload interface{})
|
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)
|
2021-02-15 05:17:06 +13:00
|
|
|
SetWebRTCConnected(webrtcPeer WebRTCPeer, connected bool)
|
2021-02-06 06:14:45 +13:00
|
|
|
GetWebRTCPeer() WebRTCPeer
|
2020-10-23 03:54:50 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2021-03-14 10:17:49 +13:00
|
|
|
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
|
2020-11-02 04:09:48 +13:00
|
|
|
|
|
|
|
SetHost(host Session)
|
2020-11-01 11:53:19 +13:00
|
|
|
GetHost() Session
|
2020-10-23 03:54:50 +13:00
|
|
|
ClearHost()
|
2020-11-02 04:09:48 +13:00
|
|
|
|
2021-11-02 05:31:00 +13:00
|
|
|
SetCursor(cursor Cursor, session Session)
|
2021-10-24 12:09:41 +13:00
|
|
|
PopCursors() map[Session]Cursor
|
|
|
|
|
2021-09-02 07:16:36 +12:00
|
|
|
Broadcast(event string, payload interface{}, exclude interface{})
|
|
|
|
AdminBroadcast(event string, payload interface{}, exclude interface{})
|
2021-11-04 09:59:38 +13:00
|
|
|
InactiveCursorsBroadcast(event string, payload interface{}, exclude interface{})
|
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))
|
2020-12-04 04:10:52 +13:00
|
|
|
OnProfileChanged(listener func(session Session))
|
|
|
|
OnStateChanged(listener func(session Session))
|
2021-03-14 09:37:00 +13:00
|
|
|
OnHostChanged(listener func(session Session))
|
2020-12-03 05:29:38 +13:00
|
|
|
|
2020-12-02 23:24:20 +13:00
|
|
|
ImplicitHosting() bool
|
2021-11-02 05:49:02 +13:00
|
|
|
InactiveCursors() bool
|
2021-04-25 06:53:37 +12:00
|
|
|
CookieEnabled() bool
|
2021-08-24 04:41:19 +12:00
|
|
|
MercifulReconnect() 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)
|
2020-10-23 03:54:50 +13:00
|
|
|
}
|