Documentation ¶
Index ¶
- Constants
- type Channel
- func (c *Channel) FindContext(clientId string, path string) (*Context, bool)
- func (c *Channel) HandleMessage(client *Client, message *Message)
- func (c *Channel) IsSubscribed(clientId string, path string) bool
- func (c *Channel) PathMatches(path string) (bool, map[string]string)
- func (c *Channel) Subscribe(context *Context)
- func (c *Channel) Unsubscribe(clientId string, path string) bool
- func (c *Channel) UnsubscribeAllPaths(clientId string) bool
- type ChannelHandlers
- type ChannelStore
- func (s *ChannelStore) Get(path string) (bool, *Channel, map[string]string)
- func (s *ChannelStore) OnMessage(client *Client, message *Message)
- func (s *ChannelStore) Register(path string, handlers ChannelHandlers) *Channel
- func (s *ChannelStore) Subscribe(client *Client, channelPath string) bool
- func (s *ChannelStore) Unsubscribe(clientId string, channelPath string) bool
- func (s *ChannelStore) UnsubscribeAll(clientId string)
- type ChannelSubscribers
- func (subs *ChannelSubscribers) Add(context *Context)
- func (subs *ChannelSubscribers) GetContext(clientId string, path string) (*Context, bool)
- func (subs *ChannelSubscribers) IsSubscribed(clientId string, path string) bool
- func (subs *ChannelSubscribers) Remove(clientId string, path string)
- func (subs *ChannelSubscribers) RemoveAllPaths(clientId string) []*Context
- type Client
- type ClientStore
- type ConnectHookFunc
- type Connector
- type Context
- func (context *Context) Get(key string) (value interface{}, exists bool)
- func (context *Context) Param(key string) string
- func (context *Context) Send(payload []byte) error
- func (context *Context) SendError(error *Error) error
- func (context *Context) Set(key string, value interface{})
- func (context *Context) SetParams(params map[string]string)
- type DisconnectHookFunc
- type Error
- type EventHandlerFunc
- type Hooks
- type Message
- type MessageHandlerFunc
- type MessageHookFunc
- type MessageSendFunc
- type Realtime
- func (r *Realtime) HandleRequest(writer http.ResponseWriter, request *http.Request, ...) error
- func (r *Realtime) IsConnected(clientId string) bool
- func (r *Realtime) IsSubscribed(channelPath string, clientId string) bool
- func (r *Realtime) RegisterChannel(channelName string, handlers ChannelHandlers) *Channel
- func (r *Realtime) Send(channelPath string, clientId string, payload []byte) error
- type RequestHandlerFunc
- type SubscriptionMiddleware
Constants ¶
const ( MessageTypeSubscribe = "subscribe" MessageTypeUnsubscribe = "unsubscribe" MessageTypeChannelMessage = "message" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Channel ¶
type Channel struct {
// contains filtered or unexported fields
}
Channel describes a room, websocket users can subscribe and sent messages to.
func (*Channel) FindContext ¶
func (*Channel) HandleMessage ¶
HandleMessage executes the channels OnMessage method if it exists.
func (*Channel) IsSubscribed ¶
IsSubscribed returns true if the client is connected to the channel
func (*Channel) PathMatches ¶
PathMatches returns true and the params of the channel subscription if the path matches the path of the Channel.
func (*Channel) Subscribe ¶
Subscribe executes the Channels middlewares and(if successful) adds the user to the Channel and executes the channels OnSubscribe handler.
func (*Channel) Unsubscribe ¶
Unsubscribe removes the client from the channel and executes the OnUnsubscribe handler
func (*Channel) UnsubscribeAllPaths ¶
UnsubscribeAllPaths unsubscribes a client from all paths of the channel they are connected to.
type ChannelHandlers ¶
type ChannelHandlers struct { OnSubscribe EventHandlerFunc OnUnsubscribe EventHandlerFunc OnMessage MessageHandlerFunc SubscriptionMiddlewares []SubscriptionMiddleware }
ChannelHandlers contains all handler functions for various events in the Channel.
type ChannelStore ¶
type ChannelStore struct {
// contains filtered or unexported fields
}
ChannelStore stores pointers to all Channels
func (*ChannelStore) OnMessage ¶
func (s *ChannelStore) OnMessage(client *Client, message *Message)
func (*ChannelStore) Register ¶
func (s *ChannelStore) Register(path string, handlers ChannelHandlers) *Channel
func (*ChannelStore) Subscribe ¶
func (s *ChannelStore) Subscribe(client *Client, channelPath string) bool
func (*ChannelStore) Unsubscribe ¶
func (s *ChannelStore) Unsubscribe(clientId string, channelPath string) bool
func (*ChannelStore) UnsubscribeAll ¶
func (s *ChannelStore) UnsubscribeAll(clientId string)
type ChannelSubscribers ¶
type ChannelSubscribers struct {
// contains filtered or unexported fields
}
func (*ChannelSubscribers) Add ¶
func (subs *ChannelSubscribers) Add(context *Context)
func (*ChannelSubscribers) GetContext ¶
func (subs *ChannelSubscribers) GetContext(clientId string, path string) (*Context, bool)
func (*ChannelSubscribers) IsSubscribed ¶
func (subs *ChannelSubscribers) IsSubscribed(clientId string, path string) bool
func (*ChannelSubscribers) Remove ¶
func (subs *ChannelSubscribers) Remove(clientId string, path string)
func (*ChannelSubscribers) RemoveAllPaths ¶
func (subs *ChannelSubscribers) RemoveAllPaths(clientId string) []*Context
type Client ¶
type Client struct { Id string // contains filtered or unexported fields }
func NewClient ¶
func NewClient(sendMessage MessageSendFunc, properties map[string]interface{}) *Client
type ClientStore ¶
type ClientStore struct {
// contains filtered or unexported fields
}
func (*ClientStore) Exists ¶
func (c *ClientStore) Exists(id string) bool
func (*ClientStore) Get ¶
func (c *ClientStore) Get(id string) *Client
func (*ClientStore) Join ¶
func (c *ClientStore) Join(client *Client)
func (*ClientStore) NextId ¶
func (c *ClientStore) NextId() string
func (*ClientStore) Remove ¶
func (c *ClientStore) Remove(id string)
type ConnectHookFunc ¶
type ConnectHookFunc func(*Client)
type Connector ¶
type Connector struct {
// contains filtered or unexported fields
}
func NewConnector ¶
func NewConnector(requestHandler RequestHandlerFunc) *Connector
type DisconnectHookFunc ¶
type DisconnectHookFunc func(*Client)
type EventHandlerFunc ¶
type EventHandlerFunc func(s *Context)
EventHandlerFunc is a function that is executed when subscribing or unsubscribing to the Channel.
type Hooks ¶
type Hooks struct { OnConnect ConnectHookFunc OnDisconnect DisconnectHookFunc OnMessage MessageHookFunc }
type Message ¶
type Message struct { Type string `json:"type"` Channel string `json:"channel"` Payload json.RawMessage `json:"payload"` }
type MessageHandlerFunc ¶
MessageHandlerFunc is a function that executes when a message is sent to the Channel.
type MessageHookFunc ¶
type MessageSendFunc ¶
type Realtime ¶
type Realtime struct {
// contains filtered or unexported fields
}
func (*Realtime) HandleRequest ¶
func (r *Realtime) HandleRequest(writer http.ResponseWriter, request *http.Request, properties map[string]interface{}) error
HandleRequest handles a new websocket request, adds the properties to the new client
func (*Realtime) IsConnected ¶
func (*Realtime) IsSubscribed ¶
IsSubscribed checks whether a client is subscribed to a certain channelPath or not
func (*Realtime) RegisterChannel ¶
func (r *Realtime) RegisterChannel(channelName string, handlers ChannelHandlers) *Channel
RegisterChannel registers a new channel
type RequestHandlerFunc ¶
type SubscriptionMiddleware ¶
SubscriptionMiddleware is a function that is executed when a client connects to a Channel. If the middleware returns a non nil Error, the subscription won't be finished.