sockets

package
v0.0.0-...-ea53bbc Latest Latest
Warning

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

Go to latest
Published: May 28, 2021 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var WebSocketCollections = make(map[string]*Collection)

Functions

func GetUpgrader

func GetUpgrader() *websocket.Upgrader

func LockCollections

func LockCollections()

func ReadSocket

func ReadSocket(connection *Connection, f ...ReadFunc)

func RemoveCollection

func RemoveCollection(name string)

func RemoveCollectionIfEmpty

func RemoveCollectionIfEmpty(name string)

func UnlockCollections

func UnlockCollections()

Types

type Collection

type Collection struct {
	Name string
	// contains filtered or unexported fields
}

func NewCollection

func NewCollection(name string) *Collection

func (*Collection) AddConnection

func (C *Collection) AddConnection(connection *Connection)

func (*Collection) All

func (C *Collection) All() []*Connection

func (*Collection) ConnectionExists

func (C *Collection) ConnectionExists(connection *Connection) bool

func (*Collection) Count

func (C *Collection) Count() int

func (*Collection) GetConnections

func (C *Collection) GetConnections() []*Connection

func (*Collection) GetName

func (C *Collection) GetName() string

func (*Collection) HasRelated

func (C *Collection) HasRelated(key string, values ...interface{}) []*Connection

func (*Collection) HasTag

func (C *Collection) HasTag(tag string) []*Connection

func (*Collection) HasUUID

func (C *Collection) HasUUID(uuid string) []*Connection

func (*Collection) LockUp

func (C *Collection) LockUp()

func (Collection) New

func (C Collection) New() *Collection

func (*Collection) RemoveConnection

func (C *Collection) RemoveConnection(connection *Connection)

func (*Collection) RemoveConnectionByUUID

func (C *Collection) RemoveConnectionByUUID(uuid string)

func (Collection) Send

func (C Collection) Send(messageType int, data []byte, connections ...*Connection)

func (Collection) SendCommand

func (C Collection) SendCommand(command *JSONRequest, connections ...*Connection)

func (Collection) SendData

func (C Collection) SendData(data []byte, connections ...*Connection)

func (Collection) SendText

func (C Collection) SendText(data string, connections ...*Connection)

func (*Collection) String

func (C *Collection) String() string

func (*Collection) UUIDExists

func (C *Collection) UUIDExists(uuid string) bool

func (*Collection) Unlock

func (C *Collection) Unlock()

type CollectionInterface

type CollectionInterface interface {
	LockUp()
	Unlock()
	AddConnection(connection *Connection)
	RemoveConnection(connection *Connection)
	RemoveConnectionByUUID(uuid string)
	UUIDExists(uuid string) bool
	ConnectionExists(connection *Connection) bool
	Count() int
	String() string
	GetConnections() []*Connection
	GetName() string
	All() []*Connection
	HasTag(tag string) []*Connection
	HasRelated(key string, values ...interface{}) []*Connection
	HasUUID(uuid string) []*Connection
	SendCommand(command *JSONRequest, connections ...*Connection)
	SendData(data []byte, connections ...*Connection)
	SendText(data string, connections ...*Connection)
	Send(messageType int, data []byte, connections ...*Connection)
}

type CommandRequest

type CommandRequest struct {
	Command string
	Data    string
}

func (*CommandRequest) GetCommand

func (R *CommandRequest) GetCommand() string

func (*CommandRequest) GetData

func (R *CommandRequest) GetData() interface{}

func (*CommandRequest) GetParams

func (R *CommandRequest) GetParams() interface{}

type Connection

type Connection struct {
	Related map[string]interface{}
	Tags    []string
	// contains filtered or unexported fields
}

func (*Connection) Close

func (C *Connection) Close() error

Closes the WebSocket and Removes from collection

func (*Connection) GetCollection

func (C *Connection) GetCollection() *Collection

func (*Connection) GetUUID

func (C *Connection) GetUUID() string

func (Connection) New

func (C Connection) New(socket *websocket.Conn) *Connection

func (*Connection) PeerAddress

func (C *Connection) PeerAddress() net.Addr

Returns the remote network address.

func (*Connection) Ping

func (C *Connection) Ping() error

func (*Connection) Pong

func (C *Connection) Pong(v interface{}) error

func (*Connection) ReadMessage

func (C *Connection) ReadMessage() (messageType int, p []byte, err error)

func (*Connection) SetCollection

func (C *Connection) SetCollection(collection *Collection)

func (*Connection) SetUUID

func (C *Connection) SetUUID(uuid string)

func (*Connection) String

func (C *Connection) String() string

func (*Connection) SwapTags

func (C *Connection) SwapTags(from []string, to []string) ([]string, error)

func (*Connection) WriteMessage

func (C *Connection) WriteMessage(messageType int, data []byte) error

type JSONRequest

type JSONRequest struct {
	Command string
	Data    map[string]interface{}
	Params  map[string]interface{}
}

func (*JSONRequest) GetCommand

func (R *JSONRequest) GetCommand() string

func (*JSONRequest) GetData

func (R *JSONRequest) GetData() interface{}

func (*JSONRequest) GetParams

func (R *JSONRequest) GetParams() interface{}

func (JSONRequest) New

func (R JSONRequest) New() *JSONRequest

type ReadFunc

type ReadFunc = func(*Connection, []byte)

type Request

type Request interface {
	GetCommand() string
	GetData() interface{}
	GetParams() interface{}
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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