Documentation ¶
Index ¶
Constants ¶
const ( // All is the string which the Emitter use to send a message to all All = "" // NotMe is the string which the Emitter use to send a message to all except this connection NotMe = ";iris;to;all;except;me;" // Broadcast is the string which the Emitter use to send a message to all except this connection, same as 'NotMe' Broadcast = NotMe )
Variables ¶
This section is empty.
Functions ¶
func RegisterServer ¶
RegisterServer registers the handlers for the websocket server it's a bridge between station and websocket server
Types ¶
type Connection ¶
type Connection interface { // Emitter implements EmitMessage & Emit Emitter // 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) Emitter // 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 Emitter ¶
type Emitter interface { // EmitMessage sends a native websocket message EmitMessage([]byte) error // Emit sends a message on a particular event Emit(string, interface{}) error }
Emitter 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 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 ¶
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.