const port = 3000;
const SAVE_TIMEOUT = 5000;
+const KEEP_ALIVE = 30000;
var http = require("http");
var fs = require("fs");
? "data:" + data + "\n\n"
: data.length + data
);
+
+ if (!terminate) {
+ keepAlive(responseAndIsES);
+ }
+}
+
+function stopKeepAlive(responseAndIsES) {
+ if (responseAndIsES.keepAliveTimeout) {
+ clearTimeout(responseAndIsES.keepAliveTimeout);
+ }
+}
+
+function keepAlive(responseAndIsES) {
+ stopKeepAlive(responseAndIsES);
+ responseAndIsES.keepAliveTimeout = setTimeout(function () {
+ responseAndIsES[0].write(
+ responseAndIsES[1]
+ ? ":\n\n"
+ : "2[]"
+ )
+ }, KEEP_ALIVE);
}
function newBoard() {
var that = this;
that.listeningPlayers.push(responseAndIsES);
+ keepAlive(responseAndIsES);
responseAndIsES[0].on("close", function () {
+ stopKeepAlive(responseAndIsES);
var index = that.listeningPlayers.indexOf(responseAndIsES);
if (index !== -1) {
that.listeningPlayers[index] = that.listeningPlayers[that.listeningPlayers.length - 1];