From 40a2b7368d337f834085f0e1125cf742d72693ac Mon Sep 17 00:00:00 2001 From: Christian Franke Date: Fri, 11 Nov 2022 14:20:24 +0100 Subject: [PATCH] Handle AirPlay key events properly Fixes: https://github.com/videojs/videojs-contrib-eme/issues/159 --- src/plugin.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/plugin.js b/src/plugin.js index 53cb8e9..9f75ae1 100644 --- a/src/plugin.js +++ b/src/plugin.js @@ -227,6 +227,21 @@ const onPlayerReady = (player, emeError) => { setupSessions(player); + /* + * If playback is switched to AirPlay, we will receive another encrypted event, + * proxied from the AirPlay device, as is described here: + * + * https://developer.apple.com/streaming/fps/FairPlayStreamingOverview.pdf + * + * To accomodate for this, we should clear our list of sessions when the playback + * target changes, because the request is otherwise dropped as a duplicate. + */ + if ('webkitCurrentPlaybackTargetIsWireless' in player.tech_.el_) { + player.tech_.el_.addEventListener('webkitcurrentplaybacktargetiswirelesschanged', () => { + player.eme.sessions = []; + }); + } + if (window.MediaKeys) { // Support EME 05 July 2016 // Chrome 42+, Firefox 47+, Edge, Safari 12.1+ on macOS 10.14+