daveappserver 0.7.15 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/appserver.js +23 -15
  2. package/package.json +2 -2
package/appserver.js CHANGED
@@ -1,4 +1,4 @@
1
- var myVersion = "0.7.15", myProductName = "daveAppServer";
1
+ var myVersion = "0.8.0", myProductName = "daveAppServer";
2
2
 
3
3
  exports.start = startup;
4
4
  exports.notifySocketSubscribers = notifySocketSubscribers;
@@ -14,7 +14,7 @@ const fs = require ("fs");
14
14
  var dns = require ("dns");
15
15
  var os = require ("os");
16
16
  const request = require ("request");
17
- const websocket = require ("nodejs-websocket");
17
+ const websocket = require ("ws");
18
18
  const utils = require ("daveutils");
19
19
  const davehttp = require ("davehttp");
20
20
  const davetwitter = require ("davetwitter");
@@ -285,7 +285,7 @@ function cleanFileStats (stats) { //4/19/21 by DW
285
285
  payload = utils.jsonStringify (payload);
286
286
  }
287
287
  }
288
- theWsServer.connections.forEach (function (conn, ix) {
288
+ theWsServer.clients.forEach (function (conn, ix) {
289
289
  ctTotalSockets++;
290
290
  if (conn.appData !== undefined) { //it's one of ours
291
291
  var flnotify = true;
@@ -294,13 +294,13 @@ function cleanFileStats (stats) { //4/19/21 by DW
294
294
  }
295
295
  if (flnotify) {
296
296
  try {
297
- conn.sendText (verb + "\r" + payload);
297
+ conn.send (verb + "\r" + payload); //5/25/25 by DW
298
298
  conn.appData.whenLastUpdate = now;
299
299
  conn.appData.ctUpdates++;
300
300
  ctUpdates++;
301
301
  }
302
302
  catch (err) {
303
- console.log ("notifySocketSubscribers: socket #" + i + ": error updating");
303
+ console.log ("notifySocketSubscribers: err.message == " + err.message);
304
304
  }
305
305
  }
306
306
  }
@@ -314,20 +314,24 @@ function cleanFileStats (stats) { //4/19/21 by DW
314
314
  return (0);
315
315
  }
316
316
  else {
317
- return (theWsServer.connections.length);
317
+ return (theWsServer.clients.length);
318
318
  }
319
319
  }
320
320
  function getOpenSocketsArray () { //return an array with data about open sockets
321
321
  var theArray = new Array ();
322
- theWsServer.connections.forEach (function (conn, ix) {
322
+ function viewTime (when) { //5/21/25 by DW -- wanted to see more detail in time, include seconds
323
+ return (new Date (when).toLocaleTimeString ());
324
+ }
325
+ theWsServer.clients.forEach (function (conn, ix) {
323
326
  if (conn.appData !== undefined) { //it's one of ours
324
327
  theArray.push ({
325
328
  arrayIndex: ix,
326
329
  lastVerb: conn.appData.lastVerb,
327
330
  urlToWatch: conn.appData.urlToWatch,
328
331
  domain: conn.appData.domain,
329
- whenStarted: utils.viewDate (conn.appData.whenStarted),
330
- whenLastUpdate: utils.viewDate (conn.appData.whenLastUpdate)
332
+ whenStarted: viewTime (conn.appData.whenStarted),
333
+ whenLastUpdate: viewTime (conn.appData.whenLastUpdate),
334
+ emailAddress: conn.appData.emailAddress //5/21/25 by DW
331
335
  });
332
336
  }
333
337
  });
@@ -335,6 +339,7 @@ function cleanFileStats (stats) { //4/19/21 by DW
335
339
  }
336
340
  function handleWebSocketConnection (conn) {
337
341
  var now = new Date ();
342
+
338
343
  conn.appData = { //initialize
339
344
  whenStarted: now,
340
345
  ctUpdates: 0,
@@ -345,10 +350,10 @@ function cleanFileStats (stats) { //4/19/21 by DW
345
350
  };
346
351
 
347
352
  function logToConsole (conn, verb, value) {
348
- getDomainName (conn.socket.remoteAddress, function (theName) { //log the request
353
+ getDomainName (conn._socket.remoteAddress, function (theName) { //log the request
349
354
  var freemem = utils.gigabyteString (os.freemem ()), method = "WS:" + verb, now = new Date ();
350
355
  if (theName === undefined) {
351
- theName = conn.socket.remoteAddress;
356
+ theName = conn._socket.remoteAddress;
352
357
  }
353
358
  console.log (now.toLocaleTimeString () + " " + freemem + " " + method + " " + value + " " + theName);
354
359
  conn.appData.domain = theName;
@@ -356,19 +361,19 @@ function cleanFileStats (stats) { //4/19/21 by DW
356
361
  }
357
362
 
358
363
  function kissOtherLogonsGoodnight (screenname, theNewConnection) { //12/14/21 by DW
359
- theWsServer.connections.forEach (function (conn, ix) {
364
+ theWsServer.clients.forEach (function (conn, ix) {
360
365
  if (conn.appData !== undefined) { //it's one of ours
361
366
  if (conn != theNewConnection) { //it's not the new one
362
367
  if (conn.appData.screenname == screenname) {
363
368
  console.log ("kissOtherLogonsGoodnight: \"" + conn.appData.screenname + "\" = \"" + screenname + "\""); //2/12/23 by DW
364
- conn.sendText ("goodnight");
369
+ conn.send ("goodnight"); //5/25/25 by DW
365
370
  }
366
371
  }
367
372
  }
368
373
  });
369
374
  }
370
375
 
371
- conn.on ("text", function (s) {
376
+ conn.on ("message", function (s) {
372
377
  var words = s.split (" ");
373
378
  if (words.length > 1) { //new protocol as of 11/29/15 by DW
374
379
  conn.appData.whenLastUpdate = now;
@@ -402,6 +407,8 @@ function cleanFileStats (stats) { //4/19/21 by DW
402
407
  logToConsole (conn, conn.appData.lastVerb, conn.appData.screenname);
403
408
  }
404
409
  });
410
+ conn.appData.emailAddress = emailAddress; //5/21/25 by DW
411
+ conn.appData.emailSecret = emailSecret;
405
412
  }
406
413
  break;
407
414
 
@@ -419,7 +426,8 @@ function cleanFileStats (stats) { //4/19/21 by DW
419
426
  function webSocketStartup () {
420
427
  if (config.flWebsocketEnabled) {
421
428
  try {
422
- theWsServer = websocket.createServer (handleWebSocketConnection);
429
+ theWsServer = new websocket.Server({port: config.websocketPort}); //5/25/25 by DW
430
+ theWsServer.on ("connection", handleWebSocketConnection); //5/25/25 by DW
423
431
  console.log ("webSocketStartup: config.websocketPort == " + config.websocketPort);
424
432
  theWsServer.listen (config.websocketPort);
425
433
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "daveappserver",
3
3
  "description": "Factored code that was appearing in all my servers.",
4
- "version": "0.7.15",
4
+ "version": "0.8.0",
5
5
  "main": "appserver.js",
6
6
  "repository": {
7
7
  "type" : "git",
@@ -14,7 +14,7 @@
14
14
  "dependencies" : {
15
15
  "querystring": "*",
16
16
  "request": "*",
17
- "nodejs-websocket": "*",
17
+ "ws": "*",
18
18
  "require-from-string": "*",
19
19
  "daveutils": "*",
20
20
  "davefilesystem": "*",