Need Javascript help to avoid timeouts when loading audio files

I support several churches that don’t have musicians, by providing a little website with a bunch of pure Javascript so they can select music for their services from a collection of about 1100 mp3 and m4a music files. Previously, they created playlists in iTunes or Media Player, but after a track completed, the player would immediately start the next track unless they quickly clicked ‘Stop’. So my website allows them to select all their music ahead of time (up to 10 tracks), with a separate “Play” button for each. Hit “Play” and it plays that one track and stops. (Duh.)

I’m encountering delays in loading the files into my “audio” tags – and I need the file to load when they select it so I can display the track duration, which is frequently important to the selection of the music for the service. A delay doesn’t occur very often, but often enough to be annoying. Also, the load will occasionally time out completely, even after several attempts. I’ve experimented played with various techniques, like using setTimeout with different values to allow several seconds before checking if it’s loaded, or, loading 5 or 10 times with shorter timeout values until it’s loaded. I created a test page that indicates that the timeouts vary greatly – from 2% to 5% of the time, to upwards of 25% occasionally (during tests of 1,000 to 10,000 random loads).

My first technique was relying on events (I tried both ‘canplay’ and ‘canplaythrough’ events with minimal difference):

const testAudio = document.getElementById('test-audio');
let timeStart = Date.now();
function loadMusic(p_file) {
    testAudio.src = p_file;
    testAudio.addEventListener('canplaythrough', musicLoaded);
    timeStart = Date.now();
    testAudio.load();
}
function musicLoaded() {
    console.log('music loaded in ' + (Date.now()-timeStart) + 'ms');
    testAudio.removeEventListener('canplaythrough', musicLoaded);
    /* should I add/remove the listener each time I change the source file ? */
}

My second approach (from a post here: https://stackoverflow.com/questions/10235919/the-canplay-canplaythrough-events-for-an-html5-video-are-not-called-on-firefox) is to check the ‘readyState’ of the audio element after a specified timeout, rather than relying on an event. This question specifically addressed Firefox, so I should mention that in my tests Firefox has horrible load times for both the “events” and the “readyState” techniques. Chrome and Edge vary in the range of 2% to 6% load failure due to timeout and Firefox has 27% to 39% load timeouts.

let myTimeout = '';
function loadMusic(p_file) {
    myTimeout = setTimeout(fileTimeout, 1000); /* I've tried various values here */
    testAudio.src = p_file;
    timeStart = Date.now();
    testAudio.load();
}
function fileTimeout() {
    if (testAudio.readyState > 3) {
        console.log('music loaded in ' + (Date.now()-timeStart) + 'ms');
    } else {
        /* here, I've tried calling loadMusic again 5 to 10 times, which sometimes works */
        /* or, just reporting that the load failed... */
        console.log('music FAILED to load!');
    }
}

I have a shared server hosting plan, and I suspect the delay might be due to traffic on my server. Unfortunately, my hosting service turns a deaf ear to anything that might be application or content related (not surprising). And this isn’t worth upgrading to a dedicated server just to eliminate that variable. But I suspect that might be a major factor here.

I need a technique that will always work – even if it takes 30 seconds or more. As long as I can display an intermittent “Still loading…” type message I (and my users) would be satisfied. The “track X won’t load” messages happen often enough to be annoying. Early on, I had a few files with bad characters in the file name that needed to be fixed before they would load. So the users think that problem persists. But I know I’ve fixed all them now.

Any and all suggestions are welcome – but I’d love to keep everything in plain Javascript.

I’m getting a error in react Plugin eslint-config-react-app

i’m facing a problem in react app whenever i save the document.
The error is

Plugin “react” was conflicted between “package.json » eslint-config-react-app

i tried to solve this error with lot of methods but it’s not going.

my package.json

{
  "name": "chat",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@emotion/react": "^11.8.1",
    "@emotion/styled": "^11.8.1",
    "@mui/icons-material": "^5.4.2",
    "@mui/material": "^5.4.3",
    "@testing-library/jest-dom": "^5.16.2",
    "@testing-library/react": "^12.1.3",
    "@testing-library/user-event": "^13.5.0",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-scripts": "5.0.0",
    "web-vitals": "^2.1.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {}
}

enter image description here

dialog is not a function – TypeError

I’m trying to implement a mouse hover functionality and below is my jsp;

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

<%@ include file="/include/taglibs.jsp"%>
<!DOCTYPE html>
<html>
<head>
    <title>hover example</title>
</head>





<script>
    $(document).ready(function () {

        $(".hover").each(function () {

            $(this).mouseover(function() {
                console.log('in');

                $("#popup").dialog({
                    autoOpen: true,
                    title: 'Title',
                    width: '100px',
                    height: '100px',
                    modal: true
                });

            })
                    .mouseout(function() {
                        console.log('out');
                    });


        });
    });
</script>

    <div class="hover">
        this is the test hover...

    </div>


    <div id="popup" style="display:none; width: 100px; height:100px;">
        <b>yasgfshdfhsdhf</b>
        <b>yasgfshdfhsdhf</b>
        <b>yasgfshdfhsdhf</b>
    </div>

</html>

But I keep getting a .dialog is not a function error. I have tried many solutions from stackoverflow but still can’t get rid of the error. Can someone please point out what is causing the error.

Strapi Api doens’t show me content of my post when using Components and DynamicZones

As the title says, my local Strapi project doesn’t show the content of the post in API. Permissions are granted, I tried several times deleting and starting from scratch.

As you can see, I have access to a single post “/api/post-templates/1”

and I have access to several posts if I had them. “/api/post-templates”

The issue is, I can’t see any content of the post fields I entered.

Here is the example of the content type which gives its content and this content type is made by explicitly telling what I want on the page.

Picture of Strapi-side which doesn’t show its content

And which shows its content in API.

I want to access content to use it on the front-end as I did in postCards case.

create a condition in angular for the top 12

In my project I have 12 top users ranking by point, I got them from an api rest.

I create 2 button (showMor) and (showLess).

So in my code by default the first three users appear on the list, when i click the button showmore three users are added to the first users, each time i press the button show more three users are added until the end ( 12 users ). and vice versa when pressing the button showless, decrease three users from the list …

the problem was when i press the button showmore 4 times, i have all the 12 users, but when i click on this button for the fifth-sixth-seventh time it is added space for other users doesn’t exist, and the same for button showless when i click on this button on the first time he is hiding the first three users appear on the list by default.

I want to create a condition for the two button’s :

  1. when i click the button showless, i don’t want it to hiding the first three users.

  2. when i click the button showmore, i don’t want it to add more space the the space allotted to the 12 users.

code html :

<div class="col-md-6  text-center">
            <h2><strong>TOP 12 FANS</strong></h2>

            <div *ngFor="let top of top2" class="rank" style="width: 74%;">
                <div class="data-row">
                    <div class="row-user">
                        <div class="col-lg-4 col-md-7 col-sm-7 col-7">
                            <div class="rank-row">
                                <span class="logo-wrapper ">
                                    <img src={{top.photoUrl}}>
                                </span>
                                <div class="td-wrap"><a class="uni-link">{{top.firstname}} {{top.familyname}}</a>
                                </div>
                                <div class="location "> <img width="10px" src="../assets/localisation.png">
                                    france</div>
                            </div>
                        </div>
                        <div
                            class="col-lg-4 offset-lg-0 col-md-12 offset-md-0 col-sm-11 offset-sm-1 text-center">
                            <span><img width="25px" src="../assets/golden.png"> {{top.point}} PT</span>
                        </div>
                    </div>
                </div>
                    <button (click)="showMore()">show more</button>
                    <button (click)="showLess()">show less</button>
            </div>

code ts :

import { Component, OnInit } from '@angular/core';
import { ApiService } from './api.service';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
  top2 = [];
  result = [];
  i=0;
  perChunk = 3; 

  constructor(private apiService: ApiService) { }


  ngOnInit() {
    this.getTop2();
  }

  getTop2() {
    this.apiService.gettop2().subscribe((res: []) => {
      

      var inputArray = res;
      
       this.result = inputArray.reduce((resultArray, item, index) => { 
        const chunkIndex = Math.floor(index/this.perChunk)
      
        if(!resultArray[chunkIndex]) {
          resultArray[chunkIndex] = [] // start a new chunk
        }
      
        resultArray[chunkIndex].push(item)
      
        return resultArray
      }, [])
      
      this.top2 =  this.result[0];
      console.log(res)

    });
  }

  showMore() {
    this.i++;
      this.top2 = this.top2.concat(this.result[this.i])
      console.log(this.top2)
  }

  showLess() {
    this.i--;
    let length = this.top2.length;
    this.top2.length = length-this.perChunk;


  }
}

how to route angular to new page

I have a angular application where I wnat to route the user to a new page after succesfull login. But the webpage is not loading just the url is changing, I tried router-outlet but it renders the component under my login component. What I want is to route to a complete new page.

App-routing module:

const routes: Routes = [
  {path: 'dashboard' , component: DashboardComponent, canActivate: [AuthGuard]},
  {path: 'authenticate', component: LoginComponent},
  {path: '' , redirectTo: 'authenticate', pathMatch: 'full'}
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule],
  providers: [AuthGuard]
})
export class AppRoutingModule {

}

App component.html

  <nb-layout-header fixed >
    Moniesta
  </nb-layout-header>

  <nb-layout-column>
    <moniesta-login></moniesta-login>
    <router-outlet></router-outlet>
  </nb-layout-column>

  <nb-layout-footer fixed>
    <!-- Insert footer here -->
  </nb-layout-footer>

</nb-layout>

Method in my service to load to new url and webpage:

  authenticateUser(login: LoginModel){
    return this.http.post(environment.rootUrl + 'authenticate', {
      username: login.username,
      password: login.password,
    }).subscribe({
      next: (data) => {
       localStorage.setItem('token', data.toString())
        this.router.navigate(['/dashboard'])
      }, error: (error) => {
        this.isAuthenticated = false
      }
    })
  }

Could someone help me out and tell me what is wrong?

How can I read .xlsx row using javascript and convert it to .json file

I have some trouble on on converting my code to .json file.

document.getElementById('button').addEventListener("click", () => {
XLSX.utils.json_to_sheet(data, 'out.xlsx');
if(selectedFile){
    let fileReader = new FileReader();
    fileReader.readAsBinaryString(selectedFile);
    fileReader.onload = (event)=>{
     let data = event.target.result;
     let workbook = XLSX.read(data,{type:"binary"});
     console.log(workbook);
     workbook.SheetNames.forEach(sheet => {
          let rowObject = XLSX.utils.sheet_to_row_object_array(workbook.Sheets[sheet]);
          console.log(rowObject);
          document.getElementById("jsondata").innerHTML = JSON.stringify(rowObject,undefined,4)
     });
    }
}

});

Also I need to read xlsx file per row and convert it as a .json file
Thanks for the help!

check if item exists in json file then get it if exists [duplicate]

I get a json file from outer link by ajax call. i want to check element is exists in this json file or not and get it if exists. because it changes every time and items increases or decreases.
If I get item and this item not existing, I get error and the code not complete. i want to check this item json.children[1].children and json.children[2].children ,….. if exists.

 {
    "num": 1,
    "name": "aa",
    "properites": [
        {
            "name": "prop1",
            "value": "value1"
        }
    ],
    "children": [
       
        {
            "num2": 1,
            "name2": "name2",
            "properites": [
                {
                    "name": "name",
                    "value": "value"
                }
            ],
            "children": []
        },
       
        {
            "name": 1,
            "num": "1",
            "attributes": [
                {
                    "name": "name",
                    "value": "value"
                }
            ],
            "children": []
        .......................... big json file

Discord JS – Error: Cannot find module ‘node:events’ on node v16.14.0

I am currently using node v16.14.0 as per the title and getting this error:

Error: Cannot find module 'node:events'
Require stack:
- /Users/username/bp/bp-website/backend/node_modules/discord.js/src/client/BaseClient.js
- /Users/username/bp/bp-website/backend/node_modules/discord.js/src/index.js
- /Users/username/bp/bp-website/backend/discord/bot.js
- /Users/username/bp/bp-website/backend/discord/purchase.js
- /Users/username/bp/bp-website/backend/webserver.js
- /Users/username/bp/bp-website/backend/index.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:924:15)
    at Function.Module._load (node:internal/modules/cjs/loader:769:27)
    at Module.require (node:internal/modules/cjs/loader:996:19)
    at require (node:internal/modules/cjs/helpers:92:18)
    at Object.<anonymous> (/Users/username/bp/bp-website/backend/node_modules/discord.js/src/client/BaseClient.js:3:22)
    at Module._compile (node:internal/modules/cjs/loader:1092:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
    at Module.load (node:internal/modules/cjs/loader:972:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Module.require (node:internal/modules/cjs/loader:996:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/username/bp/bp-website/backend/node_modules/discord.js/src/client/BaseClient.js',
    '/Users/username/bp/bp-website/backend/node_modules/discord.js/src/index.js',
    '/Users/username/bp/bp-website/backend/discord/bot.js',
    '/Users/username/bp/bp-website/backend/discord/purchase.js',
    '/Users/username/bp/bp-website/backend/webserver.js',
    '/Users/username/bp/bp-website/backend/index.js'
  ]
}

I have looked at other questions, however, they all say upgrade to Node v16.6 which I downgraded to to test but also still didn’t work. Any help would be greatly appreciated!

How can I prevent gap property lines in a grid container from being erased when zooming out?

I have a container div with 16 divs inside.
I have applied the gap property with 1 px both horizontally and vertically.
I created 4 columns and 4 rows, so that the container was 4 x 4.

This is the code:

HTML

<div id="container">
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
  </div>

CSS

#container {
 display: grid;
 background-color: #696969;
 border: 1px solid #000;
 width: 500px;
 height: 500px;
 grid-template-columns: repeat(4, 1fr);
 grid-template-rows: repeat(4, 1fr);
 gap: 1px;
}

#container div {
 background-color: #fff;
}

100% default zoom.
introducir la descripción de la imagen aquí

Zoom 120%
introducir la descripción de la imagen aquí

Zoom 80%
introducir la descripción de la imagen aquí

You can see that at 120% zoom the vertical gap is larger in the middle line. On the other hand, at 80% zoom several lines of the gap disappear.

How can I avoid this behavior?

NodeJS Express: I have two app.get requests and they blend together

So I have 1 request that is app.get('/assignment/loans', (req, res) => { const id = req.query.bookID; and another that is this app.get('/assignment/loans', (req, res) => { const id = req.query.studentID; for some reason the studentID one does not work and it always goes to the bookID to search. I use this http://localhost:3000/assignment/loans?bookID=1 and it works as intended but if I use http://localhost:3000/assignment/loans?studentID=9653 I get enter image description here which is an error that should only appear for the bookID. How can I differentiate the two? Thank you in advance.

Vue js & node js installed. Version also showing but not starting

kirti@kirti-Vostro-14-3468:~/flipbook-vue$ node --version
v17.6.0
kirti@kirti-Vostro-14-3468:~/flipbook-vue$ vue --version
@vue/cli 5.0.1
kirti@kirti-Vostro-14-3468:~/flipbook-vue$ npm run serve

> [email protected] serve
> vue-cli-service serve

sh: 1: vue-cli-service: not found
kirti@kirti-Vostro-14-3468:~/flipbook-vue$ 

System: Ubuntu 20.04

Via: Downloaded via terminal.
I’m running a GitHub repo on my system. I saw the instructions for directly running a github repo on VS Code but as it gave me this error.

I thought, to verify and install vue & node properly first and then run. But, it still gives me error. What can I do?