daveappserver 0.7.15 → 0.8.1
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.
- package/appserver.js +27 -16
- package/package.json +3 -3
package/appserver.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var myVersion = "0.
|
|
1
|
+
var myVersion = "0.8.1", 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 ("
|
|
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,8 @@ function cleanFileStats (stats) { //4/19/21 by DW
|
|
|
285
285
|
payload = utils.jsonStringify (payload);
|
|
286
286
|
}
|
|
287
287
|
}
|
|
288
|
-
|
|
288
|
+
console.log ("\nnotifySocketSubscribers: getOpenSocketsArray () == " + utils.jsonStringify (getOpenSocketsArray ()) + "\n"); //6/7/21 by DW
|
|
289
|
+
theWsServer.clients.forEach (function (conn, ix) {
|
|
289
290
|
ctTotalSockets++;
|
|
290
291
|
if (conn.appData !== undefined) { //it's one of ours
|
|
291
292
|
var flnotify = true;
|
|
@@ -294,13 +295,14 @@ function cleanFileStats (stats) { //4/19/21 by DW
|
|
|
294
295
|
}
|
|
295
296
|
if (flnotify) {
|
|
296
297
|
try {
|
|
297
|
-
|
|
298
|
+
console.log ("notifySocketSubscribers: conn.appData.emailAddress == " + conn.appData.emailAddress); //5/25/25 by DW
|
|
299
|
+
conn.send (verb + "\r" + payload); //5/25/25 by DW
|
|
298
300
|
conn.appData.whenLastUpdate = now;
|
|
299
301
|
conn.appData.ctUpdates++;
|
|
300
302
|
ctUpdates++;
|
|
301
303
|
}
|
|
302
304
|
catch (err) {
|
|
303
|
-
console.log ("notifySocketSubscribers:
|
|
305
|
+
console.log ("notifySocketSubscribers: err.message == " + err.message);
|
|
304
306
|
}
|
|
305
307
|
}
|
|
306
308
|
}
|
|
@@ -314,20 +316,23 @@ function cleanFileStats (stats) { //4/19/21 by DW
|
|
|
314
316
|
return (0);
|
|
315
317
|
}
|
|
316
318
|
else {
|
|
317
|
-
return (theWsServer.
|
|
319
|
+
return (theWsServer.clients.length);
|
|
318
320
|
}
|
|
319
321
|
}
|
|
320
322
|
function getOpenSocketsArray () { //return an array with data about open sockets
|
|
321
323
|
var theArray = new Array ();
|
|
322
|
-
|
|
324
|
+
function viewTime (when) { //5/21/25 by DW -- wanted to see more detail in time, include seconds
|
|
325
|
+
return (new Date (when).toLocaleTimeString ());
|
|
326
|
+
}
|
|
327
|
+
theWsServer.clients.forEach (function (conn, ix) {
|
|
323
328
|
if (conn.appData !== undefined) { //it's one of ours
|
|
324
329
|
theArray.push ({
|
|
325
|
-
arrayIndex: ix,
|
|
326
330
|
lastVerb: conn.appData.lastVerb,
|
|
327
331
|
urlToWatch: conn.appData.urlToWatch,
|
|
328
332
|
domain: conn.appData.domain,
|
|
329
|
-
whenStarted:
|
|
330
|
-
whenLastUpdate:
|
|
333
|
+
whenStarted: viewTime (conn.appData.whenStarted),
|
|
334
|
+
whenLastUpdate: viewTime (conn.appData.whenLastUpdate),
|
|
335
|
+
emailAddress: conn.appData.emailAddress //5/21/25 by DW
|
|
331
336
|
});
|
|
332
337
|
}
|
|
333
338
|
});
|
|
@@ -335,6 +340,7 @@ function cleanFileStats (stats) { //4/19/21 by DW
|
|
|
335
340
|
}
|
|
336
341
|
function handleWebSocketConnection (conn) {
|
|
337
342
|
var now = new Date ();
|
|
343
|
+
|
|
338
344
|
conn.appData = { //initialize
|
|
339
345
|
whenStarted: now,
|
|
340
346
|
ctUpdates: 0,
|
|
@@ -343,12 +349,13 @@ function cleanFileStats (stats) { //4/19/21 by DW
|
|
|
343
349
|
urlToWatch: undefined,
|
|
344
350
|
domain: undefined
|
|
345
351
|
};
|
|
352
|
+
console.log ("\nhandleWebSocketConnection: getOpenSocketsArray () == " + utils.jsonStringify (getOpenSocketsArray ()) + "\n"); //6/7/21 by DW
|
|
346
353
|
|
|
347
354
|
function logToConsole (conn, verb, value) {
|
|
348
|
-
getDomainName (conn.
|
|
355
|
+
getDomainName (conn._socket.remoteAddress, function (theName) { //log the request
|
|
349
356
|
var freemem = utils.gigabyteString (os.freemem ()), method = "WS:" + verb, now = new Date ();
|
|
350
357
|
if (theName === undefined) {
|
|
351
|
-
theName = conn.
|
|
358
|
+
theName = conn._socket.remoteAddress;
|
|
352
359
|
}
|
|
353
360
|
console.log (now.toLocaleTimeString () + " " + freemem + " " + method + " " + value + " " + theName);
|
|
354
361
|
conn.appData.domain = theName;
|
|
@@ -356,19 +363,20 @@ function cleanFileStats (stats) { //4/19/21 by DW
|
|
|
356
363
|
}
|
|
357
364
|
|
|
358
365
|
function kissOtherLogonsGoodnight (screenname, theNewConnection) { //12/14/21 by DW
|
|
359
|
-
theWsServer.
|
|
366
|
+
theWsServer.clients.forEach (function (conn, ix) {
|
|
360
367
|
if (conn.appData !== undefined) { //it's one of ours
|
|
361
368
|
if (conn != theNewConnection) { //it's not the new one
|
|
362
369
|
if (conn.appData.screenname == screenname) {
|
|
363
370
|
console.log ("kissOtherLogonsGoodnight: \"" + conn.appData.screenname + "\" = \"" + screenname + "\""); //2/12/23 by DW
|
|
364
|
-
conn.
|
|
371
|
+
conn.send ("goodnight"); //5/25/25 by DW
|
|
365
372
|
}
|
|
366
373
|
}
|
|
367
374
|
}
|
|
368
375
|
});
|
|
369
376
|
}
|
|
370
377
|
|
|
371
|
-
conn.on ("
|
|
378
|
+
conn.on ("message", function (s) {
|
|
379
|
+
s = s.toString (); //5/25/25 by DW
|
|
372
380
|
var words = s.split (" ");
|
|
373
381
|
if (words.length > 1) { //new protocol as of 11/29/15 by DW
|
|
374
382
|
conn.appData.whenLastUpdate = now;
|
|
@@ -402,6 +410,8 @@ function cleanFileStats (stats) { //4/19/21 by DW
|
|
|
402
410
|
logToConsole (conn, conn.appData.lastVerb, conn.appData.screenname);
|
|
403
411
|
}
|
|
404
412
|
});
|
|
413
|
+
conn.appData.emailAddress = emailAddress; //5/21/25 by DW
|
|
414
|
+
conn.appData.emailSecret = emailSecret;
|
|
405
415
|
}
|
|
406
416
|
break;
|
|
407
417
|
|
|
@@ -419,7 +429,8 @@ function cleanFileStats (stats) { //4/19/21 by DW
|
|
|
419
429
|
function webSocketStartup () {
|
|
420
430
|
if (config.flWebsocketEnabled) {
|
|
421
431
|
try {
|
|
422
|
-
theWsServer = websocket.
|
|
432
|
+
theWsServer = new websocket.Server({port: config.websocketPort}); //5/25/25 by DW
|
|
433
|
+
theWsServer.on ("connection", handleWebSocketConnection); //5/25/25 by DW
|
|
423
434
|
console.log ("webSocketStartup: config.websocketPort == " + config.websocketPort);
|
|
424
435
|
theWsServer.listen (config.websocketPort);
|
|
425
436
|
}
|
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.
|
|
4
|
+
"version": "0.8.1",
|
|
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
|
-
"
|
|
17
|
+
"ws": "*",
|
|
18
18
|
"require-from-string": "*",
|
|
19
19
|
"daveutils": "*",
|
|
20
20
|
"davefilesystem": "*",
|
|
@@ -25,6 +25,6 @@
|
|
|
25
25
|
"daves3": "*",
|
|
26
26
|
"davehttp": "*",
|
|
27
27
|
"davemail": "*",
|
|
28
|
-
"wpidentity": "^0.
|
|
28
|
+
"wpidentity": "^0.5.27"
|
|
29
29
|
}
|
|
30
30
|
}
|