@@ -29,8 +29,11 @@ const (
2929
3030// WebSocket message types
3131type WSMessage struct {
32- Type string `json:"type"`
33- Password string `json:"password,omitempty"`
32+ Type string `json:"type"`
33+ Password string `json:"password,omitempty"`
34+ OS string `json:"os,omitempty"`
35+ OSVersion string `json:"os_version,omitempty"`
36+ AppVersion string `json:"app_version,omitempty"`
3437}
3538
3639var upgrader = websocket.Upgrader {
@@ -130,25 +133,30 @@ func (h *WSHandler) HandleWebSocket(c *gin.Context) {
130133
131134 // Host connection: Auto-register if not exists, create temp password
132135 if ! isClient {
136+ // Read device info from query params
137+ osInfo := c .DefaultQuery ("os" , "Unknown" )
138+ osVersion := c .DefaultQuery ("os_version" , "Unknown" )
139+ appVersion := c .DefaultQuery ("app_version" , "Unknown" )
140+
133141 // Check if device exists
134142 _ , err := h .deviceService .GetByDeviceID (c .Request .Context (), deviceID )
135143 if err != nil {
136144 // Device doesn't exist, register it
137145 log .Printf ("Device %s not registered, auto-registering..." , deviceID )
138146 req := & service.RegisterDeviceRequest {
139- OS : "Unknown" ,
140- OSVersion : "Unknown" ,
141- AppVersion : "1.0.0" ,
147+ OS : osInfo ,
148+ OSVersion : osVersion ,
149+ AppVersion : appVersion ,
142150 }
143-
151+
144152 // Use provided device_id
145153 device , err := h .deviceService .RegisterDeviceWithID (c .Request .Context (), deviceID , req )
146154 if err != nil {
147155 log .Printf ("Failed to register device: %v" , err )
148156 c .JSON (http .StatusInternalServerError , gin.H {"error" : "failed to register device" })
149157 return
150158 }
151-
159+
152160 // Generate and set temporary password
153161 tempPassword := h .authService .GenerateTemporaryPassword ()
154162 if accessCode == "" {
@@ -158,10 +166,13 @@ func (h *WSHandler) HandleWebSocket(c *gin.Context) {
158166 if err != nil {
159167 log .Printf ("Failed to set temporary password: %v" , err )
160168 }
161-
169+
162170 log .Printf ("Device registered: device_id=%s, temp_password=%s" , device .DeviceID , accessCode )
163171 } else {
164- // Device exists, update temporary password if provided
172+ // Device exists, update device info and temporary password
173+ if osInfo != "Unknown" || osVersion != "Unknown" || appVersion != "Unknown" {
174+ h .deviceService .UpdateDeviceInfo (c .Request .Context (), deviceID , osInfo , osVersion , appVersion )
175+ }
165176 if accessCode != "" {
166177 err = h .authService .SetTemporaryPassword (c .Request .Context (), deviceID , accessCode )
167178 if err != nil {
@@ -297,6 +308,18 @@ func (h *WSHandler) HandleWebSocket(c *gin.Context) {
297308 }
298309 continue // Don't forward this message to clients
299310 }
311+ if ! isClient && wsMsg .Type == "set_device_info" {
312+ // Host is reporting its device info (OS, version, etc.)
313+ if wsMsg .OS != "" || wsMsg .OSVersion != "" || wsMsg .AppVersion != "" {
314+ h .deviceService .UpdateDeviceInfo (context .Background (), deviceID , wsMsg .OS , wsMsg .OSVersion , wsMsg .AppVersion )
315+ log .Printf ("Device info updated for %s: os=%s, os_version=%s, app_version=%s" ,
316+ deviceID , wsMsg .OS , wsMsg .OSVersion , wsMsg .AppVersion )
317+ h .sendToConnection (conn , map [string ]interface {}{
318+ "type" : "device_info_set" ,
319+ })
320+ }
321+ continue
322+ }
300323 }
301324
302325 // Forward message
0 commit comments