@@ -71,6 +71,7 @@ function requestHandler(req, res) {
7171 res . writeHead ( 200 , { "Content-Type" : "application/json" } ) ;
7272 const connections = Array . from ( uploadStates . entries ( ) ) . map ( ( [ id , state ] ) => ( {
7373 id,
74+ clientName : state . clientName || "Unknown Device" ,
7475 hasMetadata : state . metadata !== null ,
7576 filename : state . metadata ?. filename || null ,
7677 receivedData : state . receivedData
@@ -144,7 +145,8 @@ wss.on("connection", function connection(ws) {
144145 uploadStates . set ( connectionId , {
145146 metadata : null ,
146147 fileStream : null ,
147- receivedData : false
148+ receivedData : false ,
149+ clientName : null
148150 } ) ;
149151 clientConnections . set ( connectionId , ws ) ;
150152 console . log ( `Client connected ${ connectionId } ` ) ;
@@ -172,11 +174,18 @@ wss.on("connection", function connection(ws) {
172174 }
173175
174176 if ( isStringMessage ) {
175- // First message: metadata or test message as JSON string
177+ // First message: metadata, test message, or client info as JSON string
176178 try {
177179 const parsedMessage = JSON . parse ( message ) ;
178180 console . log ( `Received message:` , parsedMessage ) ;
179181
182+ // Check if this is a client info message
183+ if ( parsedMessage . type === "clientInfo" ) {
184+ state . clientName = parsedMessage . clientName ;
185+ console . log ( `Client identified as: ${ state . clientName } ` ) ;
186+ return ;
187+ }
188+
180189 // Check if this is a test message
181190 if ( parsedMessage . type === "test" ) {
182191 ws . send ( JSON . stringify ( { status : "success" , message : "Test message received" } ) ) ;
0 commit comments