neko/internal/types/session.go

77 lines
1.9 KiB
Go
Raw Normal View History

package types
2021-02-06 06:14:45 +13:00
import "net/http"
2020-11-02 06:39:12 +13:00
type MemberProfile struct {
2020-12-09 03:14:20 +13:00
Name string `json:"name"`
IsAdmin bool `json:"is_admin"`
CanLogin bool `json:"can_login"`
CanConnect bool `json:"can_connect"`
CanWatch bool `json:"can_watch"`
CanHost bool `json:"can_host"`
CanAccessClipboard bool `json:"can_access_clipboard"`
}
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"`
}
type Session interface {
ID() string
2020-12-03 05:29:38 +13:00
2020-12-09 03:37:48 +13:00
// profile
Name() string
2020-12-03 04:49:51 +13:00
IsAdmin() bool
2020-12-03 05:29:38 +13:00
CanLogin() bool
CanConnect() bool
CanWatch() bool
CanHost() bool
CanAccessClipboard() bool
2020-12-09 03:37:48 +13:00
GetProfile() MemberProfile
2020-12-03 05:29:38 +13:00
2020-12-09 03:37:48 +13:00
// state
IsHost() bool
2020-12-03 04:49:51 +13:00
IsConnected() bool
2021-03-14 11:42:16 +13:00
GetState() SessionState
2020-12-03 05:29:38 +13:00
2020-12-09 03:37:48 +13:00
// websocket
2021-02-15 05:11:21 +13:00
SetWebSocketPeer(websocketPeer WebSocketPeer)
2020-11-26 08:02:53 +13:00
SetWebSocketConnected(connected bool)
2020-12-03 05:29:38 +13:00
Send(v interface{}) error
2020-12-09 03:37:48 +13:00
Disconnect(reason string) error
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
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)
GetHost() Session
ClearHost()
2020-11-02 04:09:48 +13:00
2020-11-19 08:30:33 +13:00
Broadcast(v interface{}, exclude interface{})
AdminBroadcast(v 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
2020-11-02 06:39:12 +13:00
2021-03-14 09:11:48 +13:00
Authenticate(r *http.Request) (Session, error)
}