New Entity

Draft 1.1:
Index


Source Code: tempoCommunicate.js



Purpose: Talk to the prototype Time-server which can be used to publicly declare instance availability or revoke it. Generate time-driven outputs.

Additional Usage: Extend time-driven functions and establish automative routines.

            
// Copyright (C) 2020-2023 New Entity Operations Inc.
// All Rights Reserved
// tempoCommunicate.js
// https://www.NewEntity.io/section/7/
// tempoCommunicate.js
// Version 0.5 (03/12/2023)
let counterTimeNow = 0;

function makeRequestPOST (objectRequestPOST) {
  let oXMLHR = new XMLHttpRequest();
  oXMLHR.open("POST", urlFullPathContact, 1);
  oXMLHR.setRequestHeader('Content-Type', 'application/json');
  oXMLHR.send();
}

function makeMockRequestPOST (tempo_contribution) {
 let oXMLHR = new XMLHttpRequest();
 // console.log("The contributed tempo object was: "+tempo_contribution);
 oXMLHR.open("POST", urlFullPathMock, 1);
 var csrf_meta_token = document.querySelector('meta[name="csrf-validation_token"]').content
 // console.log("token-> valid: "+csrf_meta_token)
 oXMLHR.setRequestHeader('X-csrf-token', csrf_meta_token)
 oXMLHR.setRequestHeader('Content-Type', 'application/json');
 oXMLHR.send(tempo_contribution);
 // console.log("tempo-> commit: Success")
}

function formatVariableTime (spentTime=counterTimeNow) {
 // You can tie this into a custom POST hook when needed
 // console.log("Spent "+spentTime+" seconds on page "+pageCurrent);
 // Public Data Definitions: GDPR and CCPA compliant Ad Network
 // console.log("Spent "+spentTime+" seconds on page "+pageCurrent);
 // console.log("You're now contributing a tempo slug to CORE.HOST: "+spentTime)
 makeMockRequestPOST(tempo_contribution=spentTime);
 // console.log(spentTime+" added.");
}

function tallyTime() {
    counterTimeNow++;
    // console.log(counterTimeNow);
}

function stateStart () {
   var trackerInterval = window.setInterval(tallyTime, 1000);
   // To branch states, begin here.
   //clearInterval(trackerInterval);
   //console.log("Interval: Ended");
}

function formatTimeEnd () {
  var timeEnd = 0; //
}

function alterWindowObject () {
  // Add each object here that is state focused, such as loaders or off-site linkers
  var alterWindowX = 0;
}

function makeRequestGET (active, objectRequestGET) {
 // None given by default
 if (active=0) {
   // console.log("No activity happens between any other host nodes.");
 } else if (active=1) {
   // GET call code here
   // Use your own method or use the default
   // console.log("Resync: "+COREHOST);
   // console.log("This site is PUBLIC and set to receive communications on endpoint "+sockINOUT+" serving the pages defined in "+locationSiteMap+" for the DOMAIN: "+originPoint);
 } else {
   // console.log("No host or networked communication routines identified.");
 }
}

let objectRequestGET = {
  // GET the 'tempo' object
  "CURRENTSITEMAP": locationSiteMap,
  "DOMAIN": originPoint,
  "LOCATIONCOMM": sockINOUT
}

// See 'Legacy Factors: Section 8' for more details about what a 'legacy factor' will be
function runTempoRoutine (legacy, mode) {
  stateStart();
  if (legacy == 0) {
    // console.log("Not supporting legacy factors.");
  } else if (legacy == 1) {
    // console.log("Supporting legacy factors.");
  } else {
    // console.log("Legacy state was unable to be determined.");
  }

  if (mode == 0) {
    // console.log("This entity is not communicating with CORE.HOST");
  } else if (mode == 1) {
    makeRequestGET(objectRequestGET);
    // console.log("This entity is communicating with CORE.HOST");
  } else {
    // console.log("Invalid mode: Falling back to OUTLINK: 0")
  }
}

function destroyTempoRoutine() {
  formatVariableTime(counterTimeNow);
}

if (MAINTENANCE==1) {
  location.replace("/about/");
} else {
  // Actions Center
  // Perform action and consider various legacy scenarios
  if (document.addEventListener, legacy=ON, mode=OUTLINK) {
    // Active runner, extend as needed
    document.addEventListener("DOMContentLoaded", () => {
      runTempoRoutine(legacy, mode);
    });
    window.addEventListener("pagehide", () => {
      destroyTempoRoutine();
    });
  } else if (document.attachEvent, legacy=ON) {
    // Branch browsers here as neededo
    console.log("Try a newer browser, site function and loading will work better!");
    document.attachEvent("DOMContentLoaded", runTempoRoutine);
    document.attachEvent("unload", destroyTempoRoutine);
  }
}