sanity-plugin-mux-input 2.2.4 → 2.3.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 +148 -16
- package/lib/index.cjs +3995 -3676
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +210 -0
- package/lib/index.d.ts +109 -25
- package/lib/index.esm.js +4384 -0
- package/lib/index.esm.js.map +1 -0
- package/lib/index.js +3957 -3625
- package/lib/index.js.map +1 -1
- package/package.json +47 -51
- package/src/_exports/index.ts +32 -0
- package/src/actions/upload.ts +35 -40
- package/src/clients/upChunkObservable.ts +5 -1
- package/src/components/ConfigureApi.tsx +0 -1
- package/src/components/FileInputArea.tsx +92 -0
- package/src/components/FileInputButton.tsx +3 -2
- package/src/components/FileInputMenuItem.styled.tsx +2 -2
- package/src/components/FileInputMenuItem.tsx +2 -10
- package/src/components/ImportVideosFromMux.tsx +317 -0
- package/src/components/Input.tsx +3 -3
- package/src/components/PlayerActionsMenu.tsx +14 -12
- package/src/components/SelectAsset.tsx +1 -1
- package/src/components/StudioTool.tsx +11 -6
- package/src/components/TextTracksEditor.tsx +214 -0
- package/src/components/UploadConfiguration.tsx +390 -0
- package/src/components/UploadPlaceholder.tsx +41 -55
- package/src/components/Uploader.styled.tsx +0 -1
- package/src/components/Uploader.tsx +384 -0
- package/src/components/VideoDetails/DeleteDialog.tsx +20 -24
- package/src/components/VideoPlayer.tsx +33 -5
- package/src/components/VideoThumbnail.tsx +21 -7
- package/src/components/VideosBrowser.tsx +6 -3
- package/src/components/withFocusRing/withFocusRing.ts +20 -22
- package/src/hooks/useClient.ts +1 -1
- package/src/hooks/useImportMuxAssets.ts +127 -0
- package/src/hooks/useMuxAssets.ts +168 -0
- package/src/plugin.tsx +5 -5
- package/src/util/asserters.ts +9 -0
- package/src/util/createSearchFilter.ts +1 -1
- package/src/util/formatBytes.ts +32 -0
- package/src/util/generateJwt.ts +1 -0
- package/src/util/getAnimatedPosterSrc.ts +1 -1
- package/src/util/getPlaybackId.ts +1 -1
- package/src/util/getPlaybackPolicy.ts +1 -1
- package/src/util/parsers.ts +5 -0
- package/src/util/types.ts +195 -12
- package/lib/index.cjs.js +0 -5
- package/src/components/__legacy__Uploader.tsx +0 -280
- package/src/index.ts +0 -29
package/README.md
CHANGED
|
@@ -73,17 +73,125 @@ Having the ID be non-root ensures that only editors are able to see it.
|
|
|
73
73
|
|
|
74
74
|
The Mux plugin will find its access tokens by fetching this document.
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
## Fetching playback IDs and understanding the data structure
|
|
77
|
+
|
|
78
|
+
When a Mux video is uploaded/chosen in a document via this plugin, it gets stored as a reference to the video document:
|
|
79
|
+
|
|
80
|
+
```json
|
|
81
|
+
// example document
|
|
82
|
+
{
|
|
83
|
+
"_type": "exampleSchemaWithVideo",
|
|
84
|
+
// Example video field
|
|
85
|
+
"myVideoField": {
|
|
86
|
+
"_type": "mux.video",
|
|
87
|
+
"asset": {
|
|
88
|
+
"_type": "reference",
|
|
89
|
+
"_weak": true,
|
|
90
|
+
"_ref": "4e37284e-cec2-406d-973c-fdf9ab1e5598" // 👈 ID of the document holding the video's Mux data
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Before you can display videos in your frontend, you need to follow these references to fetch the asset's playback ID, which will be used to create a player. Here's an example GROQ query to expand the video reference in the example data above:
|
|
97
|
+
|
|
98
|
+
```groq
|
|
99
|
+
// Example for fetching data above
|
|
100
|
+
*[ _type == "exampleSchemaWithVideo" ] {
|
|
101
|
+
myVideoField {
|
|
102
|
+
asset-> {
|
|
103
|
+
playbackId,
|
|
104
|
+
assetId,
|
|
105
|
+
filename,
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
💡 For more information on querying references, refer to the documentation on [Writing GROQ queries for references](https://www.sanity.io/docs/reference-type#96b949753900) or on [Sanity's GraphQL API](https://www.sanity.io/docs/graphql).
|
|
112
|
+
|
|
113
|
+
For reference, here's an example `mux.videoAsset` document:
|
|
114
|
+
|
|
115
|
+
```json
|
|
116
|
+
{
|
|
117
|
+
"_id": "4e37284e-cec2-406d-973c-fdf9ab1e5598",
|
|
118
|
+
"_type": "mux.videoAsset",
|
|
119
|
+
"assetId": "7ovyI76F92n02H00mWP7lOCZMIU00N4iysDiQDNppX026HY",
|
|
120
|
+
"filename": "mux-example-video.mp4",
|
|
121
|
+
"status": "ready",
|
|
122
|
+
"playbackId": "YA02HBpY02fKWHDRMNilo301pdH02LY3k9HTcK43ItGJLWA",
|
|
123
|
+
// Full Mux asset data:
|
|
124
|
+
"data": {
|
|
125
|
+
"encoding_tier": "smart",
|
|
126
|
+
"max_resolution_tier": "1080p",
|
|
127
|
+
"aspect_ratio": "16:9",
|
|
128
|
+
"created_at": "1706645034",
|
|
129
|
+
"duration": 25.492133,
|
|
130
|
+
"status": "ready",
|
|
131
|
+
"master_access": "none",
|
|
132
|
+
"max_stored_frame_rate": 29.97,
|
|
133
|
+
"playback_ids": [
|
|
134
|
+
{
|
|
135
|
+
"id": "YA02HBpY02fKWHDRMNilo301pdH02LY3k9HTcK43ItGJLWA",
|
|
136
|
+
"policy": "signed"
|
|
137
|
+
}
|
|
138
|
+
],
|
|
139
|
+
"resolution_tier": "1080p",
|
|
140
|
+
"ingest_type": "on_demand_url",
|
|
141
|
+
"max_stored_resolution": "HD",
|
|
142
|
+
"tracks": [
|
|
143
|
+
{
|
|
144
|
+
"max_channel_layout": "stereo",
|
|
145
|
+
"max_channels": 2,
|
|
146
|
+
"id": "00MKMC73SYimw1YTh0102lPJJp9w2R5rHddpNX1N9opAMk",
|
|
147
|
+
"type": "audio",
|
|
148
|
+
"primary": true,
|
|
149
|
+
"duration": 25.45
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
"max_frame_rate": 29.97,
|
|
153
|
+
"max_height": 1080,
|
|
154
|
+
"id": "g1wEph3CVvbJL01YNKzAWMyH8N1SxW00WeECGjqwEHW9g",
|
|
155
|
+
"type": "video",
|
|
156
|
+
"duration": 25.4254,
|
|
157
|
+
"max_width": 1920
|
|
158
|
+
}
|
|
159
|
+
],
|
|
160
|
+
"id": "7ovyI76F92n02H00mWP7lOCZMIU00N4iysDiQDNppX026HY",
|
|
161
|
+
"mp4_support": "none"
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
```
|
|
77
165
|
|
|
78
|
-
|
|
166
|
+
## Playing videos in the frontend
|
|
79
167
|
|
|
80
|
-
|
|
168
|
+
We recommend using [Mux Player](https://www.mux.com/player) to properly display your videos, through packages like `@mux/mux-player` and `@mux/mux-player-react`. Here's an example of how you can use the Mux Player to display a video in a React component:
|
|
169
|
+
|
|
170
|
+
```tsx
|
|
171
|
+
'use client'
|
|
172
|
+
|
|
173
|
+
import MuxPlayer from '@mux/mux-player-react'
|
|
174
|
+
|
|
175
|
+
export default function MuxVideo({playbackId, title}: {playbackId?: string; title?: string}) {
|
|
176
|
+
if (!playbackId) return null
|
|
177
|
+
|
|
178
|
+
return <MuxPlayer playbackId={playbackId} metadata={title ? {video_title: title} : undefined} />
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
💡 You can try these recommendations through the [Codesandbox example](https://codesandbox.io/s/github/sanity-io/sanity-plugin-mux-input/tree/main/example).
|
|
183
|
+
|
|
184
|
+
## Configuring Mux video uploads
|
|
185
|
+
|
|
186
|
+
### Signed URLs (private playbacks)
|
|
81
187
|
|
|
82
188
|
To enable [signed urls](https://docs.mux.com/docs/security-signed-urls) with content uploaded to Mux, you will need to check the "Enable Signed Urls" option in the Mux Plugin configuration. Assuming that the API Access Token and Secret Key are set (as per the [Quick start](#quick-start) section).
|
|
83
189
|
|
|
84
190
|
More information for this feature of the plugin can be found on Mux's [documentation](https://docs.mux.com/docs/headless-cms-sanity#advanced-signed-urls)
|
|
85
191
|
|
|
86
|
-
|
|
192
|
+
### Encoding tier
|
|
193
|
+
|
|
194
|
+
### MP4 support (downloadable videos)
|
|
87
195
|
|
|
88
196
|
To enable [static MP4 renditions](https://docs.mux.com/guides/video/enable-static-mp4-renditions), add `mp4_support: 'standard'` to the `options` of your `mux.video` schema type.
|
|
89
197
|
|
|
@@ -95,9 +203,37 @@ export default defineConfig({
|
|
|
95
203
|
})
|
|
96
204
|
```
|
|
97
205
|
|
|
98
|
-
|
|
206
|
+
If MP4 support is enabled in the plugin's configuration, editors can still choose to enable MP4 renditions on a per-video basis when uploading new assets.
|
|
207
|
+
|
|
208
|
+
### Video resolution (max_resolution_tier)
|
|
99
209
|
|
|
100
|
-
#
|
|
210
|
+
To edit [max_resolution_tier](https://docs.mux.com/api-reference#video/operation/create-direct-upload) to support other resolutions other than 1080p, add `max_resolution_tier: '1080p' | '1440p' | '2160p'` to the `options` of your `mux.video` schema type. Defaults to `1080p`.
|
|
211
|
+
|
|
212
|
+
```js
|
|
213
|
+
import {muxInput} from 'sanity-plugin-mux-input'
|
|
214
|
+
|
|
215
|
+
export default defineConfig({
|
|
216
|
+
plugins: [muxInput({max_resolution_tier: '2160p'})],
|
|
217
|
+
})
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
When uploading new assets, editors can still choose a lower resolution for each video than configured globally.
|
|
221
|
+
|
|
222
|
+
### Encoding tier (smart or baseline)
|
|
223
|
+
|
|
224
|
+
The [encoding tier](https://docs.mux.com/guides/use-encoding-tiers) informs the cost, quality, and available platform features for the asset. You can choose between `smart` and `baseline` at the plugin configuration. Defaults to `smart`.
|
|
225
|
+
|
|
226
|
+
```js
|
|
227
|
+
import {muxInput} from 'sanity-plugin-mux-input'
|
|
228
|
+
|
|
229
|
+
export default defineConfig({
|
|
230
|
+
plugins: [muxInput({encoding_tier: 'baseline'})],
|
|
231
|
+
})
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
If `encoding_tier: 'smart'`, editors can still choose to use the `baseline` encoding tier on a per-video basis when uploading new assets.
|
|
235
|
+
|
|
236
|
+
## Contributing
|
|
101
237
|
|
|
102
238
|
Issues are actively monitored and PRs are welcome. When developing this plugin the easiest setup is:
|
|
103
239
|
|
|
@@ -111,7 +247,7 @@ Issues are actively monitored and PRs are welcome. When developing this plugin t
|
|
|
111
247
|
1. Edit `schemas/post.js` and add follow the plugin documentation to add a `mux.video` type field.
|
|
112
248
|
1. Your studio should reload, and now when you edit the plugin code it should reload the studio, when you're done creating a branch, put in a PR and a maintainer will review it. Thank you!
|
|
113
249
|
|
|
114
|
-
|
|
250
|
+
### Publishing
|
|
115
251
|
|
|
116
252
|
Run the ["CI" workflow](https://github.com/sanity-io/sanity-plugin-mux-input/actions/workflows/ci.yml).
|
|
117
253
|
Make sure to select the main branch and check "Release new version".
|
|
@@ -133,15 +269,7 @@ On the [main](/tree/main) branch this will result in:
|
|
|
133
269
|
|
|
134
270
|
After Studio v3 turns stable this behavior will change. The v2 version will then be available on the `studio-v2` dist-tag, and `studio-v3` is upgraded to live on `latest`.
|
|
135
271
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
`npm test`
|
|
139
|
-
|
|
140
|
-
## License
|
|
141
|
-
|
|
142
|
-
MIT-licensed. See LICENSE.
|
|
143
|
-
|
|
144
|
-
## Develop & test
|
|
272
|
+
### Develop & test
|
|
145
273
|
|
|
146
274
|
This plugin uses [@sanity/plugin-kit](https://github.com/sanity-io/plugin-kit)
|
|
147
275
|
with default configuration for build & watch scripts.
|
|
@@ -155,3 +283,7 @@ Run ["CI & Release" workflow](https://github.com/sanity-io/sanity-plugin-mux-inp
|
|
|
155
283
|
Make sure to select the main branch and check "Release new version".
|
|
156
284
|
|
|
157
285
|
Semantic release will only release on configured branches, so it is safe to run release on any branch.
|
|
286
|
+
|
|
287
|
+
## License
|
|
288
|
+
|
|
289
|
+
MIT-licensed. See LICENSE.
|