-
Notifications
You must be signed in to change notification settings - Fork 373
feat: on the fly thumbnail generation #3523
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
cd9b6b3
chore: remove expo-av support for videos
isekovanic 01cf652
feat: add thumbnail generation feature
isekovanic 1f581e0
chore: bump deps
isekovanic f565d16
Merge branch 'develop' into feat/thumbnail-generation
isekovanic 3da85cd
feat: implement rudimentary caching for thumbnails
isekovanic 0476718
feat: introduce bounded parallelism
isekovanic ff8fd1b
fix: return object results
isekovanic 683ad26
chore: tighten up scheme support
isekovanic e7626f0
fix: stop using image background
isekovanic 9c3a648
fix: tests
isekovanic 3b07660
fix: node cmd issues with new AS version
isekovanic 3fe37e2
chore: tweak config
isekovanic ade01a5
fix: clean android impl
isekovanic ce1367e
fix: optimize swift impl
isekovanic 304416d
fix: remove testing change
isekovanic 1f7a570
fix: ci
isekovanic 87dc12c
fix: android build
isekovanic 44db460
fix: android ci
isekovanic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
package/expo-package/android/src/newarch/com/streamchatexpo/StreamVideoThumbnailModule.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package com.streamchatexpo | ||
|
|
||
| import com.facebook.react.bridge.Arguments | ||
| import com.facebook.react.bridge.Promise | ||
| import com.facebook.react.bridge.ReactApplicationContext | ||
| import com.facebook.react.bridge.ReadableArray | ||
| import com.streamchatreactnative.shared.StreamVideoThumbnailGenerator | ||
| import java.util.concurrent.Executors | ||
|
|
||
| class StreamVideoThumbnailModule( | ||
| reactContext: ReactApplicationContext, | ||
| ) : NativeStreamVideoThumbnailSpec(reactContext) { | ||
| override fun getName(): String = NAME | ||
|
|
||
| override fun createVideoThumbnails(urls: ReadableArray, promise: Promise) { | ||
| val urlList = mutableListOf<String>() | ||
| for (index in 0 until urls.size()) { | ||
| urlList.add(urls.getString(index) ?: "") | ||
| } | ||
|
|
||
| executor.execute { | ||
| try { | ||
| val thumbnails = StreamVideoThumbnailGenerator.generateThumbnails(reactApplicationContext, urlList) | ||
| val result = Arguments.createArray() | ||
| thumbnails.forEach { thumbnail -> | ||
| val thumbnailMap = Arguments.createMap() | ||
| if (thumbnail.uri != null) { | ||
| thumbnailMap.putString("uri", thumbnail.uri) | ||
| } else { | ||
| thumbnailMap.putNull("uri") | ||
| } | ||
| if (thumbnail.error != null) { | ||
| thumbnailMap.putString("error", thumbnail.error) | ||
| } else { | ||
| thumbnailMap.putNull("error") | ||
| } | ||
| result.pushMap(thumbnailMap) | ||
| } | ||
| promise.resolve(result) | ||
| } catch (error: Throwable) { | ||
| promise.reject("stream_video_thumbnail_error", error.message, error) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| companion object { | ||
| const val NAME = "StreamVideoThumbnail" | ||
| private val executor = Executors.newCachedThreadPool() | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
package/expo-package/src/native/NativeStreamVideoThumbnail.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import type { TurboModule } from 'react-native'; | ||
|
|
||
| import { TurboModuleRegistry } from 'react-native'; | ||
|
|
||
| export type VideoThumbnailResult = { | ||
| error?: string | null; | ||
| uri?: string | null; | ||
| }; | ||
|
|
||
| export interface Spec extends TurboModule { | ||
| createVideoThumbnails(urls: ReadonlyArray<string>): Promise<ReadonlyArray<VideoThumbnailResult>>; | ||
| } | ||
|
|
||
| export default TurboModuleRegistry.getEnforcing<Spec>('StreamVideoThumbnail'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import NativeStreamVideoThumbnail, { type VideoThumbnailResult } from './NativeStreamVideoThumbnail'; | ||
|
|
||
| export type { VideoThumbnailResult } from './NativeStreamVideoThumbnail'; | ||
|
|
||
| export const createVideoThumbnails = async (urls: string[]): Promise<VideoThumbnailResult[]> => { | ||
| const results = await NativeStreamVideoThumbnail.createVideoThumbnails(urls); | ||
| return Array.from(results); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,18 @@ | ||
| let AudioComponent; | ||
| let VideoComponent; | ||
| let RecordingObject; | ||
|
|
||
| try { | ||
| const audioVideoPackage = require('expo-av'); | ||
| AudioComponent = audioVideoPackage.Audio; | ||
| VideoComponent = audioVideoPackage.Video; | ||
| RecordingObject = audioVideoPackage.RecordingObject; | ||
| } catch (e) { | ||
| // do nothing | ||
| } | ||
|
|
||
| if (!AudioComponent || !VideoComponent) { | ||
| if (!AudioComponent) { | ||
| console.log( | ||
| 'Audio Video library is currently not installed. To allow in-app audio playback, install the "expo-av" package.', | ||
| 'The audio library is currently not installed. To allow in-app audio playback, install the "expo-av" package.', | ||
| ); | ||
| } | ||
|
|
||
| export { AudioComponent, RecordingObject, VideoComponent }; | ||
| export { AudioComponent, RecordingObject }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
package/expo-package/src/optionalDependencies/generateThumbnail.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import { createGenerateVideoThumbnails } from 'stream-chat-react-native-core/src/utils/createGenerateVideoThumbnails'; | ||
|
|
||
| import { createVideoThumbnails, type VideoThumbnailResult } from '../native/videoThumbnail'; | ||
|
|
||
| export const generateThumbnails: ( | ||
| uris: string[], | ||
| ) => Promise<Record<string, VideoThumbnailResult>> = createGenerateVideoThumbnails({ | ||
| createVideoThumbnails, | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.