mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
memberState -> sessionState.
This commit is contained in:
parent
b03a730c84
commit
dafebc79e5
@ -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) {
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
11
internal/types/member.go
Normal 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)
|
||||
}
|
@ -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"`
|
||||
}
|
||||
|
||||
/////////////////////////////
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user