Add realtime gateway and simulator bridge

This commit is contained in:
2026-03-27 21:06:17 +08:00
parent 0703fd47a2
commit 2c0fd4c549
36 changed files with 6852 additions and 1 deletions

View File

@@ -0,0 +1,64 @@
package model
import "encoding/json"
type Role string
const (
RoleProducer Role = "producer"
RoleConsumer Role = "consumer"
RoleController Role = "controller"
)
type Envelope struct {
SchemaVersion int `json:"schemaVersion"`
MessageID string `json:"messageId,omitempty"`
Timestamp int64 `json:"timestamp"`
Topic string `json:"topic"`
Source Source `json:"source"`
Target Target `json:"target"`
Payload json.RawMessage `json:"payload"`
}
type Source struct {
Kind Role `json:"kind"`
ID string `json:"id"`
Mode string `json:"mode,omitempty"`
}
type Target struct {
ChannelID string `json:"channelId,omitempty"`
DeviceID string `json:"deviceId,omitempty"`
GroupID string `json:"groupId,omitempty"`
}
type ClientMessage struct {
Type string `json:"type"`
Role Role `json:"role,omitempty"`
ChannelID string `json:"channelId,omitempty"`
Token string `json:"token,omitempty"`
Subscriptions []Subscription `json:"subscriptions,omitempty"`
Envelope *Envelope `json:"envelope,omitempty"`
}
type Subscription struct {
ChannelID string `json:"channelId,omitempty"`
DeviceID string `json:"deviceId,omitempty"`
GroupID string `json:"groupId,omitempty"`
Topic string `json:"topic,omitempty"`
}
type ServerMessage struct {
Type string `json:"type"`
SessionID string `json:"sessionId,omitempty"`
Error string `json:"error,omitempty"`
Envelope *Envelope `json:"envelope,omitempty"`
State json.RawMessage `json:"state,omitempty"`
}
type LatestState struct {
DeviceID string `json:"deviceId"`
GroupID string `json:"groupId,omitempty"`
UpdatedAt int64 `json:"updatedAt"`
Topics []string `json:"topics"`
}