memberState -> sessionState.

This commit is contained in:
Miroslav Šedivý 2021-03-13 23:42:16 +01:00
parent b03a730c84
commit dafebc79e5
8 changed files with 26 additions and 25 deletions

View File

@ -21,7 +21,7 @@ type SessionLoginPayload struct {
type SessionWhoamiPayload struct { type SessionWhoamiPayload struct {
ID string `json:"id"` ID string `json:"id"`
Profile types.MemberProfile `json:"profile"` Profile types.MemberProfile `json:"profile"`
State types.MemberState `json:"state"` State types.SessionState `json:"state"`
} }
func (api *ApiManagerCtx) Login(w http.ResponseWriter, r *http.Request) { func (api *ApiManagerCtx) Login(w http.ResponseWriter, r *http.Request) {

View File

@ -60,7 +60,7 @@ func CanHostOnly(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
session := GetSession(r) session := GetSession(r)
if !session.CanHost() { if !session.CanHost() {
utils.HttpForbidden(w, "Only for members, that can host.") utils.HttpForbidden(w, "Only for sessions, that can host.")
} else { } else {
next.ServeHTTP(w, r) next.ServeHTTP(w, r)
} }
@ -71,7 +71,7 @@ func CanWatchOnly(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
session := GetSession(r) session := GetSession(r)
if !session.CanWatch() { if !session.CanWatch() {
utils.HttpForbidden(w, "Only for members, that can watch.") utils.HttpForbidden(w, "Only for sessions, that can watch.")
} else { } else {
next.ServeHTTP(w, r) next.ServeHTTP(w, r)
} }

View File

@ -14,7 +14,7 @@ type SessionCtx struct {
logger zerolog.Logger logger zerolog.Logger
manager *SessionManagerCtx manager *SessionManagerCtx
profile types.MemberProfile profile types.MemberProfile
state types.MemberState state types.SessionState
websocketPeer types.WebSocketPeer websocketPeer types.WebSocketPeer
webrtcPeer types.WebRTCPeer webrtcPeer types.WebRTCPeer
} }
@ -91,7 +91,7 @@ func (session *SessionCtx) IsConnected() bool {
return session.state.IsConnected return session.state.IsConnected
} }
func (session *SessionCtx) GetState() types.MemberState { func (session *SessionCtx) GetState() types.SessionState {
return session.state return session.state
} }

11
internal/types/member.go Normal file
View File

@ -0,0 +1,11 @@
package types
type MembersDatabase interface {
Connect() error
Disconnect() error
Insert(id string, profile MemberProfile) error
Update(id string, profile MemberProfile) error
Delete(id string) error
Select() (map[string]MemberProfile, error)
}

View File

@ -78,17 +78,17 @@ type MemberProfile struct {
*types.MemberProfile *types.MemberProfile
} }
type MemberState struct { type SessionState struct {
Event string `json:"event,omitempty"` Event string `json:"event,omitempty"`
ID string `json:"id"` ID string `json:"id"`
*types.MemberState *types.SessionState
} }
type MemberData struct { type MemberData struct {
Event string `json:"event,omitempty"` Event string `json:"event,omitempty"`
ID string `json:"id"` ID string `json:"id"`
Profile types.MemberProfile `json:"profile"` Profile types.MemberProfile `json:"profile"`
State types.MemberState `json:"state"` State types.SessionState `json:"state"`
} }
///////////////////////////// /////////////////////////////

View File

@ -13,21 +13,11 @@ type MemberProfile struct {
CanAccessClipboard bool `json:"can_access_clipboard"` CanAccessClipboard bool `json:"can_access_clipboard"`
} }
type MemberState struct { type SessionState struct {
IsConnected bool `json:"is_connected"` IsConnected bool `json:"is_connected"`
IsWatching bool `json:"is_watching"` IsWatching bool `json:"is_watching"`
} }
type MembersDatabase interface {
Connect() error
Disconnect() error
Insert(id string, profile MemberProfile) error
Update(id string, profile MemberProfile) error
Delete(id string) error
Select() (map[string]MemberProfile, error)
}
type Session interface { type Session interface {
ID() string ID() string
@ -44,7 +34,7 @@ type Session interface {
// state // state
IsHost() bool IsHost() bool
IsConnected() bool IsConnected() bool
GetState() MemberState GetState() SessionState
// websocket // websocket
SetWebSocketPeer(websocketPeer WebSocketPeer) SetWebSocketPeer(websocketPeer WebSocketPeer)

View File

@ -69,10 +69,10 @@ func (h *MessageHandlerCtx) SessionStateChanged(session types.Session) error {
state := session.GetState() state := session.GetState()
h.sessions.Broadcast( h.sessions.Broadcast(
message.MemberState{ message.SessionState{
Event: event.MEMBER_STATE, Event: event.MEMBER_STATE,
ID: session.ID(), ID: session.ID(),
MemberState: &state, SessionState: &state,
}, nil) }, nil)
return nil return nil

View File

@ -36,7 +36,7 @@ func (h *MessageHandlerCtx) systemInit(session types.Session) error {
return session.Send( return session.Send(
message.SystemInit{ message.SystemInit{
Event: event.SYSTEM_INIT, Event: event.SYSTEM_INIT,
// TODO: Session ID. // TODO: Session ID.
MemberId: session.ID(), MemberId: session.ID(),
ControlHost: controlHost, ControlHost: controlHost,