websocket

package
v0.0.0-...-e964040 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2023 License: Apache-2.0 Imports: 14 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(ctx *hfwContext.Context) interface{}

NewStream .

Types

type Method

type Method string
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(ctx *hfwContext.Context) error             // WebSocket 认证
	Buffer    int                                             // 缓冲区间。default: 16
	Timeout   time.Duration                                   // 超时时间。default: 3s
	Heartbeat time.Duration                                   // 心跳。default: 5s
	Action    func(ctx *hfwContext.Context, session *Session) // 主动推送
}

Options .

type Session

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

Session .

func (*Session) Context

func (session *Session) Context() *hfwContext.Context

Context .

func (*Session) WriteError

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

WriteError WebSocket 返回错误

func (*Session) WriteResponse

func (session *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     sessionID        `json:"id" validate:"required"`
	Method Method           `json:"method" validate:"required"`
	Params *json.RawMessage `json:"params,omitempty"`
}

WebSocketRequest .

type WebSocketResponse

type WebSocketResponse struct {
	ID      sessionID      `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