server

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package server implements the bayeux specific message handling and server logic for a bayeux backend server

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Start

func Start(addr string)

Start inits the http server on the address/port given in the addr param

Types

type BayeuxMessage

type BayeuxMessage struct {
	Channel                  string      `json:"channel"`
	ClientID                 string      `json:"clientId,omitempty"`
	Subscription             string      `json:"subscription,omitempty"`
	Data                     interface{} `json:"data,omitempty"`
	ID                       string      `json:"id,omitempty"`
	SupportedConnectionTypes []string    `json:"supportedConnectionTypes,omitempty"`
}

BayeuxMessage represents an incoming Bayeux message along with the associated fields

type BayeuxResponse

type BayeuxResponse struct {
	Channel                  string                 `json:"channel,omitempty"`
	Successful               bool                   `json:"successful,omitempty"`
	Version                  string                 `json:"version,omitempty"`
	SupportedConnectionTypes []string               `json:"supportedConnectionTypes,omitempty"`
	ConnectionType           string                 `json:"connectionType,omitempty"`
	ClientID                 string                 `json:"clientId,omitempty"`
	Advice                   map[string]interface{} `json:"advice,omitempty"`
	Subscription             string                 `json:"subscription,omitempty"`
	Error                    string                 `json:"error,omitempty"`
	ID                       string                 `json:"id,omitempty"`
	Data                     interface{}            `json:"data,omitempty"`
	Ext                      interface{}            `json:"ext,omitempty"`
}

BayeuxResponse represents a Bayeux response message and all associated fields

type Client

type Client struct {
	ClientID     string
	WriteChannel chan []byte
	ClientSubs   []string
}

Client represents a connected Faye Client, each has an ID negotiated during handshake, a write channel tied to their network connection and a list of subscriptions(faye channels) that have been subscribed to by the client.

type Connection

type Connection struct {
	// contains filtered or unexported fields
}

Connection represents a websocket connection along with reader and writer state

type Server

type Server struct {
	Connections   []Connection
	Subscriptions map[string][]Client
	SubMutex      sync.RWMutex
	Clients       map[string]Client
	ClientMutex   sync.RWMutex
	// contains filtered or unexported fields
}

Server is the main Bayeux server object which manages connections, subscriptions and clients

func NewServer

func NewServer() *Server

NewServer returns and instance of Server

func (*Server) DisconnectChannel

func (s *Server) DisconnectChannel(c chan []byte)

DisconnectChannel disconnects from the given channel sending the bayeux disconnect message

func (*Server) HandleMessage

func (s *Server) HandleMessage(message []byte, c chan []byte) ([]byte, error)

HandleMessage is the core Bayeux message handler for the server, it interprets each bayeux message and triggers the appropriate response

func (*Server) UpdateClientChannel

func (s *Server) UpdateClientChannel(clientID string, c chan []byte) bool

UpdateClientChannel updates the write channel for the given clientID with the provided channel

Jump to

Keyboard shortcuts

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