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 {
|
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) {
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
|
@ -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
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
|
*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"`
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
|
@ -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)
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user