Skip to content

Commit 2bbf7f6

Browse files
committed
update client display name to be more identfiable
1 parent 6e9543e commit 2bbf7f6

File tree

5 files changed

+81
-6
lines changed

5 files changed

+81
-6
lines changed

AllSpark-ios/CameraViewController.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,17 @@ class CameraViewController: UIViewController, UIDocumentPickerDelegate, UINaviga
640640

641641
// MARK: - WebSocket Methods
642642

643+
private func getClientDisplayName() -> String {
644+
let deviceName = UIDevice.current.name
645+
let customName = UserDefaults.standard.string(forKey: "clientDisplayName")
646+
647+
if let customName = customName, !customName.isEmpty {
648+
return "\(customName) (\(deviceName))"
649+
} else {
650+
return deviceName
651+
}
652+
}
653+
643654
private func setupWebSocketConnection() {
644655
var hostString = UserDefaults.standard.string(forKey: "serverHost") ?? "localhost:8080"
645656

@@ -688,6 +699,25 @@ class CameraViewController: UIViewController, UIDocumentPickerDelegate, UINaviga
688699

689700
print("Connecting to WebSocket at \(wsURL)")
690701

702+
// Send client identification message immediately after connection
703+
let clientName = getClientDisplayName()
704+
let clientInfo: [String: Any] = [
705+
"type": "clientInfo",
706+
"clientName": clientName
707+
]
708+
709+
if let jsonData = try? JSONSerialization.data(withJSONObject: clientInfo, options: []),
710+
let jsonString = String(data: jsonData, encoding: .utf8) {
711+
let message = URLSessionWebSocketTask.Message.string(jsonString)
712+
task.send(message) { error in
713+
if let error = error {
714+
print("Failed to send client info: \(error)")
715+
} else {
716+
print("Client info sent: \(clientName)")
717+
}
718+
}
719+
}
720+
691721
// Start receiving messages - this will detect connection errors and trigger fallback if needed
692722
receiveWebSocketMessage()
693723
}

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,14 @@ Located in **SettingsView.swift**, allows users to:
178178
- Shows connection protocol (ws:// or wss://) being used
179179
- Useful for diagnosing network or certificate issues
180180

181-
4. **Test HTTP Connection**
181+
4. **Set Client Display Name** (optional)
182+
- Custom name shown on server's web interface
183+
- Example: "Lab Camera 1", "Front Lobby", etc.
184+
- If set, displays as "CustomName (DeviceModel)"
185+
- If not set, displays just device name
186+
- Helps identify which device is which when multiple clients connect
187+
188+
5. **Test HTTP Connection**
182189
- Calls `/api/health` endpoint
183190
- Verifies server status and uptime
184191
- Displays health check response

tests/perceptor-host-test/README.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ Returns information about current WebSocket connections and their upload states.
9797
"connections": [
9898
{
9999
"id": "abc123def",
100+
"clientName": "Lab Camera 1 (iPhone 14 Pro)",
100101
"hasMetadata": true,
101102
"filename": "video.mp4",
102103
"receivedData": true
@@ -185,7 +186,32 @@ Any request that doesn't match the above endpoints returns a `404` error.
185186

186187
### WebSocket Message Protocol
187188

188-
#### 1. Command Message from Server (String/JSON)
189+
#### 1. Client Identification Message (String/JSON)
190+
191+
Client sends identification info upon connecting:
192+
193+
**Format:**
194+
```json
195+
{
196+
"type": "clientInfo",
197+
"clientName": "Lab Camera 1 (iPhone 14 Pro)"
198+
}
199+
```
200+
201+
**Parameters:**
202+
- `type`: `"clientInfo"` - Identifies this as a client identification message
203+
- `clientName`: Display name for this client, shown in server's web interface
204+
- Format: "CustomName (DeviceModel)" if custom name is set
205+
- Format: "DeviceModel" if no custom name is set
206+
207+
**Server Behavior:**
208+
- Stores clientName for the connection
209+
- Returns it in `/api/status` endpoint for display on web interface
210+
- Helps identify which device is which in multi-client scenarios
211+
212+
---
213+
214+
#### 2. Command Message from Server (String/JSON)
189215

190216
Server sends commands to client:
191217

@@ -297,7 +323,10 @@ The server provides a web-based control interface at `http://localhost:8080` for
297323
### Features
298324

299325
1. **Active Connections List**
300-
- Shows all connected clients with their IDs
326+
- Shows all connected clients with their display names
327+
- Device names automatically sent by clients (customizable in Settings)
328+
- Format: "CustomName (DeviceModel)" or just "DeviceModel"
329+
- Connection ID shown in smaller text below the name
301330
- Displays metadata status and received data status
302331
- Real-time updates every 5 seconds
303332

tests/perceptor-host-test/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ <h2>Active Connections</h2>
131131
const isChecked = existingCheckbox ? existingCheckbox.checked : true;
132132
return `
133133
<div class="connection-item">
134-
<div class="connection-id">ID: ${conn.id}</div>
134+
<div class="connection-id">${conn.clientName || 'Unknown Device'} <span style="color: #999; font-size: 0.85em;">(${conn.id})</span></div>
135135
<div class="connection-details">
136136
<p>Metadata: ${conn.hasMetadata ? '✓' : '✗'} ${conn.filename ? `(${conn.filename})` : ''}</p>
137137
<p>Data Received: ${conn.receivedData ? '✓' : '✗'}</p>

tests/perceptor-host-test/server.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)