mirror of
https://github.com/IS1DI/x0gp.git
synced 2026-07-16 20:47:55 +00:00
Add WebRTC support and remove deviceId from apis
This commit is contained in:
@@ -47,6 +47,7 @@ type Car struct {
|
||||
ID string
|
||||
DriverID string // session id
|
||||
DriverName string
|
||||
DeviceID *int // internal mapping to physical ESP32 device ID
|
||||
X, Y float64
|
||||
Heading float64 // radians
|
||||
Speed float64 // m/s
|
||||
@@ -169,7 +170,7 @@ func (e *Engine) SetPhase(p RacePhase) { e.phase.Store(int32(p)) }
|
||||
|
||||
// AddCar registers a car and returns it. Returns an error if the driver
|
||||
// already has a car or the max car count is reached.
|
||||
func (e *Engine) AddCar(driverID, driverName string, slot int) (*Car, error) {
|
||||
func (e *Engine) AddCar(driverID, driverName string, slot int, deviceID *int) (*Car, error) {
|
||||
e.mu.Lock()
|
||||
defer e.mu.Unlock()
|
||||
|
||||
@@ -185,6 +186,7 @@ func (e *Engine) AddCar(driverID, driverName string, slot int) (*Car, error) {
|
||||
ID: id,
|
||||
DriverID: driverID,
|
||||
DriverName: driverName,
|
||||
DeviceID: deviceID,
|
||||
// Spread cars along start grid (x = 0, y = slot * 0.4 m).
|
||||
Y: float64(slot) * 0.4,
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ type DriverMeta struct {
|
||||
LastSeenMs int64 `json:"last_seen_ms"`
|
||||
Country string `json:"country,omitempty"` // optional, for UI
|
||||
AvatarHue int `json:"avatar_hue,omitempty"` // 0..360, deterministic per id
|
||||
DeviceID *int `json:"device_id,omitempty"`
|
||||
DeviceID *int `json:"-"`
|
||||
}
|
||||
|
||||
// Snapshot is the immutable view broadcast to clients.
|
||||
|
||||
@@ -239,6 +239,19 @@ type VersionResponse struct {
|
||||
Version string `json:"version" example:"0.1.0-poc"`
|
||||
}
|
||||
|
||||
// WebRTCConnectRequest is the body of the WebRTC connection API.
|
||||
type WebRTCConnectRequest struct {
|
||||
SDP string `json:"sdp"`
|
||||
Type string `json:"type" example:"offer"`
|
||||
DriverID string `json:"driver_id" example:"driver-alice"`
|
||||
}
|
||||
|
||||
// WebRTCConnectResponse is the response to WebRTCConnectRequest.
|
||||
type WebRTCConnectResponse struct {
|
||||
SDP string `json:"sdp"`
|
||||
Type string `json:"type" example:"answer"`
|
||||
}
|
||||
|
||||
// LobbyDriver is the wire form of lobby.DriverMeta.
|
||||
type LobbyDriver struct {
|
||||
ID string `json:"id"`
|
||||
@@ -249,7 +262,6 @@ type LobbyDriver struct {
|
||||
LastSeenMs int64 `json:"last_seen_ms"`
|
||||
Country string `json:"country,omitempty"`
|
||||
AvatarHue int `json:"avatar_hue,omitempty"`
|
||||
DeviceID *int `json:"device_id,omitempty"`
|
||||
}
|
||||
|
||||
// LobbySnapshot is the full lobby state, broadcast on change.
|
||||
|
||||
Reference in New Issue
Block a user