Skip to content

Commit

Permalink
feat(project): add view nexa epg provider
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonLantukh committed Nov 20, 2023
1 parent 5e2ce14 commit 9a71457
Show file tree
Hide file tree
Showing 22 changed files with 1,389 additions and 437 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"classnames": "^2.3.1",
"date-fns": "^2.28.0",
"dompurify": "^2.3.8",
"fast-xml-parser": "^4.3.2",
"i18next": "^22.4.15",
"i18next-browser-languagedetector": "^6.1.1",
"i18next-http-backend": "^2.2.0",
Expand Down
5 changes: 5 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,8 @@ export const DEFAULT_FEATURES = {
hasProfiles: false,
hasNotifications: false,
};

export const EPG_TYPE = {
JW: 'JW',
VIEW_NEXA: 'VIEW_NEXA',
} as const;
6 changes: 3 additions & 3 deletions src/hooks/useLiveChannels.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { Playlist } from '#types/playlist';
import livePlaylistFixture from '#test/fixtures/livePlaylist.json';
import epgChannelsFixture from '#test/fixtures/epgChannels.json';
import epgChannelsUpdateFixture from '#test/fixtures/epgChannelsUpdate.json';
import EpgService from '#src/services/epg.service';
import EpgClientService from '#src/services/epg/epgClient.service';

const livePlaylist: Playlist = livePlaylistFixture;
const schedule: EpgChannel[] = epgChannelsFixture;
Expand All @@ -17,9 +17,9 @@ const scheduleUpdate: EpgChannel[] = epgChannelsUpdateFixture;
const mockSchedule = vi.fn();

vi.mock('#src/modules/container', () => ({
getModule: (type: typeof EpgService) => {
getModule: (type: typeof EpgClientService) => {
switch (type) {
case EpgService:
case EpgClientService:
return { getSchedules: mockSchedule };
}
},
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useLiveChannels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import type { PlaylistItem } from '#types/playlist';
import type { EpgProgram, EpgChannel } from '#types/epg';
import { getLiveProgram, programIsLive } from '#src/utils/epg';
import { LIVE_CHANNELS_REFETCH_INTERVAL } from '#src/config';
import EpgService from '#src/services/epg.service';
import { getModule } from '#src/modules/container';
import EpgClientService from '#src/services/epg/epgClient.service';

/**
* This hook fetches the schedules for the given list of playlist items and manages the current channel and program.
Expand All @@ -31,7 +31,7 @@ const useLiveChannels = ({
initialChannelId: string | undefined;
enableAutoUpdate?: boolean;
}) => {
const epgService = getModule(EpgService);
const epgService = getModule(EpgClientService);

const { data: channels = [] } = useQuery(['schedules', ...playlist.map(({ mediaid }) => mediaid)], () => epgService.getSchedules(playlist), {
refetchInterval: LIVE_CHANNELS_REFETCH_INTERVAL,
Expand Down
10 changes: 4 additions & 6 deletions src/modules/container.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { Container, interfaces } from 'inversify';

import type { IntegrationType } from '#types/Config';

export const container = new Container({ defaultScope: 'Singleton', skipBaseClassChecks: true });

export function getModule<T>(constructorFunction: interfaces.ServiceIdentifier<T>, required: false): T | undefined;
Expand All @@ -15,10 +13,10 @@ export function getModule<T>(constructorFunction: interfaces.ServiceIdentifier<T
return module;
}

export function getNamedModule<T>(constructorFunction: interfaces.ServiceIdentifier<T>, integration: IntegrationType | null, required: false): T | undefined;
export function getNamedModule<T>(constructorFunction: interfaces.ServiceIdentifier<T>, integration: IntegrationType | null, required: true): T;
export function getNamedModule<T>(constructorFunction: interfaces.ServiceIdentifier<T>, integration: IntegrationType | null): T;
export function getNamedModule<T>(constructorFunction: interfaces.ServiceIdentifier<T>, integration: IntegrationType | null, required = true): T | undefined {
export function getNamedModule<T>(constructorFunction: interfaces.ServiceIdentifier<T>, integration: string | null, required: false): T | undefined;
export function getNamedModule<T>(constructorFunction: interfaces.ServiceIdentifier<T>, integration: string | null, required: true): T;
export function getNamedModule<T>(constructorFunction: interfaces.ServiceIdentifier<T>, integration: string | null): T;
export function getNamedModule<T>(constructorFunction: interfaces.ServiceIdentifier<T>, integration: string | null, required = true): T | undefined {
if (!integration) {
return;
}
Expand Down
17 changes: 13 additions & 4 deletions src/modules/register.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
// To organize imports in a better way
/* eslint-disable import/order */
import 'reflect-metadata'; // include once in the app for inversify (see: https://github.com/inversify/InversifyJS/blob/master/README.md#-installation)
import { INTEGRATION } from '#src/config';
import { EPG_TYPE, INTEGRATION } from '#src/config';
import { container } from '#src/modules/container';

import ApiService from '#src/services/api.service';
import WatchHistoryService from '#src/services/watchhistory.service';
import EpgService from '#src/services/epg.service';
import GenericEntitlementService from '#src/services/genericEntitlement.service';
import JWPEntitlementService from '#src/services/jwpEntitlement.service';
import FavoritesService from '#src/services/favorites.service';
import ConfigService from '#src/services/config.service';
import SettingsService from '#src/services/settings.service';

// Epg services
import EpgClientService from '#src/services/epg/epgClient.service';
import EpgProvider from '#src/services/epg/epgProvider.service';
import ViewNexaEpgService from '#src/services/epg/viewNexaEpg.service';
import JWEpgService from '#src/services/epg/jwEpg.service';

import WatchHistoryController from '#src/stores/WatchHistoryController';
import CheckoutController from '#src/stores/CheckoutController';
import AccountController from '#src/stores/AccountController';
Expand Down Expand Up @@ -40,7 +45,6 @@ import InplayerProfileService from '#src/services/inplayer.profile.service';

// Common services
container.bind(ConfigService).toSelf();
container.bind(EpgService).toSelf();
container.bind(WatchHistoryService).toSelf();
container.bind(FavoritesService).toSelf();
container.bind(GenericEntitlementService).toSelf();
Expand All @@ -52,7 +56,7 @@ container.bind(AppController).toSelf();
container.bind(WatchHistoryController).toSelf();
container.bind(FavoritesController).toSelf();

// Integration controllers (conditionally register?)
// Integration controllers
container.bind(AccountController).toSelf();
container.bind(CheckoutController).toSelf();
container.bind(ProfileController).toSelf();
Expand All @@ -73,3 +77,8 @@ container.bind(AccountService).to(InplayerAccountService).whenTargetNamed(INTEGR
container.bind(CheckoutService).to(InplayerCheckoutService).whenTargetNamed(INTEGRATION.JWP);
container.bind(SubscriptionService).to(InplayerSubscriptionService).whenTargetNamed(INTEGRATION.JWP);
container.bind(ProfileService).to(InplayerProfileService).whenTargetNamed(INTEGRATION.JWP);

// EPG integration
container.bind(EpgClientService).toSelf();
container.bind(EpgProvider).to(JWEpgService).whenTargetNamed(EPG_TYPE.JW);
container.bind(EpgProvider).to(ViewNexaEpgService).whenTargetNamed(EPG_TYPE.VIEW_NEXA);
Loading

0 comments on commit 9a71457

Please sign in to comment.