Documentation ¶
Index ¶
- Constants
- Variables
- type ClientSocket
- type Emitter
- type EventHandler
- type Handler
- type Namespace
- type Packet
- type PacketHandler
- type Room
- type Server
- func (ns Server) Emit(event string, args ...interface{}) error
- func (ns Server) Name() string
- func (s *Server) Of(name string) Namespace
- func (ns Server) On(event string, fn interface{}) error
- func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (ns Server) To(room string) Emitter
- type Socket
- type Transport
Constants ¶
const Connection = "connection"
const Disconnect = "disconnect"
const Disconnection = "disconnection"
Variables ¶
var ErrNotSocketFunc = errors.New("connection/disconnection must take fn of type func(Socket)")
Functions ¶
This section is empty.
Types ¶
type ClientSocket ¶
type ClientSocket interface { // ID() is this sockets unique identifier ID() string // Namespace() is the namespace this socket is a part of Namespace() string // On will register an function to handle events sent // from the other end of the socket EventHandler // Emit will send an event to the other end of the socket Emitter // Close the underlying Transport Close() error }
ClientSocket creates a client-side Socket
func New ¶
func New(url string) (ClientSocket, error)
type Emitter ¶
Emitter handles sending messages. Emit sends an event and args which will be handled by the func registered via socket.on.
type EventHandler ¶
EventHandler registers a function to be run when an event is received. The arguments to the function will be unmarshalled from the javascript objects emitted by the client-side socket.
type Handler ¶
type Handler interface { EventHandler PacketHandler }
Handler is both a PacketHandler and a EventHandler
type Namespace ¶
type Namespace interface { // Name returns this namespace's name Name() string // To emits to a room To(room string) Emitter // On will register a function on an event EventHandler // Emit will broadcast to the namespace Emitter }
Namespace is used to multiplex a single Transport and allow independent sockets within a single connection.
type Packet ¶
type Packet interface { Namespace() string Socket() string Event() string DecodeArgs(args ...interface{}) }
Packet is used to receive a sent event and decode the javascript objects into a functions arguments
type PacketHandler ¶
type PacketHandler interface {
OnPacket(Packet)
}
PacketHandler responds to a Packet
type Room ¶
type Room interface { // Name returns the room name Name() string // Size returns the # of sockets in the room Size() int // Join adds a socket to the Room Join(so Socket) // Leave removes a socket from the Room Leave(so Socket) // Emit sends to all members of the room Emitter }
Room is a collection of Sockets
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server handles creating Sockets from http connections
func (*Server) Of ¶
Of creates a new Namespace with "name", or returns the existing Namespace with name "name"
type Socket ¶
type Socket interface { ClientSocket // Join adds a Socket to the passed Room Join(room string) // Leave removes a Socket from the passed Room Leave(room string) // Rooms returns the rooms this Socket is in Rooms() []string // To returns an Emitter to the passed room. To(string) Emitter // Request returns the request which this Socket was created from. Request() *http.Request }
Socket is a Server-side socket