reveal.js icon indicating copy to clipboard operation
reveal.js copied to clipboard

Firefox not possible to put video in fullscreen upon keyboard event

Open Sciss opened this issue 3 years ago • 1 comments

Hi there. I want to map a key of my presenter so that it starts a <video> element and puts it in full screen. What I have so far:

			var funStartStopMedia = function() {
				console.log("play/stop");
				var sl = Reveal.getCurrentSlide();
				var e  = sl.getElementsByTagName("audio")[0];
				if (typeof e !== 'undefined') {
					if (e.paused) e.play(); else e.pause();
				} else {
					e = sl.getElementsByTagName("video")[0];
					if (typeof e !== 'undefined') {
						if (e.paused) {
							e.play();
							e.requestFullscreen();   // doesn't work
						} else {
							e.pause();
							document.exitFullscreen();
						}
					};
				};
			};

			Reveal.configure({
				keyboard: {
					 27: funStartStopMedia, // logitech r400: escape
					116: funStartStopMedia, // logitech r400: f5
				}
			});

While play/stop works, entering full screen for the video does not. Firefox somehow thinks the key event is not "user issues", complaining that

Request for fullscreen was denied because Element.requestFullscreen() was not called from inside a short running user-generated event handler.

How to fix this? Is there an asynchronous indirection in the key handling, or how does Firefox think the function wasn't called from a user-generated event handler?

I tried to add an event handler directly on the document, but reveal.js blocks the corresponding key events, even if I do not include them in configure, or if I put 27: null, 116: null. Is there perhaps a way to avoid consuming specific key codes?

Sciss avatar Oct 18 '21 10:10 Sciss

I think you need to use a built-in event like keydown or something like that. Firefox won't go in fullscreen unless a event is used and I think it doesn't know that Reveal is an event (or whatever reveal is)

ZarmDev avatar Aug 15 '22 22:08 ZarmDev

You are probably right that once it's bubbled up to the reveal keyboard object, it is no longer seen as a direct keyboard event by Firefox, possibly because of some indirection in the way reveal treats events. Thus closing. I found that for I could make it work temporarily for presentations, using about:config and setting full-screen-api.allow-trusted-requests-only to false.

Sciss avatar Sep 26 '22 20:09 Sciss