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 <darren.taft@bt.com>
This commit is contained in:
EETVApps 2024-08-02 09:42:20 +01:00 committed by GitHub
parent 5abfb0d448
commit 2348c5e42c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 22 deletions

View File

@ -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)

View File

@ -512,7 +512,8 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
[onControlsVisibilityChange],
);
const usingExternalGetLicense = drm?.getLicense instanceof Function;
const selectedDrm = source?.drm || drm;
const usingExternalGetLicense = selectedDrm?.getLicense instanceof Function;
const onGetLicense = useCallback(
async (event: NativeSyntheticEvent<OnGetLicenseData>) => {
@ -520,33 +521,43 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
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(