From c8fb389f1fefc77434de043d69d171269ced97d2 Mon Sep 17 00:00:00 2001 From: Alexander Zinn Date: Thu, 30 Oct 2025 04:54:36 -0400 Subject: [PATCH] Add PhenixEdgeAuthService and PhenixChannelService for channel token creation and subscription; format countries_mapping.json for consistency. --- src/services/EdgeAuth.service.ts | 18 +++++++++++++++++ src/services/PhenixChannel.service.ts | 24 +++++++++++++++++++++++ src/services/files/countries_mapping.json | 6 ++++-- 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 src/services/EdgeAuth.service.ts create mode 100644 src/services/PhenixChannel.service.ts diff --git a/src/services/EdgeAuth.service.ts b/src/services/EdgeAuth.service.ts new file mode 100644 index 0000000..1d7e927 --- /dev/null +++ b/src/services/EdgeAuth.service.ts @@ -0,0 +1,18 @@ +// @ts-ignore - phenix-edge-auth doesn't have TypeScript definitions +import TokenBuilder from 'phenix-edge-auth'; + +export default class PhenixEdgeAuthService { + private constructor() { + throw new Error('PhenixEdgeAuthService is a static class that may not be instantiated'); + } + + public static createChannelToken({id, secret, channelId}: {id: string; secret: string; channelId: string}): string { + return new TokenBuilder() + .expiresIn(3600) + .withUri('https://pcast-stg.phenixrts.com') + .withApplicationId(id) + .withSecret(secret) + .forChannel(channelId) + .build(); + } + } \ No newline at end of file diff --git a/src/services/PhenixChannel.service.ts b/src/services/PhenixChannel.service.ts new file mode 100644 index 0000000..05e9e45 --- /dev/null +++ b/src/services/PhenixChannel.service.ts @@ -0,0 +1,24 @@ +import {Channels} from '@phenixrts/sdk'; +import type PhenixChannel from '@phenixrts/sdk/types/sdk/channels/Channel'; +import {ApplicationCredentials, Channel} from '@techniker-me/pcast-api'; +import PhenixEdgeAuthService from './EdgeAuth.service'; + + + +export default class PhenixChannelService { + private constructor() { + throw new Error('PhenixChannelService is a static class that may not be instantiated'); + } + + public static subscribeToChannel({id, secret}: ApplicationCredentials, channel: Channel, videoElement: HTMLVideoElement): PhenixChannel { + const token = PhenixEdgeAuthService.createChannelToken({id, secret, channelId: channel.channelId}); + + console.log('token', token); + console.log('channel', channel); + + return Channels.createChannel({ + token, + videoElement + }); + } +} diff --git a/src/services/files/countries_mapping.json b/src/services/files/countries_mapping.json index 3b9c723..230bece 100644 --- a/src/services/files/countries_mapping.json +++ b/src/services/files/countries_mapping.json @@ -1,4 +1,5 @@ -{"AF": "Afghanistan", +{ + "AF": "Afghanistan", "AO": "Angola", "AL": "Albania", "AE": "United Arab Emirates", @@ -174,4 +175,5 @@ "YE": "Yemen", "ZA": "South Africa", "ZM": "Zambia", - "ZW": "Zimbabwe"} \ No newline at end of file + "ZW": "Zimbabwe" +}