session

package
v2.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 16, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseAll

func CloseAll()

CloseAll calls Close on all sessions

func OnAfterSessionBind

func OnAfterSessionBind(f func(ctx context.Context, s Session) error)

OnAfterSessionBind adds a method to be called when session is bound and after all sessionBind callbacks

func OnSessionBind

func OnSessionBind(f func(ctx context.Context, s Session) error)

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

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

func GetSessionByID(id int64) Session

GetSessionByID return a session bound to a frontend server id

func GetSessionByUID

func GetSessionByUID(uid string) Session

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

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL