websocket

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2021 License: Apache-2.0 Imports: 18 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

func RegisterCallFunc added in v1.5.0

func RegisterCallFunc(cmd string, callFunc CallFunc)

func RegisterCmd added in v1.5.0

func RegisterCmd()

Types

type ActionWrap

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

type CallFunc added in v1.5.0

type CallFunc func(service callService) (Result, error)

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 MsgType added in v1.5.0

type MsgType string
const (
	MsgTypeResponse MsgType = "response"
)

type Result added in v1.5.0

type Result map[string]interface{}

func ConnectDevice added in v1.5.0

func ConnectDevice(cs callService) (result Result, err error)

ConnectDevice 连接设备 TODO 直接替代添加设备接口?

func DisconnectDevice added in v1.5.0

func DisconnectDevice(cs callService) (result Result, err error)

DisconnectDevice 设备断开连接(取消配对等) TODO 直接替代删除设备接口?

func GetAttrs added in v1.5.0

func GetAttrs(cs callService) (result Result, err error)

func SetAttrs added in v1.5.0

func SetAttrs(cs callService) (result Result, err error)

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