gosock

package module
v0.0.0-...-0e7671d Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2016 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SupportedSubProtocol string = "sac-sock"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Auth

type Auth func(ctx *iris.Context) error

type BroadcastMsg

type BroadcastMsg struct {
	EventName string
	Data      interface{}
}

BroadcastMsg represents an event to be dispatched to all Sockets on the SocketServer

type MultihomeBackend

type MultihomeBackend interface {
	//Init is called as soon as the MultihomeBackend is
	//registered using SocketServer.SetMultihomeBackend
	Init()

	//Shutdown is called immediately after all sockets have
	//been closed
	Shutdown()

	//BroadcastToBackend is called everytime a BroadcastMsg is
	//sent by a Socket
	//
	//BroadcastToBackend must be safe for concurrent use by multiple
	//go routines
	BroadcastToBackend(*BroadcastMsg)

	//RoomcastToBackend is called everytime a RoomMsg is sent
	//by a socket, even if none of this server's sockets are
	//members of that room
	//
	//RoomcastToBackend must be safe for concurrent use by multiple
	//go routines
	RoomcastToBackend(*RoomMsg)

	//BroadcastFromBackend is called once and only once as a go routine as
	//soon as the MultihomeBackend is registered using
	//SocketServer.SetMultihomeBackend
	//
	//b consumes a BroadcastMsg and dispatches
	//it to all sockets on this server
	BroadcastFromBackend(b chan<- *BroadcastMsg)

	//RoomcastFromBackend is called once and only once as a go routine as
	//soon as the MultihomeBackend is registered using
	//SocketServer.SetMultihomeBackend
	//
	//r consumes a RoomMsg and dispatches it to all sockets
	//that are members the specified room
	RoomcastFromBackend(r chan<- *RoomMsg)
}

MultihomeBackend is an interface for implementing a mechanism to syncronize Broadcasts and Roomcasts to multiple SocketServers running separate machines.

Sacrificial-Socket provides a MultihomeBackend for use with MongoDB in sacrificial-socket/backend

type RoomMsg

type RoomMsg struct {
	RoomName  string
	EventName string
	Data      interface{}
}

RoomMsg represents an event to be dispatched to a room of sockets

type Socket

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

Socket represents a websocket connection

func (*Socket) Broadcast

func (s *Socket) Broadcast(eventName string, data interface{})

Broadcast dispatches an event to all Sockets on the SocketServer.

func (*Socket) Close

func (s *Socket) Close()

Close closes the Socket connection and removes the Socket from any rooms that it was a member of

func (*Socket) Emit

func (s *Socket) Emit(eventName string, data interface{}) error

Emit dispatches an event to s.

func (*Socket) Get

func (s *Socket) Get(key string, defaultVal interface{}) interface{}

func (*Socket) GetRooms

func (s *Socket) GetRooms() []string

GetRooms returns a list of rooms that s is a member of

func (*Socket) ID

func (s *Socket) ID() string

ID returns the unique ID of s

func (*Socket) InRoom

func (s *Socket) InRoom(roomName string) bool

InRoom returns true if s is currently a member of roomName

func (*Socket) Join

func (s *Socket) Join(roomName string)

Join adds s to the specified room. If the room does not exist, it will be created

func (*Socket) Leave

func (s *Socket) Leave(roomName string)

Leave removes s from the specified room. If s is not a member of the room, nothing will happen. If the room is empty upon removal of s, the room will be closed

func (*Socket) Roomcast

func (s *Socket) Roomcast(roomName, eventName string, data interface{})

Roomcast dispatches an event to all Sockets in the specified room.

func (*Socket) Set

func (s *Socket) Set(key string, val interface{})

type SocketServer

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

SocketServer manages the coordination between sockets, rooms, events and the socket hub

func NewServer

func NewServer() *SocketServer

NewServer creates a new instance of SocketServer

func (*SocketServer) EnableSignalShutdown

func (serv *SocketServer) EnableSignalShutdown(complete chan<- bool)

EnableSignalShutdown listens for linux syscalls SIGHUP, SIGINT, SIGTERM, SIGQUIT, SIGKILL and calls the SocketServer.Shutdown() to perform a clean shutdown. true will be passed into complete after the Shutdown proccess is finished

func (*SocketServer) On

func (serv *SocketServer) On(eventName string, handleFunc func(*Socket, []byte))

On registers event functions to be called on individual Socket connections when the server's socket receives an Emit from the client's socket.

Any event functions registered with On, must be safe for concurrent use by multiple go routines

func (*SocketServer) OnConnect

func (serv *SocketServer) OnConnect(handleFunc func(*Socket))

OnConnect registers an event function to be called whenever a new Socket connection is created

func (*SocketServer) OnDisconnect

func (serv *SocketServer) OnDisconnect(handleFunc func(*Socket))

OnDisconnect registers an event function to be called as soon as a Socket connection is closed

func (*SocketServer) SetMultihomeBackend

func (serv *SocketServer) SetMultihomeBackend(b MultihomeBackend)

SetMultihomeBackend registers a MultihomeBackend interface and calls it's Init() method

func (*SocketServer) Shutdown

func (serv *SocketServer) Shutdown() bool

Shutdown closes all active sockets and triggers the Shutdown() method on any MultihomeBackend that is currently set.

func (*SocketServer) WebHandler

func (serv *SocketServer) WebHandler(auth Auth, origins []string) iris.HandlerFunc

WebHandler returns a http.Handler to be passed into http.Handle

Directories

Path Synopsis
backend

Jump to

Keyboard shortcuts

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