websocks

package
v0.0.0-...-0172641 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2020 License: GPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(webPort int, natsEndpoint string)

Run connects to NAT and start web server

Types

type Ack

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

Ack the basic ack struct

type AckCommand

type AckCommand struct {
	Acktype string `json:"acktype"`
	Channel string `json:"channel"`
	Error   string `json:"error,omitempty"`
	Ref     string `json:"ref"`
}

AckCommand provides error responses to WS clients

type Acks

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

Acks a group of acks with syncs

func NewAcks

func NewAcks() *Acks

NewAcks constructs a new map of acks with syncs

func (*Acks) Add

func (a *Acks) Add(key string, ackType string) *Ack

Add amends a key to the map and singles anything waiting for a key change

func (*Acks) GC

func (a *Acks) GC()

GC ranges over the sync map to clear out acks older than 5 minutes

func (*Acks) Has

func (a *Acks) Has(k string) bool

Has checks to see if a map key exists

func (*Acks) Stop

func (a *Acks) Stop()

Stop terminates the GC loop

func (*Acks) WaitForKey

func (a *Acks) WaitForKey(k string)

WaitForKey checks if a key exists otherwise waits for a change to the map and then checks again

func (*Acks) WaitForKeyWithTimeout

func (a *Acks) WaitForKeyWithTimeout(k string, d time.Duration) error

WaitForKeyWithTimeout waits for the key to exist or times out after specified time

type AuthCommand

type AuthCommand struct {
	*InboundCommand
	Stream int32  `json:"stream"`
	Key    string `json:"key"`
	Secret string `json:"secret"`
}

AuthCommand provides streaming information and verification

type Client

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

Client maintains WS info

func NewClient

func NewClient(conn *websocket.Conn) *Client

NewClient constructs a new websocket evntsrc client

func (*Client) ConnSub

func (c *Client) ConnSub() error

ConnSub subscribes to a connection specific channel

func (*Client) Subscribe

func (c *Client) Subscribe(channel string, cmd *InboundCommand)

Subscribe opens a NATS subscription for the websocket

func (*Client) Unsubscribe

func (c *Client) Unsubscribe(channel string, cmd *InboundCommand)

Unsubscribe closes a subscription to NATS

type ConnectionInfo

type ConnectionInfo struct {
	Ref          string `json:"ref"`
	ConnectionID string `json:"connectionID"`
}

ConnectionInfo basic information about the current connection

type InboundCommand

type InboundCommand struct {
	Command string `json:"cmd"`
	Ref     string `json:"ref"`
}

InboundCommand is the basic struct for all commands coming from browser

type NatsPublisher

type NatsPublisher struct{}

NatsPublisher sends an event into a nats cluster

func (*NatsPublisher) Publish

func (n *NatsPublisher) Publish(channel string, event *event.Event) error

Publish takes in a channel and an event, converts it into protobuf and sends it into a nats cluster

type PublishCommand

type PublishCommand struct {
	*SubscribeCommand
	Data        string            `json:"data"`
	Source      string            `json:"source"`
	Type        string            `json:"type"`
	TypeVersion string            `json:"typeVersion"`
	ContentType string            `json:"contentType"`
	Metadata    map[string]string `json:"metadata"`
}

PublishCommand sends data (server-side event) through to NATS

type PublishEventCommand

type PublishEventCommand struct {
	*SubscribeCommand
	Event *event.Event `json:"event"`
}

PublishEventCommand sends an client-side event through NATS

type Publisher

type Publisher interface {
	Publish(channel string, event *event.Event) error
}

Publisher provides a way to broadcast an event

type ReplayCommand

type ReplayCommand struct {
	*SubscribeCommand
	Stream int32       `json:"stream"`
	JustMe bool        `json:"justme"`
	Dest   string      `json:"dest"`
	Query  ReplayRange `json:"query"`
}

ReplayCommand instructs events to rebroadcast all events stored since time

type ReplayRange

type ReplayRange struct {
	StartTime *time.Time `json:"startTime"`
	EndTime   *time.Time `json:"endTime"`
	EndID     string     `json:"endID"`
}

ReplayRange specifies the time and/or ID's to include in the replay

type SubscribeCommand

type SubscribeCommand struct {
	*InboundCommand
	Subject string `json:"subject"`
}

SubscribeCommand starts a subscription

type UnsubscribeCommand

type UnsubscribeCommand struct {
	*InboundCommand
	Subject string `json:"subject"`
}

UnsubscribeCommand starts a subscription

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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