websocket

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2022 License: Apache-2.0 Imports: 23 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 Error added in v1.9.1

type Error struct {
	Code    codes.Code `json:"code"`
	Message string     `json:"message"`
}

type EventType added in v1.9.1

type EventType string

type Message added in v1.9.1

type Message struct {
	Type MsgType `json:"type"`
	// contains filtered or unexported fields
}

func NewEvent added in v1.9.1

func NewEvent(eventType string) *Message

func NewResponse added in v1.9.1

func NewResponse(id int) *Message

func (Message) AddResult added in v1.9.1

func (cr Message) AddResult(key string, value interface{})

type MsgType added in v1.5.0

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

消息类型

type Result added in v1.5.0

type Result map[string]interface{}

func CheckUpdate added in v1.9.1

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

CheckUpdate 检查设备是否有更新

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 OTA added in v1.9.1

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

OTA 更新固件

func SetAttrs added in v1.5.0

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

func UpdateThingModel added in v1.9.1

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

UpdateThingModel 更新设备的影子模型字段

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) OnDeviceChange added in v1.9.1

func (s *Server) OnDeviceChange(em event2.EventMessage) error

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

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