websocket

package
v3.0.0-beta+incompatible Latest Latest
Warning

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

Go to latest
Published: May 30, 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

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

This section is empty.

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)
	// 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 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)
}

Server is the websocket server

func New

func New(station irisStation, cfg ...config.Websocket) 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

Jump to

Keyboard shortcuts

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