Documentation
¶
Index ¶
- func AfterInited(f func(Session))
- func BeforeClosed(f func(Session))
- func CloseAll()
- func OnAfterSessionBind(f func(ctx context.Context, s Session) error)
- func OnClosed(f func(Session))
- func OnInited(f func(Session))
- func OnSessionBind(f func(ctx context.Context, s Session) error)
- func OnSessionClose(f func(s Session))
- func OnSessionClosed(s Session)
- func OnSessionInited(s Session)
- type HandshakeClientData
- type HandshakeData
- type Session
- type SessionPool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AfterInited ¶
func AfterInited(f func(Session))
AfterInited set a func that will be called after session inited
func BeforeClosed ¶
func BeforeClosed(f func(Session))
BeforeClosed set a func that will be called before session closed
func OnAfterSessionBind ¶
OnAfterSessionBind adds a method to be called when session is bound and after all sessionBind callbacks
func OnClosed ¶
func OnClosed(f func(Session))
OnClosed set a func that will be called on session closed
func OnInited ¶
func OnInited(f func(Session))
OnInited set a func that will be called on session inited
func OnSessionBind ¶
OnSessionBind adds a method to be called when a session is bound same function cannot be added twice!
func OnSessionClose ¶
func OnSessionClose(f func(s Session))
OnSessionClose adds a method that will be called when every session closes
func OnSessionClosed ¶
func OnSessionClosed(s Session)
Closed call all funcs that was registered by OnClosed
func OnSessionInited ¶
func OnSessionInited(s Session)
Inited call all funcs that was registerd by OnInited
Types ¶
type HandshakeClientData ¶
type HandshakeClientData struct { Platform string `json:"platform"` LibVersion string `json:"libVersion"` BuildNumber string `json:"clientBuildNumber"` Version string `json:"clientVersion"` }
HandshakeClientData represents information about the client sent on the handshake.
type HandshakeData ¶
type HandshakeData struct { Sys HandshakeClientData `json:"sys"` User map[string]interface{} `json:"user,omitempty"` }
HandshakeData represents information about the handshake sent by the client. `sys` corresponds to information independent from the app and `user` information that depends on the app and is customized by the user.
type Session ¶
type Session interface { GetOnCloseCallbacks() []func() GetIsFrontend() bool GetSubscriptions() []*nats.Subscription SetOnCloseCallbacks(callbacks []func()) SetIsFrontend(isFrontend bool) SetSubscriptions(subscriptions []*nats.Subscription) Push(route string, v interface{}) error ResponseMID(ctx context.Context, mid uint, v interface{}, err ...bool) error ID() int64 UID() string GetData() map[string]interface{} SetData(data map[string]interface{}) error GetDataEncoded() []byte SetDataEncoded(encodedData []byte) error SetFrontendData(frontendID string, frontendSessionID int64) Bind(ctx context.Context, uid string) error Kick(ctx context.Context) error OnClose(c func()) error Close() RemoteAddr() net.Addr Remove(key string) error Set(key string, value interface{}) error HasKey(key string) bool Get(key string) interface{} Int(key string) int Int8(key string) int8 Int16(key string) int16 Int32(key string) int32 Int64(key string) int64 Uint(key string) uint Uint8(key string) uint8 Uint16(key string) uint16 Uint32(key string) uint32 Uint64(key string) uint64 Float32(key string) float32 Float64(key string) float64 String(key string) string Value(key string) interface{} PushToFront(ctx context.Context) error Clear() SetHandshakeData(data *HandshakeData) GetHandshakeData() *HandshakeData }
Session represents a client session, which can store data during the connection. All data is released when the low-level connection is broken. Session instance related to the client will be passed to Handler method in the context parameter.
func GetSessionByID ¶
GetSessionByID return a session bound to a frontend server id
func GetSessionByUID ¶
GetSessionByUID return a session bound to an user id
type SessionPool ¶
type SessionPool interface { NewSession(entity networkentity.NetworkEntity, frontend bool, UID ...string) Session GetSessionCount() int64 GetSessionCloseCallbacks() []func(s Session) GetSessionByUID(uid string) Session GetSessionByID(id int64) Session OnSessionBind(f func(ctx context.Context, s Session) error) OnAfterSessionBind(f func(ctx context.Context, s Session) error) OnSessionClose(f func(s Session)) CloseAll() }
SessionPool centralizes all sessions within a Pitaya app
var DefaultSessionPool SessionPool
func NewSessionPool ¶
func NewSessionPool() SessionPool
NewSessionPool returns a new session pool instance