websocket

package
v0.0.0-...-714bc2e Latest Latest
Warning

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

Go to latest
Published: May 23, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitStation

func InitStation(client broker.Client) error

InitStation .

func NewStream

func NewStream(opts ...func(o *Options)) func(c *hfwctx.Context)

NewStream .

Types

type Method

type Method string

Method of ws

const (
	// MethodPing ping
	MethodPing Method = "Ping"
	// MethodResponse response
	MethodResponse Method = "Response"
	// MethodSubscribe 消息订阅
	MethodSubscribe Method = "Subscribe"
	// MethodUnsubscribe 取消订阅
	MethodUnsubscribe Method = "Unsubscribe"
	// MethodBroadcast 广播
	MethodBroadcast Method = "Broadcast"
	// MethodDisconnect 断开连接
	MethodDisconnect Method = "Disconnect"
)

func (*Method) String

func (m *Method) String() string

String .

type Options

type Options struct {
	Auth      func(c *hfwctx.Context) error             // WebSocket 认证
	Buffer    int                                       // 缓冲区间。default: 16
	Timeout   time.Duration                             // 超时时间。default: 3s
	Heartbeat time.Duration                             // 心跳。default: 5s
	Action    func(c *hfwctx.Context, session *Session) // 主动推送
}

Options .

type Session

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

Session .

func (*Session) Context

func (sess *Session) Context() *hfwctx.Context

Context .

func (*Session) WriteError

func (sess *Session) WriteError(err *webserver.WebError)

WriteError WebSocket 返回错误

func (*Session) WriteResponse

func (sess *Session) WriteResponse(data interface{})

WriteResponse 手动推送 response 至 WebSocket

type WebSocketBroadcast

type WebSocketBroadcast struct {
	Subject subject     `json:"subject" validate:"required"`
	Time    string      `json:"time" validate:"required"`
	Data    interface{} `json:"data" validate:"required"`
}

WebSocketBroadcast .

type WebSocketRequest

type WebSocketRequest struct {
	ID     hfwctx.ID        `json:"id" validate:"required"`
	Method Method           `json:"method" validate:"required"`
	Params *json.RawMessage `json:"params,omitempty"`
}

WebSocketRequest .

type WebSocketResponse

type WebSocketResponse struct {
	ID      hfwctx.ID      `json:"id" validate:"required"`
	Code    webserver.Code `json:"code,omitempty"`
	Message string         `json:"message,omitempty"`
	Method  Method         `json:"method,omitempty"`
	Data    interface{}    `json:"data,omitempty"`
}

WebSocketResponse .

Jump to

Keyboard shortcuts

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