wsnotifier

package module
v0.1.0-alpha Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2022 License: MIT Imports: 5 Imported by: 1

Documentation

Overview

Package wsnotifier implements a websocket utility for managing hubs of clients. A hub is a broadcast group. This package relies heavily on the example code from the gorilla websockets example library chat application, [https://github.com/gorilla/websocket/tree/master/examples/chat] extending it to multiple broadcast groups for JSON message passing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BroadcastGroup

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

type Client

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

type ClientMessage

type ClientMessage interface{}

type NotifierPool

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

A NotifierPool holds broadcast groups

func NewNotifierPool

func NewNotifierPool() *NotifierPool

NewNotifierPool returns a NotifierPool object

func (*NotifierPool) AddBroadcast

func (p *NotifierPool) AddBroadcast(id string, notifyIfEmpty chan<- bool)

AddBroadcast adds a broadcast group to the NotifierPool tagged by an id. The id should be unique among all broadcast groups and must be maintained to send messages at the group

notifyIfEmpty is a channel that will recieve a notification when a client disconnects and was the last client in the room

func (*NotifierPool) BroadcastAt

func (p *NotifierPool) BroadcastAt(id string, payload interface{})

BroadcastAt sends a JSON payload at each client subscribed to a BroadcastGroup tagged by an id.

func (*NotifierPool) ClientHandler

func (p *NotifierPool) ClientHandler(id string) http.HandlerFunc

func (*NotifierPool) RemoveBroadcast

func (p *NotifierPool) RemoveBroadcast(id string)

RemoveBroadcast ends all client websocket connections from a BroadcastGroup and removes the BroadcastGroup tagged by an id from the NotifierPool.

func (*NotifierPool) SubscribeClient

func (p *NotifierPool) SubscribeClient(id string, w http.ResponseWriter, r *http.Request)

SubscribeClient subscribes a websocket client bound to w,r to a BroadcastGroup tagged by an id.

Jump to

Keyboard shortcuts

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