diff --git a/ios/Video/RCTVideoManager.m b/ios/Video/RCTVideoManager.m index 2693d36e..3807f955 100644 --- a/ios/Video/RCTVideoManager.m +++ b/ios/Video/RCTVideoManager.m @@ -69,7 +69,7 @@ RCT_EXPORT_VIEW_PROPERTY(onAudioTracks, RCTDirectEventBlock); RCT_EXPORT_VIEW_PROPERTY(onTextTrackDataChanged, RCTDirectEventBlock); RCT_EXTERN_METHOD(seekCmd : (nonnull NSNumber*)reactTag time : (nonnull NSNumber*)time tolerance : (nonnull NSNumber*)tolerance) -RCT_EXTERN_METHOD(setLicenseResultCmd : (nonnull NSNumber*)reactTag lisence : (NSString*)license licenseUrl : (NSString*)licenseUrl) +RCT_EXTERN_METHOD(setLicenseResultCmd : (nonnull NSNumber*)reactTag license : (NSString*)license licenseUrl : (NSString*)licenseUrl) RCT_EXTERN_METHOD(setLicenseResultErrorCmd : (nonnull NSNumber*)reactTag error : (NSString*)error licenseUrl : (NSString*)licenseUrl) RCT_EXTERN_METHOD(setPlayerPauseStateCmd : (nonnull NSNumber*)reactTag paused : (nonnull BOOL)paused) RCT_EXTERN_METHOD(setVolumeCmd : (nonnull NSNumber*)reactTag volume : (nonnull float*)volume) diff --git a/src/Video.tsx b/src/Video.tsx index 49ca1e99..da24b567 100644 --- a/src/Video.tsx +++ b/src/Video.tsx @@ -512,7 +512,8 @@ const Video = forwardRef( [onControlsVisibilityChange], ); - const usingExternalGetLicense = drm?.getLicense instanceof Function; + const selectedDrm = source?.drm || drm; + const usingExternalGetLicense = selectedDrm?.getLicense instanceof Function; const onGetLicense = useCallback( async (event: NativeSyntheticEvent) => { @@ -520,33 +521,43 @@ const Video = forwardRef( return; } const data = event.nativeEvent; - let result; - if (data?.spcBase64) { - try { - // Handles both scenarios, getLicenseOverride being a promise and not. - const license = await drm.getLicense( + try { + if (!data?.spcBase64) { + throw new Error('No spc received'); + } + // Handles both scenarios, getLicenseOverride being a promise and not. + const license = await Promise.resolve( + selectedDrm.getLicense( data.spcBase64, data.contentId, data.licenseUrl, data.loadedLicenseUrl, - ); - result = - typeof license === 'string' ? license : 'Empty license result'; - } catch { - result = 'fetch error'; + ), + ).catch(() => { + throw new Error('fetch error'); + }); + if (typeof license !== 'string') { + throw Error('Empty license result'); + } + if (nativeRef.current) { + NativeVideoManager.setLicenseResultCmd( + getReactTag(nativeRef), + license, + data.loadedLicenseUrl, + ); + } + } catch (e) { + const msg = e instanceof Error ? e.message : 'fetch error'; + if (nativeRef.current) { + NativeVideoManager.setLicenseResultErrorCmd( + getReactTag(nativeRef), + msg, + data.loadedLicenseUrl, + ); } - } else { - result = 'No spc received'; - } - if (nativeRef.current) { - NativeVideoManager.setLicenseResultErrorCmd( - getReactTag(nativeRef), - result, - data.loadedLicenseUrl, - ); } }, - [drm, usingExternalGetLicense], + [selectedDrm, usingExternalGetLicense], ); useImperativeHandle(