2020-10-22 16:54:50 +02:00
|
|
|
package types
|
|
|
|
|
2021-08-29 17:09:13 +02: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-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"`
|
2020-11-25 22:07:05 +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
|
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)
|
2021-03-23 15:38:37 +01:00
|
|
|
SetWebSocketConnected(websocketPeer WebSocketPeer, connected bool)
|
2021-03-30 00:37:06 +02:00
|
|
|
GetWebSocketPeer() WebSocketPeer
|
2021-09-01 21:16:36 +02:00
|
|
|
Send(event string, payload interface{})
|
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)
|
2020-10-31 23:53:19 +01:00
|
|
|
GetHost() Session
|
2020-10-22 16:54:50 +02:00
|
|
|
ClearHost()
|
2020-11-01 16:09:48 +01:00
|
|
|
|
2021-09-01 21:16:36 +02:00
|
|
|
Broadcast(event string, payload interface{}, exclude interface{})
|
|
|
|
AdminBroadcast(event string, payload 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
|
2021-04-24 20:53:37 +02:00
|
|
|
CookieEnabled() bool
|
2021-08-23 18:41:19 +02:00
|
|
|
MercifulReconnect() 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
|
|
|
}
|