Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

107
Views
How to add an observer to react hooks?

I'm trying to make a live stream feature, I have an array of programs (videos), every video has startDate and endDate. If I'm running some video and the current time equals the end time of the video, it should run the main function (that calculates the time and run the new video).

const programs = [
    { video: "URL", startDate: 1644405993, endDate: 1644406032 },
    { video: "URL", startDate: 1644405993, endDate: 1644406032 },
    { video: "URL", startDate: 1644405993, endDate: 1644406032 },
    { video: "URL", startDate: 1644405993, endDate: 1644406032 }
];

Can I add any observer for example to run the function when the current time equals the end time of the current program or I can make it in another way?

The main function that should be run again:

  const runningVideo = (newPrograms) => {
    const curTime = Math.floor(new Date().getTime() / 1000);
    const currentProgram = newPrograms.filter(
      p => p.startDate < curTime && p.endDate > curTime
    );
    setPlayerDetails(currentProgram.length ? currentProgram[0].videoPath : advertisement)
  };

**NOTE: ** It's a live stream so every program depends on the start and the end time, I mean the video shouldn't be ended to start the next video, so I can't use onEndedVideo for example.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!