socket

package
v1.38.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

README

Socket

We started using https://github.com/graarh/golang-socketio But this is pretty outdated, doesn't have some functionality of latest versions of socket.io (namespaces, auth, latest versions of the protocol)

Currently this is still loosely based on this great and useful upstream repo. We need to separate this out and make a PR to update that upstream repo.

Documentation

Index

Constants

View Source
const (
	OnConnection    = "connection"
	OnDisconnection = "disconnection"
	OnError         = "error"
)
View Source
const (
	HeaderForward = "X-Forwarded-For"
)

Variables

View Source
var (
	ErrorCallerNotFunc     = errors.New("f is not function")
	ErrorCallerNot2Args    = errors.New("f should have 1 or 2 args")
	ErrorCallerMaxOneValue = errors.New("f should return not more than one value")
)
View Source
var (
	ErrorSendTimeout     = errors.New("Timeout")
	ErrorSocketOverflood = errors.New("Socket overflood")
)
View Source
var (
	ErrorServerNotSet       = errors.New("Server not set")
	ErrorConnectionNotFound = errors.New("Connection not found")
)
View Source
var (
	ErrorWaiterNotFound = errors.New("Waiter not found")
)
View Source
var (
	ErrorWrongHeader = errors.New("Wrong header")
)

Functions

func AmountOfOverflooded

func AmountOfOverflooded() int64

func GetUrl

func GetUrl(host string, port int, auth string, secure bool) string

* Get ws/wss url by host and port

Types

type Channel

type Channel struct {
	// contains filtered or unexported fields
}

* socket.io connection handler

use IsAlive to check that handler is still working use Dial to connect to websocket use In and Out channels for message exchange Close message means channel is closed ping is automatic

func (*Channel) Ack

func (c *Channel) Ack(method string, args interface{}, timeout time.Duration) (string, error)

* Create ack packet based on given data and send it and receive response

func (*Channel) Amount

func (c *Channel) Amount(room string) int

* Get amount of channels, joined to given room, using channel

func (*Channel) BroadcastTo

func (c *Channel) BroadcastTo(room, method string, args interface{})

func (*Channel) Close

func (c *Channel) Close()

* Close current channel

func (*Channel) Emit

func (c *Channel) Emit(method string, args interface{}) error

* Create packet based on given data and send it

func (*Channel) Id

func (c *Channel) Id() string

* Get id of current socket connection

func (*Channel) Ip

func (c *Channel) Ip() string

* Get ip of socket client

func (*Channel) IsAlive

func (c *Channel) IsAlive() bool

* Checks that Channel is still alive

func (*Channel) Join

func (c *Channel) Join(room string) error

* Join this channel to given room

func (*Channel) Leave

func (c *Channel) Leave(room string) error

* Remove this channel from given room

func (*Channel) List

func (c *Channel) List(room string) []*Channel

* Get list of channels, joined to given room, using channel

func (*Channel) RequestHeader

func (c *Channel) RequestHeader() http.Header

* Get request header of this connection

func (*Channel) RequestURL

func (c *Channel) RequestURL() *url.URL

* Get request url of this connection

type Client

type Client struct {
	Channel
	// contains filtered or unexported fields
}

* Socket.io client representation

func NewClient

func NewClient() *Client

func (*Client) Close

func (c *Client) Close()

* Close client connection

func (*Client) Dial

func (c *Client) Dial(url string, tr transport.Transport) error

* connect to host and initialise socket.io protocol

The correct ws protocol url example: ws://myserver.com/socket.io/?EIO=3&transport=websocket

You can use GetUrlByHost for generating correct url

func (*Client) On

func (m *Client) On(method string, f interface{}) error

* Add message processing function, and bind it to given method

type Header struct {
	Sid          string   `json:"sid"`
	Upgrades     []string `json:"upgrades"`
	PingInterval int      `json:"pingInterval"`
	PingTimeout  int      `json:"pingTimeout"`
}

* engine.io header to send or receive

type Server

type Server struct {
	http.Handler
	// contains filtered or unexported fields
}

* socket.io server instance

func NewServer

func NewServer(tr transport.Transport) *Server

* Create new socket.io server

func (*Server) Amount

func (s *Server) Amount(room string) int

* Get amount of channels, joined to given room, using server

func (*Server) AmountOfRooms

func (s *Server) AmountOfRooms() int64

* Get amount of rooms with at least one channel(or sid) joined

func (*Server) AmountOfSids

func (s *Server) AmountOfSids() int64

* Get amount of current connected sids

func (*Server) BroadcastTo

func (s *Server) BroadcastTo(room, method string, args interface{})

* Broadcast message to all room channels

func (*Server) BroadcastToAll

func (s *Server) BroadcastToAll(method string, args interface{})

* Broadcast to all clients

func (*Server) GetChannel

func (s *Server) GetChannel(sid string) (*Channel, error)

* Get channel by it's sid

func (*Server) List

func (s *Server) List(room string) []*Channel

* Get list of channels, joined to given room, using server

func (*Server) On

func (m *Server) On(method string, f interface{}) error

* Add message processing function, and bind it to given method

func (*Server) SendOpenSequence

func (s *Server) SendOpenSequence(c *Channel)

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

* implements ServeHTTP function from http.Handler

func (*Server) SetupEventLoop

func (s *Server) SetupEventLoop(conn transport.Connection, remoteAddr string,
	requestHeader http.Header, requestURL *url.URL)

* Setup event loop for given connection

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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