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 {
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) {

View File

@ -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)
}

View File

@ -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
}

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
}
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"`
}
/////////////////////////////

View File

@ -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)

View File

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