notifier

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

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

Go to latest
Published: Jan 17, 2020 License: MIT Imports: 7 Imported by: 0

README

ws-notifier

pushing messages to mutiple clients with one backend goroutine.

Blog: http://maoqide.live/post/golang/golang-websocket-message-pushing/

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatCloseMessage

func FormatCloseMessage(closeCode int, text string) []byte

FormatCloseMessage formats closeCode and text as a WebSocket close message.

Types

type Notifier

type Notifier struct {
	SessionManager *sessionmanager.SessionManager
	Melody         *melody.Melody
	// contains filtered or unexported fields
}

Notifier wrapped websocket operation for notifier

func Default

func Default() *Notifier

Default return default initialized notifier, recommended.

func New

func New() *Notifier

New creates a Notifier

func (*Notifier) Broadcast

func (n *Notifier) Broadcast(msg []byte) error

Broadcast broadcast message to all

func (*Notifier) Close

func (n *Notifier) Close() error

Close close all websocket connections

func (*Notifier) CloseGroupWithMsg

func (n *Notifier) CloseGroupWithMsg(groupID string, msg []byte) error

CloseGroupWithMsg close all websocket connections of a group with messages. Use the FormatCloseMessage function to format a proper close message payload.

func (*Notifier) CloseWithMsg

func (n *Notifier) CloseWithMsg(msg []byte) error

CloseWithMsg close all websocket connections with messages. Use the FormatCloseMessage function to format a proper close message payload.

func (*Notifier) GroupBroadcast

func (n *Notifier) GroupBroadcast(msg []byte, groupID string) error

GroupBroadcast broadcast message to a group

func (*Notifier) GroupLen

func (n *Notifier) GroupLen(groupID string) int

GroupLen return the number of connected sessions of a group.

func (*Notifier) HandleRequest

func (n *Notifier) HandleRequest(w http.ResponseWriter, r *http.Request) error

HandleRequest upgrades http requests to websocket connections and dispatches them to be handled by the melody instance.

func (*Notifier) HandleRequestWithKeys

func (n *Notifier) HandleRequestWithKeys(w http.ResponseWriter, r *http.Request, keys map[string]interface{}) error

HandleRequestWithKeys does the same as HandleRequest but populates session.Keys with keys.

func (*Notifier) IsClosed

func (n *Notifier) IsClosed() bool

IsClosed return status of websocket

func (*Notifier) Len

func (n *Notifier) Len() int

Len return the number of connected sessions.

func (*Notifier) Notify

func (n *Notifier) Notify(groupID string, f workerFunc, timeout time.Duration) error

Notify start notify worker process

func (*Notifier) ReleaseWorker

func (n *Notifier) ReleaseWorker(groupID string)

ReleaseWorker release worker for a group, usually called from a workerFunc when goroutine exited

func (*Notifier) ShowWorkers

func (n *Notifier) ShowWorkers() []string

ShowWorkers shows all workers

type NotifyMessage

type NotifyMessage struct {
	Type    string      `json:"type"`
	Code    int32       `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
}

NotifyMessage is common struct for notifier

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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