vibe

package module
v0.0.0-...-096b0d4 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2015 License: Apache-2.0, BSD-3-Clause Imports: 14 Imported by: 0

README

Vibe Go Server

This is a port of the node-js server found here: https://github.com/vibe-project/vibe-protocol.

> Vibe Protocol is a protocol based on web standards to provide reliable full duplex connection over HTTP and elegant patterns to write real-time web applications

This is still a WIP. However, it does pass the vibe server.js tests.

This port does not currently support web sockets.

License

Original Vibe source code is licensed under Apache 2.0 https://github.com/vibe-project/vibe-protocol/blob/master/LICENSE This port is dual licensed. Under my BSD, or if you prefer Vibe's Apache 2.0.

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

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 (serv *Server) IsSocketAlive(id string) bool

func (*Server) ServeHTTP

func (serv *Server) ServeHTTP(w http.ResponseWriter, req *http.Request)

func (*Server) SetHeartbeat

func (serv *Server) SetHeartbeat(t time.Duration)

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) Close

func (socket *VibeSocket) Close()

Close the connection

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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