Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add isolatedDeclarations to common, true-time and player. #151

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
"cSpell.words": [
"Retryable",
"typecheck"
]
],
"typescript.tsdk": "./node_modules/typescript/lib"
}
10 changes: 8 additions & 2 deletions packages/auth/vite-legacy.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import topLevelAwait from 'vite-plugin-top-level-await';
import { defineConfig, mergeConfig } from 'vitest/config';
import {
type UserConfigFnObject,
defineConfig,
mergeConfig,
} from 'vitest/config';

import defaultViteConfig from './vite.config';

export default defineConfig(configEnv =>
const config: UserConfigFnObject = defineConfig(configEnv =>
mergeConfig(
defaultViteConfig(configEnv),
defineConfig({
Expand All @@ -20,3 +24,5 @@ export default defineConfig(configEnv =>
}),
),
);

export default config;
10 changes: 8 additions & 2 deletions packages/auth/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import dts from 'vite-plugin-dts';
import { type UserConfig, defineConfig } from 'vitest/config';
import {
type UserConfig,
type UserConfigFnObject,
defineConfig,
} from 'vitest/config';

export default defineConfig(({ command }) => {
const config: UserConfigFnObject = defineConfig(({ command }) => {
// needed for demo cors
const serverExtras: UserConfig =
command === 'serve'
Expand Down Expand Up @@ -49,3 +53,5 @@ export default defineConfig(({ command }) => {
...serverExtras,
};
});

export default config;
4 changes: 3 additions & 1 deletion packages/common/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"baseUrl": "."
"baseUrl": ".",
"declaration": true,
"isolatedDeclarations": true
},
"include": ["."]
}
6 changes: 4 additions & 2 deletions packages/common/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import dts from 'vite-plugin-dts';
import { configDefaults, defineConfig } from 'vitest/config';
import { configDefaults, defineConfig, type UserConfig } from 'vitest/config';

export default defineConfig({
const config: UserConfig = defineConfig({
build: {
lib: {
entry: 'src/index.ts',
Expand All @@ -28,3 +28,5 @@ export default defineConfig({
unstubGlobals: true,
},
});

export default config;
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ export const eventName = 'active-device-disconnected';
/**
* Native player device disconnect event.
*/
export function activeDeviceDisconnected() {
export function activeDeviceDisconnected(): CustomEvent {
return new CustomEvent(eventName);
}
2 changes: 1 addition & 1 deletion packages/player/src/api/event/preload-request.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export function preloadRequest() {
export function preloadRequest(): CustomEvent {
return new CustomEvent('preload-request');
}
2 changes: 1 addition & 1 deletion packages/player/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ export function update(updates: Partial<Config>): Config {
return state;
}

export const events = new EventTarget();
export const events: EventTarget = new EventTarget();
4 changes: 2 additions & 2 deletions packages/player/src/event-bus.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PlayerError } from './internal';

class PlayerEventTarget extends EventTarget {
dispatchError(error: PlayerError) {
dispatchError(error: PlayerError): void {
this.dispatchEvent(
new CustomEvent('error', {
detail: error.toJSON(),
Expand All @@ -10,4 +10,4 @@ class PlayerEventTarget extends EventTarget {
}
}

export const events = new PlayerEventTarget();
export const events: PlayerEventTarget = new PlayerEventTarget();
2 changes: 1 addition & 1 deletion packages/player/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function getMediaElement(): HTMLMediaElement | null {
*
* @param {Options} options
*/
export function bootstrap(options: Options) {
export function bootstrap(options: Options): void {
playerState.activePlayer = undefined;

if (options.outputDevices === true) {
Expand Down
8 changes: 5 additions & 3 deletions packages/player/src/internal/beacon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { CommitData, PrematureEvents } from './types';
* Generates a Web Worker from a function.
*/
// eslint-disable-next-line @typescript-eslint/ban-types
export function workerize(method: Function) {
export function workerize(method: Function): string {
const functionBody = `(${method.toString()})();`;
const workerBlob = new Blob([functionBody], { type: 'text/javascript' });

Expand All @@ -34,7 +34,7 @@ async function handleWorkerMessage(
/**
* Start the event beacon worker.
*/
export async function start() {
export async function start(): Promise<void> {
if (!worker) {
const { beacon } = await import('./worker');

Expand All @@ -54,7 +54,7 @@ function notEmpty<TValue>(value: TValue | null | undefined): value is TValue {
export async function commit(
beaconWorker: Worker | undefined,
data: Pick<CommitData, 'events' | 'type'>,
) {
): Promise<CommitData | undefined> {
if (beaconWorker) {
const finishedEvents = await Promise.all(data.events);
const definedEvents: Array<PrematureEvents> =
Expand Down Expand Up @@ -86,4 +86,6 @@ export async function commit(
} else {
console.warn('Event beacon is not running.');
}

return undefined;
}
2 changes: 1 addition & 1 deletion packages/player/src/internal/beacon/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type Sessions = {
userId: number;
};

export function beacon() {
export function beacon(): void {
let queue: Array<BeaconEvent> = [];
let accessToken: string | undefined;
let clientId: string | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { runIfAuthorizedWithUser } from '../../helpers/run-if-authorized-with-us
/**
* Send event to event system scoped to play_log category.
*/
export function commit(data: Pick<CommitData, 'events'>) {
export function commit(data: Pick<CommitData, 'events'>): Promise<CommitData> {
return runIfAuthorizedWithUser(() =>
beaconCommit(worker, {
type: 'play_log' as const,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createReducer } from '../../helpers/reducer';
import { createReducer, type Reducer } from '../../helpers/reducer';
import type {
AssetPresentation,
AudioMode,
Expand Down Expand Up @@ -53,7 +53,7 @@ const defaultPayload: Payload = {
startTimestamp: -1,
};

const reducer = await createReducer<Payload, 'playback_session'>(
const reducer: Reducer<Payload, 'playback_session'> = await createReducer(
'playback_session',
defaultPayload,
);
Expand All @@ -69,14 +69,22 @@ const reducer = await createReducer<Payload, 'playback_session'>(
* of media for a certain media product has been presented
* to the user.
*/
export function playbackSession(newData: Parameters<typeof reducer>[0]) {
export function playbackSession(newData: Parameters<typeof reducer>[0]): Promise<{
payload: Payload;
name: "playback_session";
streamingSessionId: string;
} | undefined> {
return reducer(newData);
}

export function playbackSessionAction(
streamingSessionId: string,
action: Action,
) {
): Promise<{
payload: Payload;
name: "playback_session";
streamingSessionId: string;
} | undefined> {
return reducer({
actions: [action],
streamingSessionId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createReducer } from '../../helpers/reducer';
import { createReducer, type Reducer } from '../../helpers/reducer';

export type Payload = {
endReason: 'COMPLETE' | 'ERROR' | 'OTHER';
Expand All @@ -23,11 +23,15 @@ const defaultPayload: Payload = {
streamingSessionId: '',
};

const reducer = await createReducer<Payload, 'drm_license_fetch'>(
const reducer: Reducer<Payload, 'drm_license_fetch'> = await createReducer(
'drm_license_fetch',
defaultPayload,
);

export function drmLicenseFetch(newData: Parameters<typeof reducer>[0]) {
export function drmLicenseFetch(newData: Parameters<typeof reducer>[0]): Promise<{
payload: Payload;
name: "drm_license_fetch";
streamingSessionId: string;
} | undefined> {
return reducer(newData);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export { drmLicenseFetch } from './drm-license-fetch';
export { playbackInfoFetch } from './playback-info-fetch';
export { playbackStatistics } from './playback-statistics';
export { playbackStatisticsTrack, playbackStatisticsVideo, playbackStatistics } from './playback-statistics';
export { streamingSessionEnd } from './streaming-session-end';
export { streamingSessionStart } from './streaming-session-start';

Expand All @@ -11,7 +11,7 @@ import { runIfAuthorizedWithUser } from '../../helpers/run-if-authorized-with-us
/**
* Send event to event system scoped to streaming_metrics category.
*/
export function commit(data: Pick<CommitData, 'events'>) {
export function commit(data: Pick<CommitData, 'events'>): Promise<CommitData> {
return runIfAuthorizedWithUser(() =>
beaconCommit(worker, {
type: 'streaming_metrics',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createReducer } from '../../helpers/reducer';
import { createReducer, type Reducer } from '../../helpers/reducer';

export type Payload = {
endReason: 'COMPLETE' | 'ERROR' | 'OTHER';
Expand All @@ -23,14 +23,18 @@ const defaultPayload: Payload = {
streamingSessionId: '',
};

const reducer = await createReducer<Payload, 'playback_info_fetch'>(
const reducer: Reducer<Payload, 'playback_info_fetch'> = await createReducer(
'playback_info_fetch',
defaultPayload,
);

/**
* Create playbackInfoFetch event.
*/
export function playbackInfoFetch(newData: Parameters<typeof reducer>[0]) {
export function playbackInfoFetch(newData: Parameters<typeof reducer>[0]): Promise<{
payload: Payload;
name: "playback_info_fetch";
streamingSessionId: string;
} | undefined> {
return reducer(newData);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createReducer } from '../../helpers/reducer';
import { createReducer, type Reducer } from '../../helpers/reducer';
import type { OutputType } from '../../output-devices';
import type { AudioQuality, VideoQuality } from '../../types';

Expand Down Expand Up @@ -48,21 +48,19 @@ export type BasePayload = {
streamingSessionId: string;
};

export type TrackPayload = {
actualQuality: AudioQuality;
productType: 'TRACK';
};

export type VideoPayload = {
export type VideoPayload = BasePayload & {
actualQuality: VideoQuality;
productType: 'VIDEO';
};

export type Payload = BasePayload & (TrackPayload | VideoPayload);
export type TrackPayload = BasePayload & {
actualQuality: AudioQuality;
productType: 'TRACK';
};

export type PlaybackStatistics = {
name: 'playback_statistics';
payload: Payload;
payload: TrackPayload | VideoPayload;
};

export function transformOutputType(
Expand All @@ -89,7 +87,7 @@ export function transformOutputType(
}
}

const defaultPayload: Payload = {
const defaultTrackPayload: TrackPayload = {
actualAssetPresentation: 'FULL',
actualAudioMode: 'STEREO',
actualProductId: null,
Expand All @@ -111,14 +109,69 @@ const defaultPayload: Payload = {
streamingSessionId: '',
};

const reducer = await createReducer<Payload, 'playback_statistics'>(
const defaultVideoPayload: VideoPayload = {
actualAssetPresentation: 'FULL',
actualAudioMode: 'STEREO',
actualProductId: null,
actualQuality: 'HIGH',
actualStartTimestamp: 0,
actualStreamType: 'ON_DEMAND',
adaptations: [],
cdm: 'WIDEVINE',
cdmVersion: null,
endReason: 'COMPLETE',
endTimestamp: 0,
errorCode: null,
errorMessage: null,
hasAds: false,
idealStartTimestamp: 0,
outputDevice: null,
productType: 'VIDEO',
stalls: [],
streamingSessionId: '',
};

const reducer: Reducer<TrackPayload, "playback_statistics"> = await createReducer(
'playback_statistics',
defaultPayload,
defaultTrackPayload,
);

/**
* Create playbackStatistics event.
*/
export function playbackStatistics(newData: Parameters<typeof reducer>[0]) {
export function playbackStatistics(newData: Parameters<typeof reducer>[0]): Promise<{
payload: TrackPayload | VideoPayload;
name: "playback_statistics";
streamingSessionId: string;
} | undefined> {
return reducer(newData);
}

const trackPayloadReducer: Reducer<TrackPayload, "playback_statistics"> = await createReducer(
'playback_statistics',
defaultTrackPayload,
);

/**
* Create playbackStatistics event.
*/
export function playbackStatisticsTrack(newData: Parameters<typeof trackPayloadReducer>[0]): Promise<{
payload: TrackPayload;
name: "playback_statistics";
streamingSessionId: string;
} | undefined> {
return trackPayloadReducer(newData);
}

const videoPayloadReducer: Reducer<VideoPayload, "playback_statistics"> = await createReducer(
'playback_statistics',
defaultVideoPayload,
);

export function playbackStatisticsVideo(newData: Parameters<typeof videoPayloadReducer>[0]): Promise<{
payload: VideoPayload;
name: "playback_statistics";
streamingSessionId: string;
} | undefined> {
return videoPayloadReducer(newData);
}
Loading
Loading