neko/internal/types/session.go

94 lines
2.3 KiB
Go
Raw Normal View History

package types
2021-02-05 18:14:45 +01:00
import "net/http"
2020-11-01 18:39:12 +01:00
type MemberProfile struct {
2020-12-08 15:14:20 +01:00
Secret string `json:"secret,omitempty"`
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"`
}
type MemberState struct {
IsConnected bool `json:"is_connected"`
IsWatching bool `json:"is_watching"`
}
type MembersDatabase interface {
2020-12-06 18:11:11 +01:00
Connect() error
Disconnect() error
2021-02-14 14:40:17 +01:00
Insert(id string, profile MemberProfile) error
Update(id string, profile MemberProfile) error
Delete(id string) error
2020-12-06 18:11:11 +01:00
Select() (map[string]MemberProfile, error)
}
type Session interface {
ID() string
2020-12-02 17:29:38 +01:00
2020-12-08 15:37:48 +01:00
// profile
2020-12-02 17:29:38 +01:00
VerifySecret(secret string) bool
Name() string
2020-12-02 16:49:51 +01:00
IsAdmin() bool
2020-12-02 17:29:38 +01:00
CanLogin() bool
CanConnect() bool
CanWatch() bool
CanHost() bool
CanAccessClipboard() bool
2020-12-08 15:37:48 +01:00
GetProfile() MemberProfile
2020-12-02 17:29:38 +01:00
2020-12-08 15:37:48 +01:00
// state
IsHost() bool
2020-12-02 16:49:51 +01:00
IsConnected() bool
2020-12-08 15:37:48 +01:00
GetState() MemberState
2020-12-02 17:29:38 +01:00
2020-12-08 15:37:48 +01:00
// websocket
2021-02-14 17:11:21 +01:00
SetWebSocketPeer(websocketPeer WebSocketPeer)
2020-11-25 20:02:53 +01:00
SetWebSocketConnected(connected bool)
2020-12-02 17:29:38 +01:00
Send(v interface{}) error
2020-12-08 15:37:48 +01:00
Disconnect(reason string) error
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)
SetWebRTCConnected(webrtcPeer WebRTCPeer, connected bool)
2021-02-05 18:14:45 +01:00
GetWebRTCPeer() WebRTCPeer
}
type SessionManager interface {
2020-12-06 18:11:11 +01:00
Connect() error
Disconnect() error
2020-12-05 23:05:46 +01:00
Create(id string, profile MemberProfile) (Session, error)
2020-12-05 22:18:45 +01:00
Update(id string, profile MemberProfile) error
2020-11-01 16:09:48 +01:00
Get(id string) (Session, bool)
2020-11-25 22:06:13 +01:00
Delete(id string) error
2020-11-01 16:09:48 +01:00
SetHost(host Session)
GetHost() Session
ClearHost()
2020-11-01 16:09:48 +01:00
HasConnectedMembers() bool
2020-11-01 16:09:48 +01:00
Members() []Session
2020-11-18 20:30:33 +01:00
Broadcast(v interface{}, exclude interface{})
AdminBroadcast(v interface{}, exclude interface{})
2020-11-01 16:09:48 +01:00
2020-10-31 23:03:37 +01:00
OnHost(listener func(session Session))
OnHostCleared(listener func(session Session))
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))
2020-12-02 17:29:38 +01:00
2020-12-02 11:24:20 +01:00
ImplicitHosting() bool
2020-11-01 18:39:12 +01:00
2021-01-29 22:22:14 +01:00
AuthenticateRequest(r *http.Request) (Session, error)
Authenticate(id string, secret string) (Session, error)
}