🎥 Make videos programmatically with React
`@remotion/webcodecs`: Send usage event with `@remotion/licensing`
Jonny Burger005354d1e093
diff --git a/packages/licensing/src/register-usage-point.ts b/packages/licensing/src/register-usage-point.tsindex 79311e7967..b22be8a6a8 100644--- a/packages/licensing/src/register-usage-point.ts+++ b/packages/licensing/src/register-usage-point.ts@@ -26,8 +26,8 @@ export const registerUsageEvent = async ({succeeded,event,}: {- apiKey: string;- host: string;+ apiKey: string | null;+ host: string | null;succeeded: boolean;event: UsageEventType;}): Promise<RegisterUsageEventResponse> => {diff --git a/packages/licensing/src/test/register.test.ts b/packages/licensing/src/test/register.test.tsindex f6cf10dd43..0b44f2254d 100644--- a/packages/licensing/src/test/register.test.ts+++ b/packages/licensing/src/test/register.test.ts@@ -7,7 +7,7 @@ import {registerUsageEvent} from '../register-usage-point';test('Should be able to track production usage', async () => {const result = await registerUsageEvent({- apiKey: 'rm_pub_1dd7193534bbe72571b55bd43926654ddaaca3dd6f07772b',+ apiKey: 'rm_pub_cbbf1d1e7f07cb0b86daa0247693d6c9af4740463768f2f6',host: 'http://localhost:50955',succeeded: true,event: 'webcodec-conversion',@@ -20,7 +20,7 @@ test('Should be able to track production usage', async () => {test('Should be able to track development usage', async () => {const result = await registerUsageEvent({- apiKey: 'rm_pub_1dd7193534bbe72571b55bd43926654ddaaca3dd6f07772b',+ apiKey: 'rm_pub_cbbf1d1e7f07cb0b86daa0247693d6c9af4740463768f2f6',host: 'https://remotion.dev',succeeded: true,event: 'webcodec-conversion',@@ -30,8 +30,20 @@ test('Should be able to track development usage', async () => {classification: 'billable',});});+test('Should be able to track without host', async () => {+ const result = await registerUsageEvent({+ apiKey: 'rm_pub_cbbf1d1e7f07cb0b86daa0247693d6c9af4740463768f2f6',+ host: null,+ succeeded: true,+ event: 'webcodec-conversion',+ });+ expect(result).toEqual({+ billable: true,+ classification: 'billable',+ });+});-test('Should reject invalid API key', async () => {+test('Should reject invalid API key', () => {const result = registerUsageEvent({apiKey: 'rm_pub_1dd719b',host: 'http://localhost:50955',@@ -63,7 +75,7 @@ test('should require secret key for usage', () => {test('should be able to get usage', async () => {const result = await getUsage({- apiKey: 'rm_sec_7cef7338672c2b474729ac081134a6ded7dc360baf0068fe',+ apiKey: 'rm_sec_b776a51f683c850101ece5c580c7db7281397d1864e076a9',since: null,});@@ -75,7 +87,7 @@ test('should be able to get usage', async () => {expect(result.cloudRenders.failed).toBeGreaterThanOrEqual(0);});-test('should not be able to get usage older than 90 says', async () => {+test('should not be able to get usage older than 90 says', () => {const result = getUsage({apiKey: 'rm_sec_7cef7338672c2b474729ac081134a6ded7dc360baf0068fe',since: new Date().getTime() - 1000 * 60 * 60 * 24 * 700,diff --git a/packages/webcodecs/package.json b/packages/webcodecs/package.jsonindex 4064c3e16a..32ea1ace9a 100644--- a/packages/webcodecs/package.json+++ b/packages/webcodecs/package.json@@ -24,7 +24,8 @@"author": "Jonny Burger <[email protected]>","license": "Remotion License (See https://remotion.dev/docs/webcodecs#license)","dependencies": {- "@remotion/media-parser": "workspace:*"+ "@remotion/media-parser": "workspace:*",+ "@remotion/licensing": "workspace:*"},"peerDependencies": {},"devDependencies": {diff --git a/packages/webcodecs/src/convert-media.ts b/packages/webcodecs/src/convert-media.tsindex 86697a3c83..5face19d43 100644--- a/packages/webcodecs/src/convert-media.ts+++ b/packages/webcodecs/src/convert-media.ts@@ -26,11 +26,13 @@ import {generateOutputFilename} from './generate-output-filename';import type {ConvertMediaAudioCodec} from './get-available-audio-codecs';import type {ConvertMediaContainer} from './get-available-containers';import type {ConvertMediaVideoCodec} from './get-available-video-codecs';+import {Log} from './log';import {makeAudioTrackHandler} from './on-audio-track';import {type ConvertMediaOnAudioTrackHandler} from './on-audio-track-handler';import {makeVideoTrackHandler} from './on-video-track';import {type ConvertMediaOnVideoTrackHandler} from './on-video-track-handler';import {selectContainerCreator} from './select-container-creator';+import {sendUsageEvent} from './send-telemetry-event';import {throttledStateUpdate} from './throttled-state-update';export type ConvertMediaProgress = {@@ -74,6 +76,7 @@ export const convertMedia = async function <writer,progressIntervalInMs,rotate,+ apiKey,...more}: {src: ParseMediaOptions<F>['src'];@@ -90,6 +93,7 @@ export const convertMedia = async function <writer?: WriterInterface;progressIntervalInMs?: number;rotate?: number;+ apiKey?: string | null;} & ParseMediaDynamicOptions<F>): Promise<ConvertMediaResult> {if (userPassedAbortSignal?.aborted) {return Promise.reject(new Error('Aborted'));@@ -243,7 +247,17 @@ export const convertMedia = async function <finalState: throttledState.get(),});})+ .then(() => {+ sendUsageEvent({succeeded: true, apiKey: apiKey ?? null}).catch((err) => {+ Log.error('Failed to send usage event', err);+ });+ }).catch((err) => {+ sendUsageEvent({succeeded: false, apiKey: apiKey ?? null}).catch(+ (err2) => {+ Log.error('Failed to send usage event hmm', err2);+ },+ );reject(err);}).finally(() => {diff --git a/packages/webcodecs/src/send-telemetry-event.ts b/packages/webcodecs/src/send-telemetry-event.tsnew file mode 100644index 0000000000..fa6e4f3eaa--- /dev/null+++ b/packages/webcodecs/src/send-telemetry-event.ts@@ -0,0 +1,26 @@+import {registerUsageEvent} from '@remotion/licensing';++export const sendUsageEvent = async ({+ apiKey,+ succeeded,+}: {+ apiKey: string | null;+ succeeded: boolean;+}) => {+ const host =+ typeof window === 'undefined'+ ? null+ : typeof window.location === 'undefined'+ ? null+ : (window.location.origin ?? null);+ if (host === null) {+ return;+ }++ await registerUsageEvent({+ apiKey,+ event: 'webcodec-conversion',+ host,+ succeeded,+ });+};diff --git a/packages/webcodecs/tsconfig.json b/packages/webcodecs/tsconfig.jsonindex 1d969cbacb..2aee3f8f2a 100644--- a/packages/webcodecs/tsconfig.json+++ b/packages/webcodecs/tsconfig.json@@ -10,6 +10,9 @@"references": [{"path": "../media-parser"+ },+ {+ "path": "../licensing"}]}diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 5e7fb293e8..26fccb7556 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -3024,6 +3024,9 @@ importers:packages/webcodecs:dependencies:+ '@remotion/licensing':+ specifier: workspace:*+ version: link:../licensing'@remotion/media-parser':specifier: workspace:*version: link:../media-parser