Documentation ¶
Index ¶
- Constants
- Variables
- type Client
- func (c *Client) BroadcastAll(evt string, data connection.MessageDataCodec)
- func (c *Client) BroadcastAuthRequestTo(seg string)
- func (c *Client) BroadcastChatActionAll(methodName string, args []interface{})
- func (c *Client) BroadcastChatActionFrom(methodName string, args []interface{})
- func (c *Client) BroadcastChatActionTo(methodName string, args []interface{})
- func (c *Client) BroadcastErrorTo(err error)
- func (c *Client) BroadcastFrom(evt string, data connection.MessageDataCodec)
- func (c *Client) BroadcastSystemMessageAll(msg string)
- func (c *Client) BroadcastSystemMessageFrom(msg string)
- func (c *Client) BroadcastSystemMessageTo(msg string)
- func (c *Client) BroadcastTo(evt string, data connection.MessageDataCodec)
- func (c *Client) Connection() connection.Connection
- func (c *Client) Connections() []connection.Connection
- func (c *Client) GetPreviousUsername() (string, bool)
- func (c *Client) GetSourceName() string
- func (c *Client) GetUsername() (string, bool)
- func (c *Client) GetUsernameOrId() string
- func (c *Client) Namespace() (connection.Namespace, bool)
- func (c *Client) Serialize() ([]byte, error)
- func (c *Client) SetNamespace(ns string)
- func (c *Client) UUID() string
- func (c *Client) UnsetNamespace()
- func (c *Client) UpdateUsername(username string) error
- func (c *Client) UsernameEquals(c2 *Client) bool
- func (c *Client) UsernameEqualsPrevious(c2 *Client) bool
- type Handler
- type Response
- type SerializableClient
- type SerializableClientList
- type SocketClientHandler
Constants ¶
const ( MAX_USERNAME_HIST = 2 // max number of usernames per client to store USER_SYSTEM = "system" )
Variables ¶
var RESERVED_USERNAMES = map[string]bool{ "system": true, }
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClient ¶
func NewClient(conn connection.Connection) *Client
New receives a socket.io client connection and creates a new socket client, containing information about a unique socket client connection.
func (*Client) BroadcastAll ¶
func (c *Client) BroadcastAll(evt string, data connection.MessageDataCodec)
func (*Client) BroadcastAuthRequestTo ¶
func (*Client) BroadcastChatActionAll ¶
func (*Client) BroadcastChatActionFrom ¶
func (*Client) BroadcastChatActionTo ¶
func (*Client) BroadcastErrorTo ¶
BroadcastErrorTo broadcasts an error message event to the current client
func (*Client) BroadcastFrom ¶
func (c *Client) BroadcastFrom(evt string, data connection.MessageDataCodec)
func (*Client) BroadcastSystemMessageAll ¶
BroadcastSystemMessageFrom emits a system-level message to the current client as well as the rest of its channel
func (*Client) BroadcastSystemMessageFrom ¶
BroadcastSystemMessageFrom emits a system-level message from the current client to the rest of its channel
func (*Client) BroadcastSystemMessageTo ¶
BroadcastSystemMessageTo emits a system-level message to the current client only
func (*Client) BroadcastTo ¶
func (c *Client) BroadcastTo(evt string, data connection.MessageDataCodec)
func (*Client) Connection ¶
func (c *Client) Connection() connection.Connection
Connection returns the socket connection for the current client
func (*Client) Connections ¶
func (c *Client) Connections() []connection.Connection
Connections returns the socket connections that are in the same namespace as the client
func (*Client) GetPreviousUsername ¶
GetPreviousUsername returns the last active username for a client or a bool (false) if 0 or 1 total usernames have been recorded so far
func (*Client) GetSourceName ¶
GetSourceName retrieves a client's username (if exists) or unique identifier; implements stream.StreamCreationSource
func (*Client) GetUsername ¶
GetUsername returns the currently active username for a client or a bool (false) if client has no username history
func (*Client) GetUsernameOrId ¶
GetUsernameOrId retuens the currently active username for a client or its unique identifier if there is no username history.
func (*Client) Namespace ¶
func (c *Client) Namespace() (connection.Namespace, bool)
Namespace returns the name of the channel / room the socket is currently in, or boolean false if the socket has not been assigned to a room yet
func (*Client) SetNamespace ¶
SetNamespace assigns a client to a channel named after their current fully qualified namespace.
func (*Client) UnsetNamespace ¶
func (c *Client) UnsetNamespace()
func (*Client) UpdateUsername ¶
func (*Client) UsernameEquals ¶
UsernameEquals implements a quick comparison between two clients. ClientA is only equal to ClientB if and only if their currently active username strings match.
func (*Client) UsernameEqualsPrevious ¶
UsernameEqualsPrevious implements a quick comparison between two clients ClientA is only equal to ClientB if and only if ClientA's current username matches ClientB's previously active username.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler implements ClientHandler
func (*Handler) CreateClient ¶
func (h *Handler) CreateClient(socket connection.Connection) *Client
func (*Handler) DestroyClient ¶
func (h *Handler) DestroyClient(socket connection.Connection) error
func (*Handler) GetClientSize ¶
type Response ¶
type Response struct { Id string `json:"id"` IsSystem bool `json:"system"` From string `json:"user"` Message string `json:"message"` ErrMessage string `json:"error"` Extra map[string]interface{} `json:"extra"` }
Response is a serializable schema representing a response to be sent to the client
func ResponseFromClientData ¶
ResponseFromClientData receives a map of keys to empty interface{} and returns a *client.Response object with fields set to values from the received map, for every field whose name or json tag value matched the corresponding map key.
Example:
data = map[string]interface{}{ "commonkey1": "val", "commonkey2": 12345, "uniquekey1": "bob", }
Output:
Response{"val" 12345}
type SerializableClient ¶
type SerializableClient struct { Username string `json:"username"` Id string `json:"id"` Room string `json:"room"` Roles []string `json:"roles"` }
func (*SerializableClient) Serialize ¶
func (s *SerializableClient) Serialize() ([]byte, error)
type SerializableClientList ¶
type SerializableClientList struct {
Clients []SerializableClient `json:"clients"`
}
func (*SerializableClientList) Serialize ¶
func (s *SerializableClientList) Serialize() ([]byte, error)
type SocketClientHandler ¶
type SocketClientHandler interface { // CreateClient receives a socket connection, creates a Client, // and adds it to an internal map. The new created Client is returned. CreateClient(connection.Connection) *Client // DestroyClient receives a socket connection, finds a Client by its id, // removes it from its room (if joined), and deletes the Client from an // internal map. If no client exists by that id, an error is returned. DestroyClient(connection.Connection) error // GetClient receives a client's string id, and returns a Client instance // associated with that id, or an error if no client by that id is found. GetClient(string) (*Client, error) // GetClientSize returns the amount of Client instances saved in the internal map GetClientSize() int // Clients returns a slice of Client instances saved in the internal map Clients() []*Client }
func NewHandler ¶
func NewHandler() SocketClientHandler