126 lines
2.3 KiB
Go
126 lines
2.3 KiB
Go
package main
|
|
|
|
// Message is a generic envelope exchanged over the WebSocket signaling channel.
|
|
//
|
|
// Type is the message kind (e.g., "join", "leave", "chat", "offer",
|
|
// "answer", "ice", etc.). Other fields are used depending on Type; unused
|
|
// fields are omitted in JSON.
|
|
//
|
|
// The flexibility helps keep the client and server loosely coupled; consider
|
|
// introducing stricter typed payloads if this grows.
|
|
//
|
|
// Note: This struct is intentionally broad to carry both chat and WebRTC
|
|
// signaling payloads.
|
|
//
|
|
// Timestamp is set by the sender (usually server) for ordering.
|
|
// Target is a peer client ID for directed messages.
|
|
// Data/DataExt/DataList support heterogeneous payloads where necessary.
|
|
// Offer/Answer/ICE carry WebRTC SDP/ICE candidate info.
|
|
// DataType can be used by clients to dispatch UI behavior.
|
|
// DataTime is optional timing metadata.
|
|
//
|
|
// Username/UserID are the sender identity.
|
|
// Error holds error information if Type indicates a failure.
|
|
//
|
|
// All fields are optional in JSON except Type.
|
|
// Keep in sync with frontend parsing in static/app.js
|
|
// to avoid breaking changes.
|
|
//
|
|
// Consider versioning if wire format evolves.
|
|
//
|
|
//nolint:lll // wide field tags
|
|
//
|
|
//
|
|
// Message struct definition:
|
|
//
|
|
// - Type: message category
|
|
// - Username, UserID: identity
|
|
// - Data/DataExt/DataList: generic payloads
|
|
// - Offer/Answer/ICE: WebRTC signaling
|
|
// - Target: directed recipient id
|
|
// - Error: error description if any
|
|
// - Timestamp: unix ms or ns
|
|
//
|
|
// The JSON tags omit empty fields to minimize bandwidth.
|
|
//
|
|
// End of doc.
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
// Actual type follows.
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
//
|
|
|
|
type Message struct {
|
|
Type string `json:"type"`
|
|
Username string `json:"username,omitempty"`
|
|
UserID string `json:"userId,omitempty"`
|
|
Data any `json:"data,omitempty"`
|
|
DataExt any `json:"dataExt,omitempty"`
|
|
DataType string `json:"dataType,omitempty"`
|
|
DataTime int64 `json:"dataTime,omitempty"`
|
|
DataList []any `json:"dataList,omitempty"`
|
|
Offer any `json:"offer,omitempty"`
|
|
Answer any `json:"answer,omitempty"`
|
|
ICE any `json:"ice,omitempty"`
|
|
Target string `json:"target,omitempty"`
|
|
Error string `json:"error,omitempty"`
|
|
Timestamp int64 `json:"timestamp,omitempty"`
|
|
}
|