Documentation
¶
Index ¶
- Constants
- type BroadcastSendResult
- type Channel
- func (c *Channel) Broadcast(fullPath string, payload []byte, options *ChannelBroadcastOptions) *ChannelBroadcastResult
- func (c *Channel) FindContext(clientId string, path string) (*Context, bool)
- func (c *Channel) GetAllSubscribers() []*Context
- func (c *Channel) GetSubscribers(path string) []*Context
- 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 ChannelBroadcastOptions
- type ChannelBroadcastResult
- type ChannelHandlers
- type ChannelStore
- func (s *ChannelStore) Get(path string) (bool, *Channel, map[string]string)
- func (s *ChannelStore) GetByExactPath(path string) (bool, *Channel)
- 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) GetAll() []*Context
- func (subs *ChannelSubscribers) GetAllForPath(path string) []*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) Broadcast(payload []byte, options *ContextBroadcastOptions) *ChannelBroadcastResult
- func (context *Context) Get(key string) (value interface{}, exists bool)
- func (context *Context) MustGet(key string) interface{}
- 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 ContextBroadcastOptions
- type DisconnectHookFunc
- type Error
- type ErrorHandlerFunc
- type EventHandlerFunc
- type Hooks
- type Message
- type MessageHandlerFunc
- type MessageHookFunc
- type MessageSendFunc
- type RequestHandlerFunc
- type SubscriptionMiddleware
- type TubeSystem
- func (r *TubeSystem) GetChannel(channelPath string) (bool, *Channel)
- func (r *TubeSystem) HandleRequest(writer http.ResponseWriter, request *http.Request, ...) error
- func (r *TubeSystem) IsConnected(clientId string) bool
- func (r *TubeSystem) IsSubscribed(channelPath string, clientId string) bool
- func (r *TubeSystem) RegisterChannel(channelName string, handlers ChannelHandlers) *Channel
- func (r *TubeSystem) Send(channelPath string, clientId string, payload []byte) *Error
Constants ¶
const ( ErrorInvalidMessage = iota // ErrorInvalidMessage if an incoming message could not be parsed ErrorUnknownType // ErrorUnknownType if a message with an unknown type is received ErrorUnknownChannel // ErrorUnknownChannel if a message to an unknown channel is received or sent ErrorClientNotSubscribed // ErrorClientNotSubscribed if a message is sent through a channel that is not subscribed by the client ErrorSendingErrorFailed // ErrorSendingErrorFailed if a error message could not be send to a client ErrorSendingMessageFailed // ErrorSendingMessageFailed if a message could not be sent to a client )
const ( MessageTypeSubscribe = "subscribe" MessageTypeUnsubscribe = "unsubscribe" MessageTypeChannelMessage = "message" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BroadcastSendResult ¶ added in v0.0.6
type Channel ¶
type Channel struct {
// contains filtered or unexported fields
}
Channel describes a room, websocket users can subscribe and sent messages to.
func (*Channel) Broadcast ¶ added in v0.0.6
func (c *Channel) Broadcast(fullPath string, payload []byte, options *ChannelBroadcastOptions) *ChannelBroadcastResult
func (*Channel) FindContext ¶
func (*Channel) GetAllSubscribers ¶ added in v0.0.3
GetAllSubscribers returns all subscribers
func (*Channel) GetSubscribers ¶ added in v0.0.3
GetSubscribers returns subscribers for the given path
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 ChannelBroadcastOptions ¶ added in v0.0.6
type ChannelBroadcastOptions struct {
SkipClientIds []string
}
type ChannelBroadcastResult ¶ added in v0.0.6
type ChannelBroadcastResult struct {
HasErrors bool
Results []*BroadcastSendResult
}
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) GetByExactPath ¶ added in v0.0.3
func (s *ChannelStore) GetByExactPath(path string) (bool, *Channel)
GetByExactPath finds a channel by its exact path name.
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) GetAll ¶ added in v0.0.3
func (subs *ChannelSubscribers) GetAll() []*Context
func (*ChannelSubscribers) GetAllForPath ¶ added in v0.0.3
func (subs *ChannelSubscribers) GetAllForPath(path string) []*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, errorHandler ErrorHandlerFunc) *Connector
type Context ¶
type Context struct {
Client *Client
FullPath string
Channel *Channel
// contains filtered or unexported fields
}
func (*Context) Broadcast ¶ added in v0.0.6
func (context *Context) Broadcast(payload []byte, options *ContextBroadcastOptions) *ChannelBroadcastResult
type ContextBroadcastOptions ¶ added in v0.0.6
type ContextBroadcastOptions struct {
ExcludeContextOwner bool
}
type DisconnectHookFunc ¶
type DisconnectHookFunc func(*Client)
type Error ¶
type ErrorHandlerFunc ¶
type ErrorHandlerFunc func(*Error)
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 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.
type TubeSystem ¶
type TubeSystem struct {
// contains filtered or unexported fields
}
func (*TubeSystem) GetChannel ¶ added in v0.0.3
func (r *TubeSystem) GetChannel(channelPath string) (bool, *Channel)
GetChannel returns a registered channel for an exact channel path.
func (*TubeSystem) HandleRequest ¶
func (r *TubeSystem) 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 (*TubeSystem) IsConnected ¶
func (r *TubeSystem) IsConnected(clientId string) bool
func (*TubeSystem) IsSubscribed ¶
func (r *TubeSystem) IsSubscribed(channelPath string, clientId string) bool
IsSubscribed checks whether a client is subscribed to a certain channelPath or not
func (*TubeSystem) RegisterChannel ¶
func (r *TubeSystem) RegisterChannel(channelName string, handlers ChannelHandlers) *Channel
RegisterChannel registers a new channel
