neko/internal/types/session.go

55 lines
1.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
2021-03-13 23:42:16 +01:00
type SessionState struct {
2020-12-08 15:14:20 +01:00
IsConnected bool `json:"is_connected"`
IsWatching bool `json:"is_watching"`
}
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
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 {
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
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)
GetHost() Session
ClearHost()
2020-11-01 16:09:48 +01:00
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-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))
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-03-13 21:11:48 +01:00
Authenticate(r *http.Request) (Session, error)
}