From dafebc79e53ef67be05ce027004a1c39c4dbfad6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Sat, 13 Mar 2021 23:42:16 +0100 Subject: [PATCH] memberState -> sessionState. --- internal/api/session.go | 2 +- internal/http/auth/auth.go | 4 ++-- internal/session/session.go | 4 ++-- internal/types/member.go | 11 +++++++++++ internal/types/message/messages.go | 6 +++--- internal/types/session.go | 14 ++------------ internal/websocket/handler/session.go | 8 ++++---- internal/websocket/handler/system.go | 2 +- 8 files changed, 26 insertions(+), 25 deletions(-) create mode 100644 internal/types/member.go diff --git a/internal/api/session.go b/internal/api/session.go index 87f66d31..9fc5b001 100644 --- a/internal/api/session.go +++ b/internal/api/session.go @@ -21,7 +21,7 @@ type SessionLoginPayload struct { type SessionWhoamiPayload struct { ID string `json:"id"` 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) { diff --git a/internal/http/auth/auth.go b/internal/http/auth/auth.go index a8d627e7..3c6ac7e4 100644 --- a/internal/http/auth/auth.go +++ b/internal/http/auth/auth.go @@ -60,7 +60,7 @@ func CanHostOnly(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { session := GetSession(r) if !session.CanHost() { - utils.HttpForbidden(w, "Only for members, that can host.") + utils.HttpForbidden(w, "Only for sessions, that can host.") } else { 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) { session := GetSession(r) if !session.CanWatch() { - utils.HttpForbidden(w, "Only for members, that can watch.") + utils.HttpForbidden(w, "Only for sessions, that can watch.") } else { next.ServeHTTP(w, r) } diff --git a/internal/session/session.go b/internal/session/session.go index 9847a4e0..9759d239 100644 --- a/internal/session/session.go +++ b/internal/session/session.go @@ -14,7 +14,7 @@ type SessionCtx struct { logger zerolog.Logger manager *SessionManagerCtx profile types.MemberProfile - state types.MemberState + state types.SessionState websocketPeer types.WebSocketPeer webrtcPeer types.WebRTCPeer } @@ -91,7 +91,7 @@ func (session *SessionCtx) IsConnected() bool { return session.state.IsConnected } -func (session *SessionCtx) GetState() types.MemberState { +func (session *SessionCtx) GetState() types.SessionState { return session.state } diff --git a/internal/types/member.go b/internal/types/member.go new file mode 100644 index 00000000..403d6c54 --- /dev/null +++ b/internal/types/member.go @@ -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) +} diff --git a/internal/types/message/messages.go b/internal/types/message/messages.go index 072a407a..4edfa7a7 100644 --- a/internal/types/message/messages.go +++ b/internal/types/message/messages.go @@ -78,17 +78,17 @@ type MemberProfile struct { *types.MemberProfile } -type MemberState struct { +type SessionState struct { Event string `json:"event,omitempty"` ID string `json:"id"` - *types.MemberState + *types.SessionState } type MemberData struct { Event string `json:"event,omitempty"` ID string `json:"id"` Profile types.MemberProfile `json:"profile"` - State types.MemberState `json:"state"` + State types.SessionState `json:"state"` } ///////////////////////////// diff --git a/internal/types/session.go b/internal/types/session.go index b60b3696..c1888cbc 100644 --- a/internal/types/session.go +++ b/internal/types/session.go @@ -13,21 +13,11 @@ type MemberProfile struct { CanAccessClipboard bool `json:"can_access_clipboard"` } -type MemberState struct { +type SessionState struct { IsConnected bool `json:"is_connected"` 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 { ID() string @@ -44,7 +34,7 @@ type Session interface { // state IsHost() bool IsConnected() bool - GetState() MemberState + GetState() SessionState // websocket SetWebSocketPeer(websocketPeer WebSocketPeer) diff --git a/internal/websocket/handler/session.go b/internal/websocket/handler/session.go index 6bad4854..b4303248 100644 --- a/internal/websocket/handler/session.go +++ b/internal/websocket/handler/session.go @@ -69,10 +69,10 @@ func (h *MessageHandlerCtx) SessionStateChanged(session types.Session) error { state := session.GetState() h.sessions.Broadcast( - message.MemberState{ - Event: event.MEMBER_STATE, - ID: session.ID(), - MemberState: &state, + message.SessionState{ + Event: event.MEMBER_STATE, + ID: session.ID(), + SessionState: &state, }, nil) return nil diff --git a/internal/websocket/handler/system.go b/internal/websocket/handler/system.go index 5f419ecb..f38e86e1 100644 --- a/internal/websocket/handler/system.go +++ b/internal/websocket/handler/system.go @@ -36,7 +36,7 @@ func (h *MessageHandlerCtx) systemInit(session types.Session) error { return session.Send( message.SystemInit{ - Event: event.SYSTEM_INIT, + Event: event.SYSTEM_INIT, // TODO: Session ID. MemberId: session.ID(), ControlHost: controlHost,