websocket

package
v3.0.0-rc.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2016 License: Apache-2.0 Imports: 12 Imported by: 0

README

Package information

This package is new and unique, if you notice a bug or issue post it here.

How to use

E-Book section

Notes

On OSX + Safari, we had an issue which is fixed now. BUT by the browser's Engine Design the socket is not closed until the whole browser window is closed, so the connection.OnDisconnect event will fire when the user closes the window browser, not just the browser's tab.

Documentation

Index

Constants

View Source
const (
	// All is the string which the Emmiter use to send a message to all
	All = ""
	// NotMe is the string which the Emmiter use to send a message to all except this connection
	NotMe = ";iris;to;all;except;me;"
	// Broadcast is the string which the Emmiter use to send a message to all except this connection, same as 'NotMe'
	Broadcast = NotMe
)

Variables

This section is empty.

Functions

func RegisterServer

func RegisterServer(station irisStation, server Server, logger *logger.Logger)

RegisterServer registers the handlers for the websocket server it's a bridge between station and websocket server

Types

type Connection

type Connection interface {
	// Emmiter implements EmitMessage & Emit
	Emmiter
	// ID returns the connection's identifier
	ID() string
	// OnDisconnect registers a callback which fires when this connection is closed by an error or manual
	OnDisconnect(DisconnectFunc)
	// OnError registers a callback which fires when this connection occurs an error
	OnError(ErrorFunc)
	// EmitError can be used to send a custom error message to the connection
	//
	// It does nothing more than firing the OnError listeners. It doesn't sends anything to the client.
	EmitError(errorMessage string)
	// To defines where server should send a message
	// returns an emmiter to send messages
	To(string) Emmiter
	// OnMessage registers a callback which fires when native websocket message received
	OnMessage(NativeMessageFunc)
	// On registers a callback to a particular event which fires when a message to this event received
	On(string, MessageFunc)
	// Join join a connection to a room, it doesn't check if connection is already there, so care
	Join(string)
	// Leave removes a connection from a room
	Leave(string)
}

Connection is the client

type ConnectionFunc

type ConnectionFunc func(Connection)

ConnectionFunc is the callback which fires when a client/connection is connected to the server. Receives one parameter which is the Connection

type DisconnectFunc

type DisconnectFunc func()

DisconnectFunc is the callback which fires when a client/connection closed

type Emmiter

type Emmiter interface {
	// EmitMessage sends a native websocket message
	EmitMessage([]byte) error
	// Emit sends a message on a particular event
	Emit(string, interface{}) error
}

Emmiter is the message/or/event manager

type ErrorFunc

type ErrorFunc (func(string))

ErrorFunc is the callback which fires when an error happens

type MessageFunc

type MessageFunc interface{}

MessageFunc is the second argument to the Emitter's Emit functions. A callback which should receives one parameter of type string, int, bool or any valid JSON/Go struct

type NativeMessageFunc

type NativeMessageFunc func([]byte)

NativeMessageFunc is the callback for native websocket messages, receives one []byte parameter which is the raw client's message

type Rooms

type Rooms map[string][]string

Rooms is just a map with key a string and value slice of string

type Server

type Server interface {
	// Upgrade upgrades the client in order websocket works
	Upgrade(context.IContext) error
	// OnConnection registers a callback which fires when a connection/client is connected to the server
	OnConnection(ConnectionFunc)
	// Config returns a pointer to server's configs
	Config() *config.Websocket
}

Server is the websocket server

func New

func New(station irisStation, c *config.Websocket, logger *logger.Logger) Server

New returns a new running websocket server, registers this to the iris station

Note that: This is not usable for you, unless you need more than one websocket server, because iris' station already has one which you can configure and start

This is deprecated after rc-1, now we create the server and after register it because I want to be able to call the Websocket via a property and no via func before iris.Listen.

func NewServer

func NewServer(c *config.Websocket) Server

NewServer creates a websocket server and returns it

Jump to

Keyboard shortcuts

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