mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
new MemberProfile & session refactor.
This commit is contained in:
parent
220e162f42
commit
0d2f3405bb
@ -16,10 +16,11 @@ type MemberDataPayload struct {
|
||||
Secret string `json:"secret,omitempty"`
|
||||
Name string `json:"name"`
|
||||
IsAdmin bool `json:"is_admin"`
|
||||
//Enabled bool `json:"enabled"`
|
||||
//CanControl bool `json:"can_control"`
|
||||
//CanWatch bool `json:"can_watch"`
|
||||
//ClipboardAccess bool `json:"clipboard_access"`
|
||||
CanLogin bool `json:"can_login"`
|
||||
CanConnect bool `json:"can_connect"`
|
||||
CanWatch bool `json:"can_watch"`
|
||||
CanHost bool `json:"can_host"`
|
||||
CanAccessClipboard bool `json:"can_access_clipboard"`
|
||||
}
|
||||
|
||||
func (h *MembersHandler) membersCreate(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -238,6 +238,18 @@ func (manager *SessionManagerCtx) OnDisconnected(listener func(session types.Ses
|
||||
})
|
||||
}
|
||||
|
||||
func (manager *SessionManagerCtx) OnReceivingStarted(listener func(session types.Session)) {
|
||||
manager.emmiter.On("receiving_started", func(payload ...interface{}) {
|
||||
listener(payload[0].(*SessionCtx))
|
||||
})
|
||||
}
|
||||
|
||||
func (manager *SessionManagerCtx) OnReceivingStopped(listener func(session types.Session)) {
|
||||
manager.emmiter.On("receiving_stopped", func(payload ...interface{}) {
|
||||
listener(payload[0].(*SessionCtx))
|
||||
})
|
||||
}
|
||||
|
||||
// ---
|
||||
// config
|
||||
// ---
|
||||
|
@ -23,6 +23,14 @@ func (session *SessionCtx) ID() string {
|
||||
return session.id
|
||||
}
|
||||
|
||||
// ---
|
||||
// profile
|
||||
// ---
|
||||
|
||||
func (session *SessionCtx) VerifySecret(secret string) bool {
|
||||
return session.profile.Secret == secret
|
||||
}
|
||||
|
||||
func (session *SessionCtx) Name() string {
|
||||
return session.profile.Name
|
||||
}
|
||||
@ -31,55 +39,44 @@ func (session *SessionCtx) IsAdmin() bool {
|
||||
return session.profile.IsAdmin
|
||||
}
|
||||
|
||||
func (session *SessionCtx) CanLogin() bool {
|
||||
return session.profile.CanLogin
|
||||
}
|
||||
|
||||
func (session *SessionCtx) CanConnect() bool {
|
||||
return session.profile.CanConnect
|
||||
}
|
||||
|
||||
func (session *SessionCtx) CanWatch() bool {
|
||||
return session.profile.CanWatch
|
||||
}
|
||||
|
||||
func (session *SessionCtx) CanHost() bool {
|
||||
return session.profile.CanHost
|
||||
}
|
||||
|
||||
func (session *SessionCtx) CanAccessClipboard() bool {
|
||||
return session.profile.CanAccessClipboard
|
||||
}
|
||||
|
||||
func (session *SessionCtx) SetProfile(profile types.MemberProfile) {
|
||||
session.profile = profile
|
||||
}
|
||||
|
||||
// ---
|
||||
// runtime
|
||||
// ---
|
||||
|
||||
func (session *SessionCtx) IsHost() bool {
|
||||
return session.manager.host != nil && session.manager.host.ID() == session.ID()
|
||||
}
|
||||
|
||||
func (session *SessionCtx) VerifySecret(secret string) bool {
|
||||
return session.profile.Secret == secret
|
||||
}
|
||||
|
||||
func (session *SessionCtx) IsConnected() bool {
|
||||
// TODO: Refactor.
|
||||
return session.websocket_connected// && session.webrtc_connected
|
||||
return session.websocket_connected
|
||||
}
|
||||
|
||||
func (session *SessionCtx) SetWebSocketPeer(websocket_peer types.WebSocketPeer) {
|
||||
session.websocket_peer = websocket_peer
|
||||
}
|
||||
|
||||
func (session *SessionCtx) SetWebSocketConnected(connected bool) {
|
||||
if connected {
|
||||
session.websocket_connected = true
|
||||
|
||||
// TODO: Refactor.
|
||||
//session.manager.emmiter.Emit("websocket_connected", session)
|
||||
session.manager.emmiter.Emit("connected", session)
|
||||
} else {
|
||||
session.websocket_connected = false
|
||||
|
||||
// TODO: Refactor.
|
||||
//session.manager.emmiter.Emit("websocket_disconnected", session)
|
||||
session.manager.emmiter.Emit("disconnected", session)
|
||||
|
||||
session.websocket_peer = nil
|
||||
}
|
||||
}
|
||||
|
||||
func (session *SessionCtx) SetWebRTCPeer(webrtc_peer types.WebRTCPeer) {
|
||||
session.webrtc_peer = webrtc_peer
|
||||
}
|
||||
|
||||
func (session *SessionCtx) SetWebRTCConnected(connected bool) {
|
||||
if connected {
|
||||
session.webrtc_connected = true
|
||||
session.manager.emmiter.Emit("webrtc_connected", session)
|
||||
} else {
|
||||
session.webrtc_connected = false
|
||||
session.manager.emmiter.Emit("webrtc_disconnected", session)
|
||||
|
||||
session.webrtc_peer = nil
|
||||
}
|
||||
func (session *SessionCtx) IsReceiving() bool {
|
||||
return session.webrtc_connected
|
||||
}
|
||||
|
||||
func (session *SessionCtx) Disconnect(reason string) error {
|
||||
@ -106,6 +103,25 @@ func (session *SessionCtx) Disconnect(reason string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ---
|
||||
// webscoket
|
||||
// ---
|
||||
|
||||
func (session *SessionCtx) SetWebSocketPeer(websocket_peer types.WebSocketPeer) {
|
||||
session.websocket_peer = websocket_peer
|
||||
}
|
||||
|
||||
func (session *SessionCtx) SetWebSocketConnected(connected bool) {
|
||||
if connected {
|
||||
session.websocket_connected = true
|
||||
session.manager.emmiter.Emit("connected", session)
|
||||
} else {
|
||||
session.websocket_connected = false
|
||||
session.manager.emmiter.Emit("disconnected", session)
|
||||
session.websocket_peer = nil
|
||||
}
|
||||
}
|
||||
|
||||
func (session *SessionCtx) Send(v interface{}) error {
|
||||
if session.websocket_peer == nil {
|
||||
return nil
|
||||
@ -114,6 +130,25 @@ func (session *SessionCtx) Send(v interface{}) error {
|
||||
return session.websocket_peer.Send(v)
|
||||
}
|
||||
|
||||
// ---
|
||||
// webrtc
|
||||
// ---
|
||||
|
||||
func (session *SessionCtx) SetWebRTCPeer(webrtc_peer types.WebRTCPeer) {
|
||||
session.webrtc_peer = webrtc_peer
|
||||
}
|
||||
|
||||
func (session *SessionCtx) SetWebRTCConnected(connected bool) {
|
||||
if connected {
|
||||
session.webrtc_connected = true
|
||||
session.manager.emmiter.Emit("receiving_started", session)
|
||||
} else {
|
||||
session.webrtc_connected = false
|
||||
session.manager.emmiter.Emit("receiving_stopped", session)
|
||||
session.webrtc_peer = nil
|
||||
}
|
||||
}
|
||||
|
||||
func (session *SessionCtx) SignalAnswer(sdp string) error {
|
||||
if session.webrtc_peer == nil {
|
||||
return nil
|
||||
|
@ -3,29 +3,41 @@ package types
|
||||
import "net/http"
|
||||
|
||||
type MemberProfile struct {
|
||||
ID string
|
||||
Secret string
|
||||
Name string
|
||||
|
||||
IsAdmin bool
|
||||
//Enabled bool
|
||||
//CanControl bool
|
||||
//CanWatch bool
|
||||
//ClipboardAccess bool
|
||||
CanLogin bool
|
||||
CanConnect bool
|
||||
CanWatch bool
|
||||
CanHost bool
|
||||
CanAccessClipboard bool
|
||||
}
|
||||
|
||||
type Session interface {
|
||||
ID() string
|
||||
|
||||
VerifySecret(secret string) bool
|
||||
Name() string
|
||||
IsAdmin() bool
|
||||
CanLogin() bool
|
||||
CanConnect() bool
|
||||
CanWatch() bool
|
||||
CanHost() bool
|
||||
CanAccessClipboard() bool
|
||||
SetProfile(profile MemberProfile)
|
||||
|
||||
IsHost() bool
|
||||
IsConnected() bool
|
||||
VerifySecret(secret string) bool
|
||||
IsReceiving() bool
|
||||
Disconnect(reason string) error
|
||||
|
||||
SetWebSocketPeer(websocket_peer WebSocketPeer)
|
||||
SetWebSocketConnected(connected bool)
|
||||
Send(v interface{}) error
|
||||
|
||||
SetWebRTCPeer(webrtc_peer WebRTCPeer)
|
||||
SetWebRTCConnected(connected bool)
|
||||
Disconnect(reason string) error
|
||||
Send(v interface{}) error
|
||||
SignalAnswer(sdp string) error
|
||||
}
|
||||
|
||||
@ -47,8 +59,8 @@ type SessionManager interface {
|
||||
OnHostCleared(listener func(session Session))
|
||||
OnConnected(listener func(session Session))
|
||||
OnDisconnected(listener func(session Session))
|
||||
|
||||
ImplicitHosting() bool
|
||||
|
||||
// auth
|
||||
Authenticate(r *http.Request) (Session, error)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user