Documentation ¶
Overview ¶
This package provides basic Server support for Vibe: http://vibe-project.github.io/
Creating a Server:
// create the server, specifying which protocols you want to support, and your heartbeat timeout v := vibe.NewServer(nil, 0) // assign your listener // create your own listener. It must implement the ServerListener interface var sl myServerListener v.Listener = sl // attach to the standard http handler http.Handle("/vibe", v) // start listening http.ListenAndServe(":8000", nil)
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( AllTransports = []TransportType{ Ws, Sse, StreamXhr, StreamXdr, StreamIframe, LongpollAjax, LongpollXdr, LongpollJsonp, } )
Functions ¶
This section is empty.
Types ¶
type Message ¶
type Message struct { Id string `json:"id"` Type string `json:"type"` Data interface{} `json:"data,omitempty"` Reply *bool `json:"reply,omitempty"` Exception *bool `json:"exception,omitempty"` }
It should have the following properties: * `id: string`: an event identifier. * `type: string`: an event type. * `data: any`: an event data.
If the server implements `reply` extension, the following properties should be considered as well. * `reply: boolean`: true if this event requires the reply.
type Server ¶
type Server struct { // The listener to get events Listener ServerListener // contains filtered or unexported fields }
Root instance of our Server
func NewServer ¶
func NewServer(transports []TransportType, heartbeat time.Duration) *Server
Creates a new server
transports - a set of supported transports to be used by a client. If nil then all used. heartbeat - interval in milliseconds for heartbeat. If 0 then 20 seconds is used.
func (*Server) IsSocketAlive ¶
func (*Server) SetHeartbeat ¶
sets the heartbeat timeout
func (*Server) SetTransports ¶
func (serv *Server) SetTransports(t []TransportType)
sets the transpotrs we are using
type ServerListener ¶
type ServerListener interface { // Socket gets called when a new socket has been opened. The request is // the one opening the socket. This can be used to associate authentication // data with an open socket. Socket(s *VibeSocket, req *http.Request) // authorizes the request. Return false to deny the request. // a vibesocket will be provided if it is an socket being manipulated Auth(req *http.Request, s *VibeSocket) bool // used for logging Log(format string, args ...interface{}) }
A listener for the whole server
type SocketCallback ¶
type SocketCallback func(resolve bool, value interface{})
When we get a reply, this will called if resolve is false then an exeception was reported by the client value is the data that was sent back to us
type SocketListener ¶
type SocketListener interface { // An error occured Error(err error) // Socket was closed Close() // A new message arrived from the client Message(messageType string, data interface{}) // The client is requiring a reply to this message ReplyMessage(messageType string, data interface{}, replyWith func(resolve bool, value interface{})) }
type TransportType ¶
type TransportType string
const ( Ws TransportType = "ws" Sse TransportType = "sse" StreamXhr TransportType = "streamxhr" StreamXdr TransportType = "streamxdr" StreamIframe TransportType = "streamiframe" LongpollAjax TransportType = "longpollajax" LongpollXdr TransportType = "longpollxdr" LongpollJsonp TransportType = "longpolljsonp" )
type VibeSocket ¶
type VibeSocket struct { // The Id of this connection Id string // The listener to listen to socket events to. Listener SocketListener // our parent Server Server *Server // contains filtered or unexported fields }
Represents a single client connect to the Server
func (*VibeSocket) OnTransportClose ¶
func (socket *VibeSocket) OnTransportClose()
func (*VibeSocket) OnTransportError ¶
func (socket *VibeSocket) OnTransportError(err error)
func (*VibeSocket) OnTransportMessage ¶
func (socket *VibeSocket) OnTransportMessage(msg string)
func (*VibeSocket) Send ¶
func (socket *VibeSocket) Send(t string, data interface{}, resolveRejectCallback SocketCallback) error
Call to send a message to the client t - type of message data - the data we want to send to the client resolveRejectCallback - if we want a reply, it will be sent to this