Skip to content

Commit

Permalink
fix: query enable condition
Browse files Browse the repository at this point in the history
  • Loading branch information
kiremitrov123 committed Sep 25, 2024
1 parent 0b73dc3 commit 3e57799
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
12 changes: 3 additions & 9 deletions packages/hooks-react/src/useContentProtection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ const useContentProtection = <T>(
const genericEntitlementService = getModule(GenericEntitlementService);
const jwpEntitlementService = getModule(JWPEntitlementService);

const { configId, signingConfig, contentProtection, jwp, urlSigning, isAcessBridgeEnabled } = useConfigStore(({ config, settings }) => ({
const { configId, signingConfig, contentProtection, jwp, urlSigning, isAccessBridgeEnabled } = useConfigStore(({ config, settings }) => ({
configId: config.id,
signingConfig: config.contentSigningService,
contentProtection: config.contentProtection,
jwp: config.integrations.jwp,
urlSigning: isTruthyCustomParamValue(config?.custom?.urlSigning),
isAcessBridgeEnabled: !!settings?.apiAccessBridgeUrl,
isAccessBridgeEnabled: !!settings?.apiAccessBridgeUrl,
}));

const host = signingConfig?.host;
Expand All @@ -36,12 +36,6 @@ const useContentProtection = <T>(
const { data: token, isLoading } = useQuery(
['token', type, id, params],
async () => {
if (isAcessBridgeEnabled) {
// if access control is set up we return nothing
// the useProtectedMedia hook will take care of it
return;
}

// if provider is not JWP
if (!!id && !!host) {
const accountController = getModule(AccountController);
Expand All @@ -56,7 +50,7 @@ const useContentProtection = <T>(
return jwpEntitlementService.getJWPMediaToken(configId, id);
}
},
{ enabled: (signingEnabled || isAcessBridgeEnabled) && enabled && !!id, keepPreviousData: false, staleTime: 15 * 60 * 1000 },
{ enabled: signingEnabled && enabled && !!id && !isAccessBridgeEnabled, keepPreviousData: false, staleTime: 15 * 60 * 1000 },
);

const queryResult = useQuery<T | undefined>([type, id, params, token], async () => callback(token, drmPolicyId), {
Expand Down
6 changes: 3 additions & 3 deletions packages/hooks-react/src/useProtectedMedia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ export default function useProtectedMedia(item: PlaylistItem) {
const apiService = getModule(ApiService);
const accessController = getModule(AccessController);

const { isAcessBridgeEnabled } = useConfigStore(({ settings }) => ({
isAcessBridgeEnabled: !!settings?.apiAccessBridgeUrl,
const { isAccessBridgeEnabled } = useConfigStore(({ settings }) => ({
isAccessBridgeEnabled: !!settings?.apiAccessBridgeUrl,
}));

const contentProtectionQuery = useContentProtection('media', item.mediaid, async (token, drmPolicyId) => {
// If the Access Bridge is enabled, use it to retrieve media via access passport.
// This bypasses the need for a DRM token or policy and directly uses the access-controlled method.
if (isAcessBridgeEnabled) {
if (isAccessBridgeEnabled) {
return accessController.getMediaById(item.mediaid);
}

Expand Down

0 comments on commit 3e57799

Please sign in to comment.