Skip to content

Commit

Permalink
Merge pull request #645 from 3flex/any-deviceids
Browse files Browse the repository at this point in the history
Use deviceIds enum type where possible
  • Loading branch information
nielsvanvelzen authored Oct 25, 2024
2 parents ddbb245 + ab21ba3 commit 7012aac
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 39 deletions.
14 changes: 7 additions & 7 deletions src/components/castDevices.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const castContext = cast.framework.CastReceiverContext.getInstance();

// Device Ids
export enum deviceIds {
export enum DeviceIds {
GEN1AND2,
AUDIO,
GEN3,
Expand All @@ -18,7 +18,7 @@ let deviceId: number | null = null;
* Tries to identify the active Cast device by testing support for different codecs.
* @returns Active Cast device Id.
*/
export function getActiveDeviceId(): number {
export function getActiveDeviceId(): DeviceIds {
if (deviceId !== null) {
return deviceId;
}
Expand All @@ -27,15 +27,15 @@ export function getActiveDeviceId(): number {
castContext.canDisplayType('video/mp4', 'hev1.1.6.L153.B0') &&
castContext.canDisplayType('video/webm', 'vp9')
) {
deviceId = deviceIds.ULTRA;
deviceId = DeviceIds.ULTRA;
} else if (castContext.canDisplayType('video/webm', 'vp9')) {
deviceId = deviceIds.NESTHUBANDMAX;
deviceId = DeviceIds.NESTHUBANDMAX;
} else if (castContext.canDisplayType('video/mp4', 'avc1.64002A')) {
deviceId = deviceIds.GEN3;
deviceId = DeviceIds.GEN3;
} else if (castContext.canDisplayType('video/mp4', 'avc1.640029')) {
deviceId = deviceIds.GEN1AND2;
deviceId = DeviceIds.GEN1AND2;
} else {
deviceId = deviceIds.AUDIO;
deviceId = DeviceIds.AUDIO;
}

return deviceId;
Expand Down
45 changes: 24 additions & 21 deletions src/components/codecSupportHelper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { deviceIds } from './castDevices';
import { DeviceIds } from './castDevices';

const castContext = cast.framework.CastReceiverContext.getInstance();

Expand Down Expand Up @@ -59,8 +59,8 @@ export function hasH265Support(): boolean {
* @param deviceId - the device id
* @returns true if text tracks are supported
*/
export function hasTextTrackSupport(deviceId: number): boolean {
return deviceId !== deviceIds.AUDIO;
export function hasTextTrackSupport(deviceId: DeviceIds): boolean {
return deviceId !== DeviceIds.AUDIO;
}

/**
Expand Down Expand Up @@ -96,7 +96,10 @@ export function getMaxBitrateSupport(): number {
* @param codec - Video codec.
* @returns Max supported width.
*/
export function getMaxWidthSupport(deviceId: number, codec?: string): number {
export function getMaxWidthSupport(
deviceId: DeviceIds,
codec?: string
): number {
if (codec === 'h264') {
// with HLS, it will produce a manifest error if we
// send any stream larger than the screen size...
Expand All @@ -108,13 +111,13 @@ export function getMaxWidthSupport(deviceId: number, codec?: string): number {
// they just refuse to do it with HLS. This increases
// the rate of direct playback.
switch (deviceId) {
case deviceIds.ULTRA:
case deviceIds.CCGTV:
case DeviceIds.ULTRA:
case DeviceIds.CCGTV:
return 3840;
case deviceIds.GEN1AND2:
case deviceIds.GEN3:
case DeviceIds.GEN1AND2:
case DeviceIds.GEN3:
return 1920;
case deviceIds.NESTHUBANDMAX:
case DeviceIds.NESTHUBANDMAX:
return 1280;
}

Expand All @@ -126,11 +129,11 @@ export function getMaxWidthSupport(deviceId: number, codec?: string): number {
* @param deviceId - Cast device id.
* @returns All supported H.264 profiles.
*/
export function getH264ProfileSupport(deviceId: number): string {
export function getH264ProfileSupport(deviceId: DeviceIds): string {
// These are supported by all Cast devices, excluding audio only devices.
let h264Profiles = 'high|main|baseline|constrained baseline';

if (deviceId === deviceIds.ULTRA || deviceId === deviceIds.CCGTV) {
if (deviceId === DeviceIds.ULTRA || deviceId === DeviceIds.CCGTV) {
h264Profiles += '|high 10';
}

Expand All @@ -142,15 +145,15 @@ export function getH264ProfileSupport(deviceId: number): string {
* @param deviceId - Cast device id.
* @returns The highest supported H.264 level.
*/
export function getH264LevelSupport(deviceId: number): number {
export function getH264LevelSupport(deviceId: DeviceIds): number {
switch (deviceId) {
case deviceIds.NESTHUBANDMAX:
case deviceIds.GEN1AND2:
case DeviceIds.NESTHUBANDMAX:
case DeviceIds.GEN1AND2:
return 41;
case deviceIds.GEN3:
case deviceIds.ULTRA:
case DeviceIds.GEN3:
case DeviceIds.ULTRA:
return 42;
case deviceIds.CCGTV:
case DeviceIds.CCGTV:
return 51;
}

Expand All @@ -162,9 +165,9 @@ export function getH264LevelSupport(deviceId: number): number {
* @param deviceId - Cast device id.
* @returns All supported H.265 profiles.
*/
export function getH265ProfileSupport(deviceId: number): string {
export function getH265ProfileSupport(deviceId: DeviceIds): string {
// These are supported by all Cast devices, excluding audio only devices.
if (deviceId === deviceIds.ULTRA || deviceId === deviceIds.CCGTV) {
if (deviceId === DeviceIds.ULTRA || deviceId === DeviceIds.CCGTV) {
return 'high|main|baseline|constrained baseline|high 10';
}

Expand All @@ -176,8 +179,8 @@ export function getH265ProfileSupport(deviceId: number): string {
* @param deviceId - Cast device id.
* @returns The highest supported H.265 level.
*/
export function getH265LevelSupport(deviceId: number): number {
if (deviceId == deviceIds.ULTRA || deviceId == deviceIds.CCGTV) {
export function getH265LevelSupport(deviceId: DeviceIds): number {
if (deviceId == DeviceIds.ULTRA || deviceId == DeviceIds.CCGTV) {
return 52;
}

Expand Down
10 changes: 5 additions & 5 deletions src/components/deviceprofileBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { EncodingContext } from '@jellyfin/sdk/lib/generated-client/models/encod
import { ProfileConditionType } from '@jellyfin/sdk/lib/generated-client/models/profile-condition-type';
import { ProfileConditionValue } from '@jellyfin/sdk/lib/generated-client/models/profile-condition-value';
import { SubtitleDeliveryMethod } from '@jellyfin/sdk/lib/generated-client/models/subtitle-delivery-method';
import { deviceIds, getActiveDeviceId } from './castDevices';
import { DeviceIds, getActiveDeviceId } from './castDevices';
import {
hasSurroundSupport,
hasTextTrackSupport,
Expand All @@ -39,7 +39,7 @@ interface ProfileOptions {
}

let profileOptions: ProfileOptions;
let currentDeviceId: number;
let currentDeviceId: DeviceIds;

/**
* Create and return a new ProfileCondition
Expand Down Expand Up @@ -79,7 +79,7 @@ function getContainerProfiles(): Array<ContainerProfile> {
function getDirectPlayProfiles(): Array<DirectPlayProfile> {
const DirectPlayProfiles: Array<DirectPlayProfile> = [];

if (currentDeviceId !== deviceIds.AUDIO) {
if (currentDeviceId !== DeviceIds.AUDIO) {
const mp4VideoCodecs = getSupportedMP4VideoCodecs();
const mp4AudioCodecs = getSupportedMP4AudioCodecs();
const vpxVideoCodecs = getSupportedVPXVideoCodecs();
Expand Down Expand Up @@ -163,7 +163,7 @@ function getCodecProfiles(): Array<CodecProfile> {
CodecProfiles.push(audioConditions);

// If device is audio only, don't add all the video related stuff
if (currentDeviceId == deviceIds.AUDIO) {
if (currentDeviceId == DeviceIds.AUDIO) {
return CodecProfiles;
}

Expand Down Expand Up @@ -319,7 +319,7 @@ function getTranscodingProfiles(): Array<TranscodingProfile> {
}

// If device is audio only, don't add all the video related stuff
if (currentDeviceId == deviceIds.AUDIO) {
if (currentDeviceId == DeviceIds.AUDIO) {
return TranscodingProfiles;
}

Expand Down
12 changes: 6 additions & 6 deletions src/components/documentManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { BaseItemDto } from '@jellyfin/sdk/lib/generated-client';
import { AppStatus } from '../types/appStatus';
import { parseISO8601Date, TicksPerSecond, ticksToSeconds } from '../helpers';
import { JellyfinApi } from './jellyfinApi';
import { deviceIds, getActiveDeviceId } from './castDevices';
import { DeviceIds, getActiveDeviceId } from './castDevices';

// eslint-disable-next-line @typescript-eslint/no-extraneous-class
export abstract class DocumentManager {
Expand All @@ -17,7 +17,7 @@ export abstract class DocumentManager {
* Hide the document body on chromecast audio to save resources
*/
public static initialize(): void {
if (getActiveDeviceId() === deviceIds.AUDIO) {
if (getActiveDeviceId() === DeviceIds.AUDIO) {
document.body.style.display = 'none';
}
}
Expand Down Expand Up @@ -133,7 +133,7 @@ export abstract class DocumentManager {
*/
public static async showItem(item: BaseItemDto): Promise<void> {
// no showItem for cc audio
if (getActiveDeviceId() === deviceIds.AUDIO) {
if (getActiveDeviceId() === DeviceIds.AUDIO) {
return;
}

Expand Down Expand Up @@ -219,7 +219,7 @@ export abstract class DocumentManager {
*/
public static async showItemId(itemId: string): Promise<void> {
// no showItemId for cc audio
if (getActiveDeviceId() === deviceIds.AUDIO) {
if (getActiveDeviceId() === DeviceIds.AUDIO) {
return;
}

Expand Down Expand Up @@ -402,7 +402,7 @@ export abstract class DocumentManager {
*/
public static async startBackdropInterval(): Promise<void> {
// no backdrop rotation for cc audio
if (getActiveDeviceId() === deviceIds.AUDIO) {
if (getActiveDeviceId() === DeviceIds.AUDIO) {
return;
}

Expand Down Expand Up @@ -453,7 +453,7 @@ export abstract class DocumentManager {
*/
public static setPlayerBackdrop(item: BaseItemDto): void {
// no backdrop rotation for cc audio
if (getActiveDeviceId() === deviceIds.AUDIO) {
if (getActiveDeviceId() === DeviceIds.AUDIO) {
return;
}

Expand Down

0 comments on commit 7012aac

Please sign in to comment.