hub

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2021 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hub

type Hub struct {
	ClientMap map[*websocket.Conn]map[string]bool

	SubFunc   func(context.Context, ...string) error
	UnSubFunc func(context.Context, ...string) error
	// contains filtered or unexported fields
}

Hub receive mq data and user websocket to push to browser 支持channel不固定,订阅多个channel

func NewHub

func NewHub(ctx context.Context, subfunc func(context.Context, ...string) error, unsubfunc func(context.Context, ...string) error) *Hub

NewHub ..

func (*Hub) AddClient

func (h *Hub) AddClient(channels []string, conn *websocket.Conn)

AddClient 新增客户端

func (*Hub) DiffChannelMap

func (h *Hub) DiffChannelMap(oldChannelMap map[string]bool, newChannels []string) (removeChannelMap map[string]bool, addChannelMap map[string]bool)

DiffChannelMap channelMap比较

func (*Hub) GetChannels

func (h *Hub) GetChannels() []string

GetChannels 获取所有channel

func (*Hub) HandlerDynamicChannel

func (h *Hub) HandlerDynamicChannel(prefix string, checkToken func(token string) bool) func(w http.ResponseWriter, r *http.Request)

HandlerDynamicChannel 向websocket推送mq数据,可以变更channel

func (*Hub) HandlerStaticChannels

func (h *Hub) HandlerStaticChannels(channels []string) func(w http.ResponseWriter, r *http.Request)

HandlerStaticChannels 向websocket推送mq数据,不可变更channel

func (*Hub) RemoveClient

func (h *Hub) RemoveClient(conn *websocket.Conn)

RemoveClient 移除客户端

func (*Hub) UpdateSubChannels

func (h *Hub) UpdateSubChannels()

UpdateSubChannels 更新Sub的channels

Jump to

Keyboard shortcuts

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