muxinc / videojs-mux-kit

MIT License
33 stars 11 forks source link

Error events don't fire #48

Closed philcluff closed 2 years ago

philcluff commented 3 years ago

I haven't been able to dig into this completely, but it seems that Video.js never fires error events when used in videojs-mux-kit.

The correct way to listen for errors in. VideoJS is:

player.on('error', function() {
  console.log(player.error());
});

As per: https://github.com/videojs/video.js/issues/6280 You can see this working in this code Sandbox: https://codesandbox.io/s/holy-forest-h2dij?file=/index.html

However, if you try to attach to errors in the same way in VideoJS Mux Kit, the error events never fire:

https://codesandbox.io/s/goofy-snow-ul4mf?file=/index.html

Now, of course this is a little complicated because we use HLS.js as the playback engine, so the errors that we'd expect to be producing would be HLS.js-style errors, not video.js ones: https://github.com/video-dev/hls.js/blob/master/docs/API.md#fifth-step-error-handling

Should player.on('error') work, or should there be another different error interface?

It looks like we attach event listeners to all of HLS.js' events here: https://github.com/muxinc/videojs-mux-kit/blob/main/src/tech/hlsjs.js#L25 and then emit them on the tech.

So maybe a workaround is to listen to those events coming from the tech right now?

cjpillsbury commented 3 years ago

So I haven't dug in fully, but it looks like the hls.js "tech" would need a bit more mapping in place.

Here are the events that vjs will "forward" from whatever underlying tech is in use to redispatch from the player: https://github.com/videojs/video.js/blob/1f4d95b050541071ba27e6f7a2729a0345adfe37/src/js/player.js#L58-L235

Here's where we're doing some hls.js -> vjs+tech event forwardading/translation: https://github.com/videojs/video.js/blob/1f4d95b050541071ba27e6f7a2729a0345adfe37/src/js/player.js#L58-L235 However, we're only passing on the hls.js events "as is" (aka we're dispatching using the vjs tech eventing system, but the events we're dispatching still "look like" hls.js events).

High level possible solutions if I'm not missing anything major/relevant:

gkatsev commented 3 years ago

Saw the convo in video.js slack. This is potentially because an error event isn't being generated. I don't really know the internals of HLS.js, but for comparison with VHS, for various issues with segments or manifests, we can't really do anything because it's possible that it will recover some time in the future, since it could be a momentary blip. We recently added an option to VHS to limit how many times we retry before we actually end up emitting an error event on the tech. Also, sounds like hls.js fires hlsError events? https://github.com/video-dev/hls.js/blob/1ea75a236151c1ce4ee0cdf6829b571465a75c3f/src/events.ts#L158

Another thing that might be interesting is that you can now modify errors with the new beforeerrorhook: https://docs.videojs.com/tutorial-hooks.html#beforeerror.

Hope this helps, good luck!

anujkgupta commented 3 years ago

Gentelman,

Video.js never fires error events when used in videojs-mux-kit I tried all alternatives, but no event is firing, when ever signed URL time is over I have looked at the links given by you , also used beforeerror hook , no luck

Anuj Gupta

OhaiHFO commented 3 years ago

I think my query is related to this open issue - I'm facing a couple of issues where either playback of a signed source halts after around 10 mins and the loading spinner appears, or playback fails to start in the first place.

For both of these occurrences, there are no errors displayed in the console or the network requests panel - forgive me, but I'm perhaps not as well versed in all the dependencies used by this project - it sounds from context like getting playback error information is a little fragmented right now?

Is there currently a recommended way to get playback errors to show so that I may diagnose my issue?

cjpillsbury commented 2 years ago

Looking into this.

cjpillsbury commented 2 years ago

@gkatsev no rush/obligation of course, but had to do a bit of acrobatics in my solution here: https://github.com/muxinc/videojs-mux-kit/pull/57 in case you have any expert recommendations (wanted to rely on what was already "built-in" and didn't want to double-bundle any modules/create too much duplicate code in the bundles)