Skip to content

Commit 13b4d42

Browse files
committed
feat: added prompt when running client & modified location to use IP if not specified
1 parent 5e25651 commit 13b4d42

File tree

1 file changed

+51
-4
lines changed

1 file changed

+51
-4
lines changed

app.js

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function runServer() {
6969
const clientInfo = {
7070
id: clientId,
7171
name: data.name || 'Anonymous',
72-
location: data.location || 'Unknown',
72+
location: data.location || clientIp,
7373
connectedAt: Date.now(),
7474
lastSeen: Date.now(),
7575
ws: ws
@@ -179,16 +179,63 @@ function runServer() {
179179
// ============================================================================
180180
// CLIENT MODE
181181
// ============================================================================
182-
function runClient() {
182+
async function runClient() {
183183
const WebSocket = require('ws');
184184
const os = require('os');
185+
const readline = require('readline');
186+
187+
// Function to prompt user for input (only works in interactive terminals)
188+
function promptUser(question) {
189+
const rl = readline.createInterface({
190+
input: process.stdin,
191+
output: process.stdout
192+
});
193+
194+
return new Promise((resolve) => {
195+
rl.question(question, (answer) => {
196+
rl.close();
197+
resolve(answer.trim() || null);
198+
});
199+
});
200+
}
185201

186202
// Configuration from environment variables
187203
const SERVER_URL = process.env.SERVER_URL || 'ws://localhost:8080';
188-
const CLIENT_NAME = process.env.CLIENT_NAME || process.env.NAME || 'Anonymous';
189-
const CLIENT_LOCATION = process.env.CLIENT_LOCATION || process.env.LOCATION || 'Unknown';
190204
const HEARTBEAT_INTERVAL = parseInt(process.env.HEARTBEAT_INTERVAL || '5000');
191205

206+
// Get name and location - only check explicit CLIENT_NAME/CLIENT_LOCATION for now
207+
let CLIENT_NAME = process.env.CLIENT_NAME;
208+
let CLIENT_LOCATION = process.env.CLIENT_LOCATION;
209+
210+
// Check if running in interactive terminal (works with 'node app.js' or 'docker run -it')
211+
if (process.stdin.isTTY && (!CLIENT_NAME || !CLIENT_LOCATION)) {
212+
console.log('\x1b[36m%s\x1b[0m', '╔════════════════════════════════════════════════════════╗');
213+
console.log('\x1b[36m%s\x1b[0m', '║ ║');
214+
console.log('\x1b[36m%s\x1b[0m', '║ 🐳 DOCKER CONNECT CLIENT 🐳 ║');
215+
console.log('\x1b[36m%s\x1b[0m', '║ ║');
216+
console.log('\x1b[36m%s\x1b[0m', '╚════════════════════════════════════════════════════════╝');
217+
console.log('');
218+
219+
if (!CLIENT_NAME) {
220+
CLIENT_NAME = await promptUser('📝 Enter your name: ');
221+
if (!CLIENT_NAME) {
222+
CLIENT_NAME = 'Anonymous';
223+
}
224+
}
225+
226+
if (!CLIENT_LOCATION) {
227+
CLIENT_LOCATION = await promptUser('📍 Enter your location (leave empty to use IP): ');
228+
if (!CLIENT_LOCATION) {
229+
CLIENT_LOCATION = '';
230+
}
231+
}
232+
console.log('');
233+
}
234+
235+
// Fall back to other env vars or defaults if still not set
236+
CLIENT_NAME = CLIENT_NAME || process.env.NAME || 'Anonymous';
237+
CLIENT_LOCATION = CLIENT_LOCATION || process.env.LOCATION || '';
238+
192239
let clientId = null;
193240
let ws = null;
194241
let heartbeatTimer = null;

0 commit comments

Comments
 (0)