wsync

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

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

Go to latest
Published: Dec 21, 2019 License: MIT Imports: 4 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// Time allowed to write the file to the client.
	WriteWait = 10 * time.Second

	// Time allowed to read the next pong message from the client.
	PongWait = 60 * time.Second

	// Send pings to client with this period. Must be less than pongWait.
	PingPeriod = (PongWait * 9) / 10
)
View Source
const DefaultMessageCache = 1
View Source
const UnitSeparator = "\x1F"

Variables

View Source
var DefaultDialer = websocket.DefaultDialer
View Source
var DefaultReadWait = PongWait
View Source
var DefaultUpgrader = websocket.Upgrader{
	ReadBufferSize:  128,
	WriteBufferSize: 128,
	CheckOrigin: func(r *http.Request) bool {
		return true
	},
}
View Source
var DefaultWriteWait = WriteWait

Functions

func Decode

func Decode(raw string) (method, topic string, metas []string)

func DecodeData

func DecodeData(data ...string) (method, topic string, metas []string)

func Encode

func Encode(method, topic string, metas ...string) []byte

Types

type Agent

type Agent struct {
	Sub map[string]Topic
}

func NewAgent

func NewAgent() *Agent

type AuthMethod

type AuthMethod int
const (
	AuthMethod_Auth AuthMethod = iota
	AuthMethod_Sub
	AuthMethod_Boardcast
)

func (AuthMethod) String

func (am AuthMethod) String() string

type Client

type Client struct {
	URL       string
	Token     string // for auth
	Dialer    *websocket.Dialer
	OnTopic   func(topic string, metas ...string)
	AfterOpen func(conn *websocket.Conn)
	OnError   func(error)

	ReadWait  time.Duration
	WriteWait time.Duration

	S chan string     // subscribe
	U chan string     // unsubscrbe
	B chan TopicEvent // boardcast
}

func NewClient

func NewClient(url string, token string) *Client

func (*Client) Boardcast

func (c *Client) Boardcast(topic string, metas ...string)

func (*Client) Serve

func (c *Client) Serve()

func (*Client) Sub

func (c *Client) Sub(topics ...string)

func (*Client) Unsub

func (c *Client) Unsub(topics ...string)

type Server

type Server struct {
	C chan ServerFunc // never closed

	Agents map[*websocket.Conn]*Agent

	InitMetas map[string][]string // map[topic]metas

	// status
	MessageSent int

	// readonly
	Upgrader     websocket.Upgrader
	MessageCache int
	Auth         func(token string, m AuthMethod, topic string) bool
}

func NewServer

func NewServer() *Server

func (*Server) Boardcast

func (s *Server) Boardcast(topic string, metas ...string)

func (*Server) GC

func (s *Server) GC()

func (*Server) GetUpdated

func (s *Server) GetUpdated(conn *websocket.Conn, ch chan<- TopicEvent)

func (*Server) Join

func (s *Server) Join(conn *websocket.Conn)

func (*Server) Leave

func (s *Server) Leave(conn *websocket.Conn)

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Server) Sub

func (s *Server) Sub(conn *websocket.Conn, topic string)

func (*Server) Unsub

func (s *Server) Unsub(conn *websocket.Conn, topic string)

type ServerFunc

type ServerFunc func(*Server)

type Topic

type Topic struct {
	Updated bool
	Meta    []string
}

type TopicEvent

type TopicEvent struct {
	Topic string
	Meta  []string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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