websocket

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2021 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package websocket 接收客户端消息,根据消息内容解包,调用对应模块API处理,然后封装返回

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrClientNotFound = errors.New("client not found")
)

Functions

This section is empty.

Types

type ActionWrap

type ActionWrap struct {
	Cmd      string `json:"cmd"`
	Name     string `json:"name"`
	IsPermit bool   `json:"is_permit"`
}

type DeviceWrap

type DeviceWrap struct {
	Cmd      string `json:"cmd"`
	Name     string `json:"name"`
	IsPermit bool   `json:"is_permit"`
}

type Event

type Event struct {
	EventType string                 `json:"event_type"`
	Data      map[string]interface{} `json:"data"`
}

type Server

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

Server WebSocket服务端

func NewWebSocketServer

func NewWebSocketServer() *Server

func (*Server) AcceptWebSocket

func (s *Server) AcceptWebSocket(c *gin.Context)

func (*Server) Broadcast

func (s *Server) Broadcast(areaID uint64, data []byte)

func (*Server) OnDeviceStateChange

func (s *Server) OnDeviceStateChange(d entity.Device, attr entity.Attribute) error

OnDeviceStateChange 设备状态改变回调,会广播给所有客户端,并且触发场景

func (*Server) Run

func (s *Server) Run(ctx context.Context)

func (*Server) SingleCast

func (s *Server) SingleCast(cliID string, data []byte) error

SingleCast 发送单播消息

Jump to

Keyboard shortcuts

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