sanity-plugin-mux-input 2.14.0 → 2.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -24
- package/dist/index.d.mts +13 -1
- package/dist/index.d.ts +13 -1
- package/dist/index.js +1057 -470
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1059 -472
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/_exports/index.ts +1 -0
- package/src/actions/secrets.ts +6 -1
- package/src/actions/upload.ts +1 -1
- package/src/components/ConfigureApi.tsx +51 -5
- package/src/components/EditCaptionDialog.tsx +2 -2
- package/src/components/InputBrowser.tsx +8 -2
- package/src/components/PageSelector.tsx +4 -7
- package/src/components/Player.styled.tsx +7 -2
- package/src/components/PlayerActionsMenu.tsx +15 -1
- package/src/components/ResyncMetadata.tsx +152 -73
- package/src/components/SelectAsset.tsx +9 -3
- package/src/components/StudioTool.tsx +2 -2
- package/src/components/TextTracksManager.tsx +11 -55
- package/src/components/UploadConfiguration.tsx +104 -343
- package/src/components/Uploader.tsx +18 -7
- package/src/components/VideoDetails/VideoDetails.tsx +55 -19
- package/src/components/VideoDetails/useVideoDetails.ts +15 -1
- package/src/components/VideoInBrowser.tsx +53 -6
- package/src/components/VideoPlayer.tsx +120 -47
- package/src/components/VideoThumbnail.tsx +84 -72
- package/src/components/VideosBrowser.tsx +7 -5
- package/src/components/uploadConfiguration/PlaybackPolicy.tsx +95 -6
- package/src/components/uploadConfiguration/PlaybackPolicyOption.tsx +26 -10
- package/src/components/uploadConfiguration/ResolutionTierSelector.tsx +71 -0
- package/src/components/uploadConfiguration/StaticRenditionSelector.tsx +179 -0
- package/src/context/DrmPlaybackWarningContext.tsx +93 -0
- package/src/hooks/useFetchFileSize.ts +54 -0
- package/src/hooks/useMediaMetadata.ts +100 -0
- package/src/hooks/useResyncAsset.ts +110 -0
- package/src/hooks/useResyncMuxMetadata.ts +33 -0
- package/src/hooks/useSaveSecrets.ts +10 -3
- package/src/hooks/useSecretsDocumentValues.ts +9 -1
- package/src/hooks/useSecretsFormState.ts +6 -3
- package/src/schema.ts +5 -0
- package/src/util/addKeysToMuxData.ts +30 -0
- package/src/util/asserters.ts +14 -0
- package/src/util/createUrlParamsObject.ts +7 -3
- package/src/util/generateJwt.ts +11 -2
- package/src/util/getPlaybackPolicy.ts +63 -4
- package/src/util/getStoryboardSrc.ts +7 -3
- package/src/util/getVideoMetadata.ts +1 -0
- package/src/util/getVideoSrc.ts +9 -9
- package/src/util/readSecrets.ts +3 -1
- package/src/util/textTracks.ts +6 -3
- package/src/util/tryWithSuspend.ts +22 -0
- package/src/util/types.ts +27 -2
- package/src/util/getPlaybackId.ts +0 -9
package/src/util/textTracks.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type {SanityClient} from '@sanity/client'
|
|
|
2
2
|
|
|
3
3
|
import {getAsset} from '../actions/assets'
|
|
4
4
|
import {generateJwt} from './generateJwt'
|
|
5
|
-
import {getPlaybackId} from './
|
|
5
|
+
import {getPlaybackId} from './getPlaybackPolicy'
|
|
6
6
|
import {getPlaybackPolicy} from './getPlaybackPolicy'
|
|
7
7
|
import type {MuxTextTrack, VideoAssetDocument} from './types'
|
|
8
8
|
|
|
@@ -169,6 +169,9 @@ export async function pollTrackStatus(
|
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
+
/**
|
|
173
|
+
* May throw a Promise. Call this with {@link tryWithSuspend} or rethrow the Promise
|
|
174
|
+
*/
|
|
172
175
|
export async function downloadVttFile(
|
|
173
176
|
client: SanityClient,
|
|
174
177
|
asset: VideoAssetDocument,
|
|
@@ -191,11 +194,11 @@ export async function downloadVttFile(
|
|
|
191
194
|
throw new Error('Playback ID is required')
|
|
192
195
|
}
|
|
193
196
|
|
|
194
|
-
const playbackPolicy = getPlaybackPolicy(asset)
|
|
197
|
+
const playbackPolicy = getPlaybackPolicy(asset)?.policy
|
|
195
198
|
|
|
196
199
|
let downloadUrl = `https://stream.mux.com/${playbackId}/text/${track.id}.vtt`
|
|
197
200
|
|
|
198
|
-
if (playbackPolicy === 'signed') {
|
|
201
|
+
if (playbackPolicy === 'signed' || playbackPolicy === 'drm') {
|
|
199
202
|
const token = generateJwt(client, playbackId, 'v')
|
|
200
203
|
downloadUrl += `?token=${token}`
|
|
201
204
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* When running `suspend()` from react-suspend a function may throw a Promise
|
|
3
|
+
* causing unexpected behavior when catching.
|
|
4
|
+
* @param block Your block of code that uses suspend
|
|
5
|
+
* @param onError (optional) How to handle a regular Error
|
|
6
|
+
* @returns Whatever is returned by the block if it succeeds, otherwise whatever is resolved by onError if defined
|
|
7
|
+
* @throws rethrows the caught Promise to comply with Suspense logic
|
|
8
|
+
*/
|
|
9
|
+
export function tryWithSuspend<T, E>(
|
|
10
|
+
block: () => T,
|
|
11
|
+
onError?: (error: Error) => E
|
|
12
|
+
): T | E | undefined {
|
|
13
|
+
try {
|
|
14
|
+
return block()
|
|
15
|
+
} catch (errorOrPromise) {
|
|
16
|
+
if (errorOrPromise instanceof Promise) {
|
|
17
|
+
// react-suspend will throw a Promise
|
|
18
|
+
throw errorOrPromise
|
|
19
|
+
}
|
|
20
|
+
return onError ? onError(errorOrPromise as Error) : undefined
|
|
21
|
+
}
|
|
22
|
+
}
|
package/src/util/types.ts
CHANGED
|
@@ -89,6 +89,13 @@ export interface MuxInputConfig {
|
|
|
89
89
|
*/
|
|
90
90
|
defaultPublic?: boolean
|
|
91
91
|
|
|
92
|
+
/**
|
|
93
|
+
* Enables DRM Protection by default, if you configured your DRM Configuration Id.
|
|
94
|
+
* @see {@link https://www.mux.com/docs/guides/protect-videos-with-drm}
|
|
95
|
+
* @defaultValue true
|
|
96
|
+
*/
|
|
97
|
+
defaultDrm?: boolean
|
|
98
|
+
|
|
92
99
|
/**
|
|
93
100
|
* Auto-generate captions for these languages by default.
|
|
94
101
|
* Requires `"video_quality": "plus"`
|
|
@@ -124,6 +131,13 @@ export interface MuxInputConfig {
|
|
|
124
131
|
*/
|
|
125
132
|
disableTextTrackConfig?: boolean
|
|
126
133
|
|
|
134
|
+
/**
|
|
135
|
+
* Whether or not to show the playback warning when trying to watch DRM content for the first time.
|
|
136
|
+
*
|
|
137
|
+
* @defaultValue false
|
|
138
|
+
*/
|
|
139
|
+
disableDrmPlaybackWarning?: boolean
|
|
140
|
+
|
|
127
141
|
/**
|
|
128
142
|
* The mime types that are accepted by the input.
|
|
129
143
|
*
|
|
@@ -266,6 +280,7 @@ export interface UploadConfig
|
|
|
266
280
|
text_tracks: UploadTextTrack[]
|
|
267
281
|
signed_policy: boolean
|
|
268
282
|
public_policy: boolean
|
|
283
|
+
drm_policy: boolean
|
|
269
284
|
}
|
|
270
285
|
|
|
271
286
|
/**
|
|
@@ -308,18 +323,28 @@ export interface MuxNewAssetSettings
|
|
|
308
323
|
}[]
|
|
309
324
|
|
|
310
325
|
/** An array of playback policy names that you want applied to this asset and available through playback_ids. */
|
|
311
|
-
playback_policy
|
|
326
|
+
playback_policy?: PlaybackPolicy[]
|
|
327
|
+
|
|
328
|
+
/** An array of playback policy objects that you want applied to this asset and available through playback_ids. advanced_playback_policies must be used instead of playback_policies when creating a DRM playback ID. */
|
|
329
|
+
advanced_playback_policies: AdvancedPlaybackPolicy[]
|
|
312
330
|
|
|
313
331
|
/** Arbitrary user-supplied metadata that will be included in the asset details and related webhooks. */
|
|
314
332
|
passthrough?: string
|
|
315
333
|
}
|
|
316
334
|
|
|
335
|
+
/** Used by advanced_playback_policies, allows to define DRM config. */
|
|
336
|
+
export type AdvancedPlaybackPolicy = {
|
|
337
|
+
policy: PlaybackPolicy
|
|
338
|
+
drm_configuration_id?: string
|
|
339
|
+
}
|
|
340
|
+
|
|
317
341
|
export interface Secrets {
|
|
318
342
|
token: string | null
|
|
319
343
|
secretKey: string | null
|
|
320
344
|
enableSignedUrls: boolean
|
|
321
345
|
signingKeyId: string | null
|
|
322
346
|
signingKeyPrivate: string | null
|
|
347
|
+
drmConfigId: string | null
|
|
323
348
|
}
|
|
324
349
|
|
|
325
350
|
// This narrowed type indicates that there may be assets that are signed, and we have the secrets to access them
|
|
@@ -366,7 +391,7 @@ export interface AssetThumbnailOptions {
|
|
|
366
391
|
asset: Pick<VideoAssetDocument, 'playbackId' | 'data' | 'thumbTime' | 'filename' | 'assetId'>
|
|
367
392
|
}
|
|
368
393
|
|
|
369
|
-
export type PlaybackPolicy = 'signed' | 'public'
|
|
394
|
+
export type PlaybackPolicy = 'signed' | 'public' | 'drm'
|
|
370
395
|
|
|
371
396
|
export interface MuxErrors {
|
|
372
397
|
type: string
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type {VideoAssetDocument} from './types'
|
|
2
|
-
|
|
3
|
-
export function getPlaybackId(asset: Pick<VideoAssetDocument, 'playbackId'>): string {
|
|
4
|
-
if (!asset?.playbackId) {
|
|
5
|
-
console.error('Asset is missing a playbackId', {asset})
|
|
6
|
-
throw new TypeError(`Missing playbackId`)
|
|
7
|
-
}
|
|
8
|
-
return asset.playbackId
|
|
9
|
-
}
|