videojs / videojs-contrib-eme

Supports Encrypted Media Extensions for playback of encrypted content in Video.js
Other
203 stars 72 forks source link

Widevine getLicense fails to report license acquisition error #157

Open drewkutilek opened 2 years ago

drewkutilek commented 2 years ago

The Widevine CDM in browsers, as part of a normal license request process, can make a 2-byte request to the license server followed by the actual license request. See this comment here in Google's Shaka Player issues list ( https://github.com/google/shaka-player/issues/1814#issuecomment-468930207 ) that confirms this can be part of the license request process.

The promise returned from makeNewRequest does not take this into account. When listening to the message event on the keySession, the Widevine CDM will emit two message events, one with the 2-byte request (which I can only assume is part of the provisioning of the CDM) followed by the 'actual' license request which POSTs a much larger body to the license server.

https://github.com/videojs/videojs-contrib-eme/blob/main/src/eme.js#L113

    keySession.addEventListener('message', (event) => {
      // all other types will be handled by keystatuseschange
      if (event.messageType !== 'license-request' && event.messageType !== 'license-renewal') {
        return;
      }

      getLicense(options, event.message, contentId)
        .then((license) => {
          resolve(keySession.update(license));
        })
        .catch((err) => {
          reject(err);
        });
    }, false);

(The event.messageType is license-request for both emitted events)

If the second 'actual' license request fails, the promise has been resolve'd and any further attempt to reject it to have it be thrown into the catch block and have it reported to emeError are ignored.

https://github.com/videojs/videojs-contrib-eme/blob/main/src/plugin.js#L237

      handleEncryptedEvent(event, getOptions(player), player.eme.sessions, player.tech_)
        .catch(emeError);