From 2348c5e42c07eced8520fd5564241f62f1cf4c43 Mon Sep 17 00:00:00 2001 From: EETVApps <168638691+EETVApps@users.noreply.github.com> Date: Fri, 2 Aug 2024 09:42:20 +0100 Subject: [PATCH] fix(ios): updated getLicense call to work with new syntax, and fixed spelling error (#4014) (#4042) * fix(android): updated getLicense call to work with new syntax, and fixed spelling error (#4014) * fix(android): corrected error with my refactor (#4014) * fix(android): Removed trailing space (#4014) * fix(ios): Refactored following review (#4014) * fix(ios): Lint tidy (#4014) * fix(ios): Removed incorrect semi-colon (#4014) * fix(ios): Fixed more lint errors (#4014) --------- Co-authored-by: Darren Taft --- ios/Video/RCTVideoManager.m | 2 +- src/Video.tsx | 53 ++++++++++++++++++++++--------------- 2 files changed, 33 insertions(+), 22 deletions(-) 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(