client

package
v0.0.0-...-2187358 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MAX_USERNAME_HIST = 2 // max number of usernames per client to store
	USER_SYSTEM       = "system"
)

Variables

View Source
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 (c *Client) BroadcastAuthRequestTo(seg string)

func (*Client) BroadcastChatActionAll

func (c *Client) BroadcastChatActionAll(methodName string, args []interface{})

func (*Client) BroadcastChatActionFrom

func (c *Client) BroadcastChatActionFrom(methodName string, args []interface{})

func (*Client) BroadcastChatActionTo

func (c *Client) BroadcastChatActionTo(methodName string, args []interface{})

func (*Client) BroadcastErrorTo

func (c *Client) BroadcastErrorTo(err error)

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

func (c *Client) BroadcastSystemMessageAll(msg string)

BroadcastSystemMessageFrom emits a system-level message to the current client as well as the rest of its channel

func (*Client) BroadcastSystemMessageFrom

func (c *Client) BroadcastSystemMessageFrom(msg string)

BroadcastSystemMessageFrom emits a system-level message from the current client to the rest of its channel

func (*Client) BroadcastSystemMessageTo

func (c *Client) BroadcastSystemMessageTo(msg string)

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

func (c *Client) GetPreviousUsername() (string, bool)

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

func (c *Client) GetSourceName() string

GetSourceName retrieves a client's username (if exists) or unique identifier; implements stream.StreamCreationSource

func (*Client) GetUsername

func (c *Client) GetUsername() (string, bool)

GetUsername returns the currently active username for a client or a bool (false) if client has no username history

func (*Client) GetUsernameOrId

func (c *Client) GetUsernameOrId() string

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) Serialize

func (c *Client) Serialize() ([]byte, error)

func (*Client) SetNamespace

func (c *Client) SetNamespace(ns string)

SetNamespace assigns a client to a channel named after their current fully qualified namespace.

func (*Client) UUID

func (c *Client) UUID() string

UUID returns the connection id for the socket client

func (*Client) UnsetNamespace

func (c *Client) UnsetNamespace()

func (*Client) UpdateUsername

func (c *Client) UpdateUsername(username string) error

func (*Client) UsernameEquals

func (c *Client) UsernameEquals(c2 *Client) bool

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

func (c *Client) UsernameEqualsPrevious(c2 *Client) bool

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) Clients

func (h *Handler) Clients() []*Client

func (*Handler) CreateClient

func (h *Handler) CreateClient(socket connection.Connection) *Client

func (*Handler) DestroyClient

func (h *Handler) DestroyClient(socket connection.Connection) error

func (*Handler) GetClient

func (h *Handler) GetClient(id string) (*Client, error)

func (*Handler) GetClientSize

func (h *Handler) GetClientSize() int

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

func ResponseFromClientData(data map[string]interface{}) Response

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}

func (*Response) Serialize

func (r *Response) Serialize() ([]byte, error)

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

Jump to

Keyboard shortcuts

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