function sendData(isTimeout) {
  if (JSON.parse(packageQueue[0]).length == 0) {
    packageQueue.shift();
    return;
  }
  let collection = JSON.parse(packageQueue[0])[0]?.outerWidth ? 'staticData' : 'clickEvents';
  fetch(`http://127.0.0.1:3000/${collection}`, {
    method: 'POST',
    headers: new Headers({ 'Content-Type': 'application/json' }),
    body: packageQueue[0]
  })
  .then(response => {response.json()})
  .then(data => {
    console.log(data);
    packageQueue.shift(); // Removes the first index from the queue on success
  })
  .catch(err => {
    console.log(`Error: ${err}`); // Log the error if unsuccessful
    if (!isTimeout) {
      setTimeout(() => {
        sendData(true);
      }, 1000);
    }
  });
}
/**
 * Makes a POST request using fetch() to the endpoint with the packaged data from the queue
 */
Makes a POST request using fetch() to the endpoint with the packaged data from the queue
Makes a POST request using fetch () to the endpoint with the packaged data from the queue
function sendData(isTimeout) {
  if (JSON.parse(packageQueue[0]).length == 0) {
    packageQueue.shift();
    return;
  }
  let collection = JSON.parse(packageQueue[0])[0]?.outerWidth ? 'staticData' : 'clickEvents';
  fetch(`http://127.0.0.1:3000/${collection}`, {
    method: 'POST',
    headers: new Headers({ 'Content-Type': 'application/json' }),
    body: packageQueue[0]
  })
  .then(response => {response.json()})
  .then(data => {
    console.log(data);
    packageQueue.shift(); 
  })
  .catch(err => {
    console.log(`Error: ${err}`); 
    if (!isTimeout) {
      setTimeout(() => {
        sendData(true);
      }, 1000);
    }
  });
}
function sendData ( isTimeout ) { if ( JSON . parse ( packageQueue [ 0 ] ) . length == 0 ) { packageQueue . shift ( ) ; return ; } let collection = JSON . parse ( packageQueue [ 0 ] ) [ 0 ] ?. outerWidth ? 'staticData' : 'clickEvents' ; fetch ( ` ${ collection } ` , { method : 'POST' , headers : new Headers ( { 'Content-Type' : 'application/json' } ) , body : packageQueue [ 0 ] } ) . then ( response => { response . json ( ) } ) . then ( data => { console . log ( data ) ; packageQueue . shift ( ) ; } ) . catch ( err => { console . log ( ` ${ err } ` ) ; if ( ! isTimeout ) { setTimeout ( ( ) => { sendData ( true ) ; } , 1000 ) ; } } ) ; }
Makes a POST request using fetch() to the endpoint with the packaged data from the queue
Makes a POST request using fetch () to the endpoint with the packaged data from the queue
// Removes the first index from the queue on success // Log the error if unsuccessful