socket

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2022 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NAMESPACE_RESERVED_EVENTS = types.NewSet("connect", "connection", "new_namespace")
View Source
var (
	SOCKET_RESERVED_EVENTS = types.NewSet("connect", "connect_error", "disconnect", "disconnecting", "newListener", "removeListener")
)

Functions

This section is empty.

Types

type Adapter

type Adapter interface {
	New(NamespaceInterface) Adapter

	Rooms() *sync.Map
	Sids() *sync.Map
	Nsp() NamespaceInterface

	// To be overridden
	Init()

	// To be overridden
	Close()

	// Returns the number of Socket.IO servers in the cluster
	ServerCount() int64

	// Adds a socket to a list of room.
	AddAll(string, *types.Set)

	// Removes a socket from a room.
	Del(string, string)

	// Removes a socket from all rooms it's joined.
	DelAll(string)

	SetBroadcast(func(*parser.Packet, *BroadcastOptions))
	// Broadcasts a packet.
	//
	// Options:
	//  - `Flags` {*BroadcastFlags} flags for this packet
	//  - `Except` {*types.Set[Room]} sids that should be excluded
	//  - `Rooms` {*types.Set[Room]} list of rooms to broadcast to
	Broadcast(*parser.Packet, *BroadcastOptions)

	// Broadcasts a packet and expects multiple acknowledgements.
	//
	// Options:
	//  - `Flags` {*BroadcastFlags} flags for this packet
	//  - `Except` {*types.Set[Room]} sids that should be excluded
	//  - `Rooms` {*types.Set[Room]} list of rooms to broadcast to
	BroadcastWithAck(*parser.Packet, *BroadcastOptions, func(uint64), func(...interface{}))

	// Gets a list of sockets by sid.
	Sockets(*types.Set) *types.Set

	// Gets the list of rooms a given socket has joined.
	SocketRooms(string) *types.Set

	// Returns the matching socket instances
	FetchSockets(*BroadcastOptions) []interface{}

	// Makes the matching socket instances join the specified rooms
	AddSockets(*BroadcastOptions, []string)

	// Makes the matching socket instances leave the specified rooms
	DelSockets(*BroadcastOptions, []string)

	// Makes the matching socket instances disconnect
	DisconnectSockets(*BroadcastOptions, bool)

	// Send a packet to the other Socket.IO servers in the cluster
	ServerSideEmit(string, ...interface{}) error
}

type BroadcastFlags

type BroadcastFlags struct {
	WriteOptions

	Local     bool
	Broadcast bool
	Binary    bool
	Timeout   *time.Duration
}

type BroadcastOperator

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

func NewBroadcastOperator

func NewBroadcastOperator(adapter Adapter, rooms *types.Set, exceptRooms *types.Set, flags *BroadcastFlags) *BroadcastOperator

func (*BroadcastOperator) AllSockets

func (b *BroadcastOperator) AllSockets() (*types.Set, error)

Gets a list of clients.

func (*BroadcastOperator) Compress

func (b *BroadcastOperator) Compress(compress bool) *BroadcastOperator

Sets the compress flag.

func (*BroadcastOperator) DisconnectSockets

func (b *BroadcastOperator) DisconnectSockets(status bool)

Makes the matching socket instances disconnect

func (*BroadcastOperator) Emit

func (b *BroadcastOperator) Emit(ev string, args ...interface{}) error

Emits to all clients.

func (*BroadcastOperator) Except

func (b *BroadcastOperator) Except(room ...string) *BroadcastOperator

Excludes a room when emitting.

func (*BroadcastOperator) FetchSockets

func (b *BroadcastOperator) FetchSockets() (remoteSockets []*RemoteSocket)

Returns the matching socket instances

func (*BroadcastOperator) In

func (b *BroadcastOperator) In(room ...string) *BroadcastOperator

Targets a room when emitting.

func (*BroadcastOperator) Local

Sets a modifier for a subsequent event emission that the event data will only be broadcast to the current node.

func (*BroadcastOperator) SocketsJoin

func (b *BroadcastOperator) SocketsJoin(room ...string)

Makes the matching socket instances join the specified rooms

func (*BroadcastOperator) SocketsLeave

func (b *BroadcastOperator) SocketsLeave(room ...string)

Makes the matching socket instances leave the specified rooms

func (*BroadcastOperator) Timeout

func (b *BroadcastOperator) Timeout(timeout time.Duration) *BroadcastOperator

Adds a timeout in milliseconds for the next operation

<pre><code>

io.Timeout(1000 * time.Millisecond).Emit("some-event", func(args ...any) {
  // ...
});

</pre></code>

func (*BroadcastOperator) To

func (b *BroadcastOperator) To(room ...string) *BroadcastOperator

Targets a room when emitting.

func (*BroadcastOperator) Volatile

func (b *BroadcastOperator) Volatile() *BroadcastOperator

Sets a modifier for a subsequent event emission that the event data may be lost if the client is not ready to receive messages (because of network slowness or other issues, or because they’re connected through long polling and is in the middle of a request-response cycle).

type BroadcastOptions

type BroadcastOptions struct {
	Rooms  *types.Set
	Except *types.Set
	Flags  *BroadcastFlags
}

type Client

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

func NewClient

func NewClient(server *Server, conn engine.Socket) *Client

Client constructor.

func (*Client) Conn

func (c *Client) Conn() engine.Socket

func (*Client) Request

func (c *Client) Request() *types.HttpContext

func (*Client) WriteToEngine

func (c *Client) WriteToEngine(encodedPackets []types.BufferInterface, opts *WriteOptions)

type ExtendedError

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

func NewExtendedError

func NewExtendedError(message string, data interface{}) *ExtendedError

func (*ExtendedError) Data

func (e *ExtendedError) Data() interface{}

func (*ExtendedError) Err

func (e *ExtendedError) Err() error

func (*ExtendedError) Error

func (e *ExtendedError) Error() string

type Handshake

type Handshake struct {
	// The headers sent as part of the handshake
	Headers *utils.ParameterBag
	// The date of creation (as string)
	Time string
	// The ip of the client
	Address string
	// Whether the connection is cross-domain
	Xdomain bool
	// Whether the connection is secure
	Secure bool
	// The date of creation (as unix timestamp)
	Issued int64
	// The request URL string
	Url string
	// The query object
	Query *utils.ParameterBag
	// The auth object
	Auth interface{}
}

type Namespace

type Namespace struct {
	*StrictEventEmitter
	// contains filtered or unexported fields
}

func NewNamespace

func NewNamespace(server *Server, name string) *Namespace

Namespace constructor.

func (*Namespace) Adapter

func (n *Namespace) Adapter() Adapter

func (*Namespace) Add

func (n *Namespace) Add(client *Client, query interface{}, fn func(*Socket)) *Socket

Adds a new client.

func (*Namespace) AllSockets

func (n *Namespace) AllSockets() (*types.Set, error)

Gets a list of clients.

func (*Namespace) Compress

func (n *Namespace) Compress(compress bool) *BroadcastOperator

Sets the compress flag.

func (*Namespace) DisconnectSockets

func (n *Namespace) DisconnectSockets(status bool)

Makes the matching socket instances disconnect

func (*Namespace) Emit

func (n *Namespace) Emit(ev string, args ...interface{}) error

Emits to all clients.

func (*Namespace) EventEmitter

func (n *Namespace) EventEmitter() *StrictEventEmitter

func (*Namespace) Except

func (n *Namespace) Except(room ...string) *BroadcastOperator

Excludes a room when emitting.

func (*Namespace) FetchSockets

func (n *Namespace) FetchSockets() ([]*RemoteSocket, error)

Returns the matching socket instances

func (*Namespace) Ids

func (n *Namespace) Ids() uint64

func (*Namespace) In

func (n *Namespace) In(room ...string) *BroadcastOperator

Targets a room when emitting.

func (*Namespace) Local

func (n *Namespace) Local() *BroadcastOperator

Sets a modifier for a subsequent event emission that the event data will only be broadcast to the current node.

func (*Namespace) Name

func (n *Namespace) Name() string

func (*Namespace) Send

func (n *Namespace) Send(args ...interface{}) NamespaceInterface

Sends a `message` event to all clients.

func (*Namespace) Server

func (n *Namespace) Server() *Server

func (*Namespace) ServerSideEmit

func (n *Namespace) ServerSideEmit(ev string, args ...interface{}) error

Emit a packet to other Socket.IO servers

func (*Namespace) Sockets

func (n *Namespace) Sockets() *sync.Map

func (*Namespace) SocketsJoin

func (n *Namespace) SocketsJoin(room ...string)

Makes the matching socket instances join the specified rooms

func (*Namespace) SocketsLeave

func (n *Namespace) SocketsLeave(room ...string)

Makes the matching socket instances leave the specified rooms

func (*Namespace) Timeout

func (n *Namespace) Timeout(timeout time.Duration) *BroadcastOperator

Adds a timeout in milliseconds for the next operation

<pre><code>

io.Timeout(1000 * time.Millisecond).Emit("some-event", func(args ...any) {
  // ...
});

</pre></code>

func (*Namespace) To

func (n *Namespace) To(room ...string) *BroadcastOperator

Targets a room when emitting.

func (*Namespace) Use

func (n *Namespace) Use(fn func(*Socket, func(*ExtendedError))) NamespaceInterface

Sets up namespace middleware.

func (*Namespace) Volatile

func (n *Namespace) Volatile() *BroadcastOperator

Sets a modifier for a subsequent event emission that the event data may be lost if the client is not ready to receive messages (because of network slowness or other issues, or because they’re connected through long polling and is in the middle of a request-response cycle).

func (*Namespace) Write

func (n *Namespace) Write(args ...interface{}) NamespaceInterface

Sends a `message` event to all clients.

type NamespaceInterface

type NamespaceInterface interface {
	EventEmitter() *StrictEventEmitter

	On(string, ...events.Listener) error
	Once(string, ...events.Listener) error
	EmitReserved(string, ...interface{})
	EmitUntyped(string, ...interface{})
	Listeners(string) []events.Listener

	Sockets() *sync.Map
	Server() *Server
	Adapter() Adapter
	Name() string
	Ids() uint64

	// Sets up namespace middleware.
	Use(func(*Socket, func(*ExtendedError))) NamespaceInterface

	// Targets a room when emitting.
	To(...string) *BroadcastOperator

	// Targets a room when emitting.
	In(...string) *BroadcastOperator

	// Excludes a room when emitting.
	Except(...string) *BroadcastOperator

	// Adds a new client.
	Add(*Client, interface{}, func(*Socket)) *Socket

	// Emits to all clients.
	Emit(string, ...interface{}) error

	// Sends a `message` event to all clients.
	Send(...interface{}) NamespaceInterface

	// Sends a `message` event to all clients.
	Write(...interface{}) NamespaceInterface

	// Emit a packet to other Socket.IO servers
	ServerSideEmit(string, ...interface{}) error

	// Gets a list of clients.
	AllSockets() (*types.Set, error)

	// Sets the compress flag.
	Compress(bool) *BroadcastOperator

	// Sets a modifier for a subsequent event emission that the event data may be lost if the client is not ready to
	// receive messages (because of network slowness or other issues, or because they’re connected through long polling
	// and is in the middle of a request-response cycle).
	Volatile() *BroadcastOperator

	// Sets a modifier for a subsequent event emission that the event data will only be broadcast to the current node.
	Local() *BroadcastOperator

	// Adds a timeout in milliseconds for the next operation
	//
	// <pre><code>
	//
	// io.Timeout(1000 * time.Millisecond).Emit("some-event", func(args ...any) {
	//   // ...
	// });
	//
	// </pre></code>
	Timeout(time.Duration) *BroadcastOperator

	// Returns the matching socket instances
	FetchSockets() ([]*RemoteSocket, error)

	// Makes the matching socket instances join the specified rooms
	SocketsJoin(...string)

	// Makes the matching socket instances leave the specified rooms
	SocketsLeave(...string)

	// Makes the matching socket instances disconnect
	DisconnectSockets(bool)
}

type ParentNamespace

type ParentNamespace struct {
	*Namespace
	// contains filtered or unexported fields
}

func NewParentNamespace

func NewParentNamespace(server *Server) *ParentNamespace

func (*ParentNamespace) CreateChild

func (p *ParentNamespace) CreateChild(name string) *Namespace

func (*ParentNamespace) Emit

func (p *ParentNamespace) Emit(ev string, args ...interface{}) error

func (*ParentNamespace) FetchSockets

func (p *ParentNamespace) FetchSockets() ([]*RemoteSocket, error)

type ParentNspNameMatchFn

type ParentNspNameMatchFn *func(string, interface{}, func(error, bool))

type RemoteSocket

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

func NewRemoteSocket

func NewRemoteSocket(adapter Adapter, details SocketDetails) *RemoteSocket

func (*RemoteSocket) Data

func (r *RemoteSocket) Data() interface{}

func (*RemoteSocket) Disconnect

func (r *RemoteSocket) Disconnect(status bool) *RemoteSocket

Disconnects this client.

func (*RemoteSocket) Emit

func (r *RemoteSocket) Emit(ev string, args ...interface{}) error

func (*RemoteSocket) Handshake

func (r *RemoteSocket) Handshake() *Handshake

func (*RemoteSocket) Id

func (r *RemoteSocket) Id() string

func (*RemoteSocket) Join

func (r *RemoteSocket) Join(room ...string)

Joins a room.

func (*RemoteSocket) Leave

func (r *RemoteSocket) Leave(room ...string)

Leaves a room.

func (*RemoteSocket) Rooms

func (r *RemoteSocket) Rooms() *types.Set

type Server

type Server struct {
	*StrictEventEmitter
	// contains filtered or unexported fields
}

func NewServer

func NewServer(srv interface{}, opts *ServerOptions) *Server

func (*Server) Adapter

func (s *Server) Adapter() Adapter

func (*Server) AllSockets

func (s *Server) AllSockets() (*types.Set, error)

Gets a list of socket ids.

func (*Server) Attach

func (s *Server) Attach(srv interface{}, opts *ServerOptions) *Server

Attaches socket.io to a server or port.

func (*Server) Bind

func (s *Server) Bind(egs engine.Server) *Server

Binds socket.io to an github.com/edelbrocken/engine.io instance.

func (*Server) Close

func (s *Server) Close(fn func())

Closes server connection

func (*Server) Compress

func (s *Server) Compress(compress bool) *BroadcastOperator

Sets the compress flag.

func (*Server) ConnectTimeout

func (s *Server) ConnectTimeout() time.Duration

func (*Server) DisconnectSockets

func (s *Server) DisconnectSockets(status bool)

Makes the matching socket instances disconnect

func (*Server) Encoder

func (s *Server) Encoder() parser.Encoder

func (*Server) Engine

func (s *Server) Engine() engine.Server

func (*Server) Except

func (s *Server) Except(room ...string) *BroadcastOperator

Excludes a room when emitting.

func (*Server) FetchSockets

func (s *Server) FetchSockets() ([]*RemoteSocket, error)

Returns the matching socket instances

func (*Server) In

func (s *Server) In(room ...string) *BroadcastOperator

Targets a room when emitting.

func (*Server) Listen

func (s *Server) Listen(srv interface{}, opts *ServerOptions) *Server

Attaches socket.io to a server or port.

func (*Server) Local

func (s *Server) Local() *BroadcastOperator

Sets a modifier for a subsequent event emission that the event data will only be broadcast to the current node.

func (*Server) Of

func (s *Server) Of(name interface{}, fn func(...interface{})) NamespaceInterface

Looks up a namespace.

func (*Server) Path

func (s *Server) Path() string

func (*Server) Send

func (s *Server) Send(args ...interface{}) *Server

Sends a `message` event to all clients.

func (*Server) ServeClient

func (s *Server) ServeClient() bool

func (*Server) ServeHandler

func (s *Server) ServeHandler(opts *ServerOptions) http.Handler

func (*Server) ServerSideEmit

func (s *Server) ServerSideEmit(ev string, args ...interface{}) error

Emit a packet to other Socket.IO servers

func (*Server) SetAdapter

func (s *Server) SetAdapter(v Adapter) *Server

Sets the adapter for rooms.

func (*Server) SetConnectTimeout

func (s *Server) SetConnectTimeout(v time.Duration) *Server

Set the delay after which a client without namespace is closed

func (*Server) SetPath

func (s *Server) SetPath(v string) *Server

Sets the client serving path.

func (*Server) SetServeClient

func (s *Server) SetServeClient(v bool) *Server

Sets/gets whether client code is being served.

func (*Server) Sockets

func (s *Server) Sockets() NamespaceInterface

func (*Server) SocketsJoin

func (s *Server) SocketsJoin(room ...string)

Makes the matching socket instances join the specified rooms

func (*Server) SocketsLeave

func (s *Server) SocketsLeave(room ...string)

Makes the matching socket instances leave the specified rooms

func (*Server) Timeout

func (s *Server) Timeout(timeout time.Duration) *BroadcastOperator

Adds a timeout in milliseconds for the next operation

<pre><code>

io.Timeout(1000 * time.Millisecond).Emit("some-event", func(args ...any) {
  // ...
});

</pre></code>

func (*Server) To

func (s *Server) To(room ...string) *BroadcastOperator

Targets a room when emitting.

func (*Server) Use

func (s *Server) Use(fn func(*Socket, func(*ExtendedError))) *Server

Sets up namespace middleware.

func (*Server) Volatile

func (s *Server) Volatile() *BroadcastOperator

Sets a modifier for a subsequent event emission that the event data may be lost if the client is not ready to receive messages (because of network slowness or other issues, or because they’re connected through long polling and is in the middle of a request-response cycle).

func (*Server) Write

func (s *Server) Write(args ...interface{}) *Server

Sends a `message` event to all clients.

type ServerOptions

type ServerOptions struct {
	config.ServerOptions
	config.AttachOptions
	// contains filtered or unexported fields
}

func DefaultServerOptions

func DefaultServerOptions() *ServerOptions

func (*ServerOptions) Adapter

func (s *ServerOptions) Adapter() Adapter

func (*ServerOptions) Assign

func (*ServerOptions) ConnectTimeout

func (s *ServerOptions) ConnectTimeout() time.Duration

func (*ServerOptions) GetRawAdapter

func (s *ServerOptions) GetRawAdapter() Adapter

func (*ServerOptions) GetRawConnectTimeout

func (s *ServerOptions) GetRawConnectTimeout() *time.Duration

func (*ServerOptions) GetRawParser

func (s *ServerOptions) GetRawParser() parser.Parser

func (*ServerOptions) GetRawServeClient

func (s *ServerOptions) GetRawServeClient() *bool

func (*ServerOptions) Parser

func (s *ServerOptions) Parser() parser.Parser

func (*ServerOptions) Path

func (s *ServerOptions) Path() string

func (*ServerOptions) ServeClient

func (s *ServerOptions) ServeClient() bool

func (*ServerOptions) SetAdapter

func (s *ServerOptions) SetAdapter(adapter Adapter)

func (*ServerOptions) SetConnectTimeout

func (s *ServerOptions) SetConnectTimeout(connectTimeout time.Duration)

func (*ServerOptions) SetParser

func (s *ServerOptions) SetParser(parser parser.Parser)

func (*ServerOptions) SetServeClient

func (s *ServerOptions) SetServeClient(serveClient bool)

type ServerOptionsInterface

type ServerOptionsInterface interface {
	config.ServerOptionsInterface
	config.AttachOptionsInterface

	SetServeClient(serveClient bool)
	GetRawServeClient() *bool
	ServeClient() bool

	SetAdapter(adapter Adapter)
	GetRawAdapter() Adapter
	Adapter() Adapter

	SetParser(parser parser.Parser)
	GetRawParser() parser.Parser
	Parser() parser.Parser

	SetConnectTimeout(connectTimeout time.Duration)
	GetRawConnectTimeout() *time.Duration
	ConnectTimeout() time.Duration
}

type Set

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

func NewSet

func NewSet(keys ...*Namespace) *Set

func (*Set) Add

func (s *Set) Add(keys ...*Namespace) bool

func (*Set) All

func (s *Set) All() map[*Namespace]Void

func (*Set) Clear

func (s *Set) Clear() bool

func (*Set) Delete

func (s *Set) Delete(keys ...*Namespace) bool

func (*Set) Has

func (s *Set) Has(key *Namespace) bool

func (*Set) Keys

func (s *Set) Keys() (list []*Namespace)

func (*Set) Len

func (s *Set) Len() int

type Socket

type Socket struct {
	*StrictEventEmitter
	// contains filtered or unexported fields
}

func NewSocket

func NewSocket(nsp *Namespace, client *Client, auth interface{}) *Socket

func (*Socket) Acks

func (s *Socket) Acks() *sync.Map

func (*Socket) Broadcast

func (s *Socket) Broadcast() *BroadcastOperator

Sets a modifier for a subsequent event emission that the event data will only be broadcast to every sockets but the sender.

func (*Socket) Client

func (s *Socket) Client() *Client

func (*Socket) Compress

func (s *Socket) Compress(compress bool) *Socket

Sets the compress flag.

func (*Socket) Conn

func (s *Socket) Conn() engine.Socket

A reference to the underlying Client transport connection (Engine.IO Socket object).

func (*Socket) Connected

func (s *Socket) Connected() bool

func (*Socket) Data

func (s *Socket) Data() interface{}

func (*Socket) Disconnect

func (s *Socket) Disconnect(status bool) *Socket

Disconnects this client.

func (*Socket) Disconnected

func (s *Socket) Disconnected() bool

Whether the socket is currently disconnected

func (*Socket) Emit

func (s *Socket) Emit(ev string, args ...interface{}) error

Emits to this client.

func (*Socket) Except

func (s *Socket) Except(room ...string) *BroadcastOperator

Excludes a room when broadcasting.

func (*Socket) Handshake

func (s *Socket) Handshake() *Handshake

func (*Socket) Id

func (s *Socket) Id() string

func (*Socket) In

func (s *Socket) In(room ...string) *BroadcastOperator

Targets a room when broadcasting.

func (*Socket) Join

func (s *Socket) Join(rooms ...string)

Joins a room.

func (*Socket) Leave

func (s *Socket) Leave(room string)

Leaves a room.

func (*Socket) ListenersAny

func (s *Socket) ListenersAny() []events.Listener

Returns an array of listeners that are listening for any event that is specified. This array can be manipulated, e.g. to remove listeners.

func (*Socket) ListenersAnyOutgoing

func (s *Socket) ListenersAnyOutgoing() []events.Listener

Returns an array of listeners that are listening for any event that is specified. This array can be manipulated, e.g. to remove listeners.

func (*Socket) Local

func (s *Socket) Local() *BroadcastOperator

Sets a modifier for a subsequent event emission that the event data will only be broadcast to the current node.

func (*Socket) NotifyOutgoingListeners

func (s *Socket) NotifyOutgoingListeners() func(*parser.Packet)

func (*Socket) Nsp

func (s *Socket) Nsp() *Namespace

func (*Socket) OffAny

func (s *Socket) OffAny(listener events.Listener) *Socket

Removes the listener that will be fired when any event is received.

func (*Socket) OffAnyOutgoing

func (s *Socket) OffAnyOutgoing(listener events.Listener) *Socket

Removes the listener that will be fired when any event is emitted.

<pre><code>

handler := func(args ...any) {
  fmt.Println(args)
}

socket.OnAnyOutgoing(handler)

then later socket.OffAnyOutgoing(handler)

</pre></code>

func (*Socket) OnAny

func (s *Socket) OnAny(listener events.Listener) *Socket

Adds a listener that will be fired when any event is received. The event name is passed as the first argument to the callback.

func (*Socket) OnAnyOutgoing

func (s *Socket) OnAnyOutgoing(listener events.Listener) *Socket

Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the callback.

<pre><code>

socket.OnAnyOutgoing(events.Listener {
  fmt.Println(args)
})

</pre></code>

func (*Socket) PrependAny

func (s *Socket) PrependAny(listener events.Listener) *Socket

Adds a listener that will be fired when any event is received. The event name is passed as the first argument to the callback. The listener is added to the beginning of the listeners array.

func (*Socket) PrependAnyOutgoing

func (s *Socket) PrependAnyOutgoing(listener events.Listener) *Socket

Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the callback. The listener is added to the beginning of the listeners array.

<pre><code>

socket.PrependAnyOutgoing(events.Listener {
  fmt.Println(args)
})

</pre></code>

func (*Socket) Request

func (s *Socket) Request() *types.HttpContext

A reference to the request that originated the underlying Engine.IO Socket.

func (*Socket) Rooms

func (s *Socket) Rooms() *types.Set

func (*Socket) Send

func (s *Socket) Send(args ...interface{}) *Socket

Sends a `message` event.

func (*Socket) SetData

func (s *Socket) SetData(data interface{})

func (*Socket) Timeout

func (s *Socket) Timeout(timeout time.Duration) *Socket

Sets a modifier for a subsequent event emission that the callback will be called with an error when the given number of milliseconds have elapsed without an acknowledgement from the client:

```

socket.Timeout(5000 * time.Millisecond).Emit("my-event", func(args ...any) {
  if args[0] != nil {
    // the client did not acknowledge the event in the given delay
  }
})

```

func (*Socket) To

func (s *Socket) To(room ...string) *BroadcastOperator

Targets a room when broadcasting.

func (*Socket) Use

func (s *Socket) Use(fn func([]interface{}, func(error))) *Socket

Sets up socket middleware.

func (*Socket) Volatile

func (s *Socket) Volatile() *Socket

Sets a modifier for a subsequent event emission that the event data may be lost if the client is not ready to receive messages (because of network slowness or other issues, or because they’re connected through long polling and is in the middle of a request-response cycle).

func (*Socket) Write

func (s *Socket) Write(args ...interface{}) *Socket

Sends a `message` event.

type SocketDetails

type SocketDetails interface {
	Id() string
	Handshake() *Handshake
	Rooms() *types.Set
	Data() interface{}
}

type StrictEventEmitter

type StrictEventEmitter struct {
	events.EventEmitter
}

Strictly typed version of an `EventEmitter`. A `TypedEventEmitter` takes type parameters for mappings of event names to event data types, and strictly types method calls to the `EventEmitter` according to these event maps.

func NewStrictEventEmitter

func NewStrictEventEmitter() *StrictEventEmitter

func (*StrictEventEmitter) Emit

func (s *StrictEventEmitter) Emit(ev string, args ...interface{})

Emits an event.

func (*StrictEventEmitter) EmitReserved

func (s *StrictEventEmitter) EmitReserved(ev string, args ...interface{})

Emits a reserved event.

This method is `protected`, so that only a class extending `StrictEventEmitter` can emit its own reserved events.

func (*StrictEventEmitter) EmitUntyped

func (s *StrictEventEmitter) EmitUntyped(ev string, args ...interface{})

Emits an event.

This method is `protected`, so that only a class extending `StrictEventEmitter` can get around the strict typing. This is useful for calling `emit.apply`, which can be called as `emitUntyped.apply`.

func (*StrictEventEmitter) Listeners

func (s *StrictEventEmitter) Listeners(ev string) []events.Listener

Returns the listeners listening to an event.

func (*StrictEventEmitter) On

func (s *StrictEventEmitter) On(ev string, listeners ...events.Listener) error

Adds the `listener` function as an event listener for `ev`.

func (*StrictEventEmitter) Once

func (s *StrictEventEmitter) Once(ev string, listeners ...events.Listener) error

type Void

type Void struct{}
var NULL Void

type WriteOptions

type WriteOptions struct {
	packet.Options

	Volatile     bool
	PreEncoded   bool
	WsPreEncoded string
}

Jump to

Keyboard shortcuts

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