Documentation
¶
Index ¶
- Constants
- Variables
- func DefaultUpgrader() websocket.Upgrader
- func Go(fn func())
- func ServeWs(hub *Hubx, w http.ResponseWriter, r *http.Request, upgrader websocket.Upgrader, ...)
- type BcFilter
- type BcListener
- type Broadcaster
- type Client
- type Hubx
- func (h *Hubx) Broadcast(subject string, data interface{})
- func (h *Hubx) BroadcastMessage() chan<- []byte
- func (h *Hubx) BroadcastWs(subject string, msg interface{})
- func (h *Hubx) Close() chan<- bool
- func (h *Hubx) CloseAsync()
- func (h *Hubx) GetClients() map[*Client]bool
- func (h *Hubx) GetOptions() Options
- func (h *Hubx) IsEmpty() bool
- func (h *Hubx) LocalChan() chan<- interface{}
- func (h *Hubx) On(subject string, cb BcListener)
- func (h *Hubx) OnDefault(cb BcListener)
- func (h *Hubx) OnWs(subject string, cb WsListener)
- func (h *Hubx) OnWsDefault(cb WsListener)
- func (h *Hubx) SendWs(subject string, data interface{}, clients ...*Client)
- func (h *Hubx) SendWsWithCtx(ctx context.Context, subject string, data interface{}, clients ...*Client)
- func (h *Hubx) SetBroadcaster(broadcaster Broadcaster)
- func (h *Hubx) Start()
- func (h *Hubx) Use(filter BcFilter)
- func (h *Hubx) UseWs(filter WsFilter)
- type Logger
- type Message
- type Options
- type PartialMessage
- type RawMessage
- type RedisBroadcaster
- type RedisOptions
- type WsFilter
- type WsListener
Constants ¶
View Source
const ( Trace = 0 Debug = 1 Warn = 2 Error = 3 )
Variables ¶
View Source
var DefaultMarhaller = func(obj interface{}) ([]byte, error) { return json.Marshal(obj) }
View Source
var DefaultUnmarhaller = func(dataBs []byte, obj interface{}) error { return json.Unmarshal(dataBs, obj) }
Functions ¶
func DefaultUpgrader ¶
Types ¶
type BcFilter ¶
type BcFilter func(msg PartialMessage, next func())
BcFilter broadcast message filter
type Broadcaster ¶
type Hubx ¶
type Hubx struct { BcListeners map[string]BcListener // subcribe redis message BeforeJoin func(client *Client) error AfterJoin func(client *Client) BeforeLeave func(client *Client) AfterLeave func(client *Client) AfterClose func() OnLocalMessage func(msg interface{}) Unmarshaller func(dataBs []byte, obj interface{}) error Marshaller func(obj interface{}) ([]byte, error) RawMessageUnmarhaller func(bs []byte) (PartialMessage, error) Ticker func(tickerCount int64) // contains filtered or unexported fields }
func (*Hubx) BroadcastMessage ¶
BroadcastMessage recevie message from network broadcast like redis pubsub
func (*Hubx) BroadcastWs ¶
BroadcastWs send msg to all websocket client
func (*Hubx) CloseAsync ¶
func (h *Hubx) CloseAsync()
func (*Hubx) GetClients ¶ added in v1.0.9
func (*Hubx) GetOptions ¶ added in v1.0.9
func (*Hubx) On ¶
func (h *Hubx) On(subject string, cb BcListener)
On set broadcast message listener
func (*Hubx) OnDefault ¶ added in v1.0.5
func (h *Hubx) OnDefault(cb BcListener)
func (*Hubx) OnWs ¶
func (h *Hubx) OnWs(subject string, cb WsListener)
OnWs set websocket message listener
func (*Hubx) OnWsDefault ¶ added in v1.0.5
func (h *Hubx) OnWsDefault(cb WsListener)
func (*Hubx) SendWsWithCtx ¶
func (h *Hubx) SendWsWithCtx(ctx context.Context, subject string, data interface{}, clients ...*Client)
SendWsWithCtx send msg to specified websocket client with context
func (*Hubx) SetBroadcaster ¶
func (h *Hubx) SetBroadcaster(broadcaster Broadcaster)
SetBroadcast we should set broadcaster before start
type PartialMessage ¶
type PartialMessage struct { Subject string Data json.RawMessage }
func DefaultRawMessageUnmarhaller ¶
func DefaultRawMessageUnmarhaller(bs []byte) (PartialMessage, error)
func (*PartialMessage) Marshal ¶
func (p *PartialMessage) Marshal() ([]byte, error)
func (*PartialMessage) String ¶
func (p *PartialMessage) String() string
func (*PartialMessage) Unmarshal ¶
func (p *PartialMessage) Unmarshal(bs []byte) error
func (*PartialMessage) UnmarshalData ¶
func (p *PartialMessage) UnmarshalData(result interface{}) error
type RawMessage ¶
type RedisBroadcaster ¶
type RedisBroadcaster struct {
// contains filtered or unexported fields
}
func NewRedisBroadcaster ¶
func NewRedisBroadcaster(hub *Hubx, options RedisOptions) (*RedisBroadcaster, error)
func (*RedisBroadcaster) Close ¶
func (r *RedisBroadcaster) Close() chan<- bool
func (*RedisBroadcaster) Send ¶
func (r *RedisBroadcaster) Send() chan<- []byte
func (*RedisBroadcaster) Start ¶
func (r *RedisBroadcaster) Start()
type RedisOptions ¶
type WsFilter ¶
type WsFilter func(client *Client, msg PartialMessage, next func())
WsFilter Websocket message filter
type WsListener ¶
type WsListener func(client *Client, msg PartialMessage)
WsListener Websocket message listener
Click to show internal directories.
Click to hide internal directories.