ws

package module
v0.0.0-...-f4aec2a Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2020 License: MIT Imports: 4 Imported by: 0

README

Simple implementation of a subscription-based websocket server.

Installation

go get github.com/grindevelop/ws

Example

Server and client example. To run the example, start the server:

go run server.go

Next, open one or more client.html pages in a browser.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BroadcastMessage

type BroadcastMessage struct {
	Event string      `json:"event"`
	Data  interface{} `json:"data"`
}

type Broadcaster

type Broadcaster interface {
	Broadcast(message *BroadcastMessage)
}

type Client

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

func NewClient

func NewClient(conn *websocket.Conn) *Client

func (*Client) AddSubscriptions

func (client *Client) AddSubscriptions(subscriptions []string)

func (*Client) ClearSubscriptions

func (client *Client) ClearSubscriptions()

func (*Client) GetSubscriptions

func (client *Client) GetSubscriptions() []string

func (*Client) HasSubscription

func (client *Client) HasSubscription(subscription string) bool

func (*Client) RemoveSubscriptions

func (client *Client) RemoveSubscriptions(subscriptions []string)

type Message

type Message struct {
	Bytes  []byte
	Source *Client
}

type Server

type Server struct {
	Receive chan *Message
	// contains filtered or unexported fields
}

func NewServer

func NewServer() *Server

func (*Server) Broadcast

func (server *Server) Broadcast(message *BroadcastMessage)

func (*Server) DefaultHTTPHandler

func (server *Server) DefaultHTTPHandler() func(http.ResponseWriter, *http.Request)

func (*Server) DisconnectAll

func (server *Server) DisconnectAll()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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