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

feat: video player #29

Draft
wants to merge 10 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
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@gorhom/bottom-sheet": "^4.5.1",
"@notifee/react-native": "^7.8.0",
"@react-native-async-storage/async-storage": "^1.19.3",
"@react-native-community/slider": "^4.4.3",
"@react-native-clipboard/clipboard": "^1.12.1",
"@react-native-community/hooks": "^3.0.0",
"@react-native/eslint-config": "^0.73.1",
Expand Down Expand Up @@ -65,6 +66,10 @@
"react-native-svg": "^13.14.0",
"react-native-tcp-socket": "^6.0.6",
"react-native-vector-icons": "^10.0.0",
"react-native-video": "^5.2.1",
"react-native-video-controls": "^2.8.1",
"react-native-web": "^0.19.8",
"react-native-windows": "^0.72.1",
"readable-stream": "^4.4.2",
"revkit": "^1.1.14",
"revolt.js": "^6.0.20",
Expand Down
1 change: 1 addition & 0 deletions src/Generic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ export const app = {
openChannel: c => {},
openDirectMessage: (c: Channel) => {},
openImage: a => {},
openVideo: (a, data) => {},
openMessage: m => {},
openServerContextMenu: (s: Server | null) => {
console.log(
Expand Down
2 changes: 1 addition & 1 deletion src/Modals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {Modal, Pressable, View} from 'react-native';
import {observer} from 'mobx-react-lite';

import ImageViewer from 'react-native-image-zoom-viewer';
import VideoPlayer from 'react-native-video-controls';
import MaterialCommunityIcon from 'react-native-vector-icons/MaterialCommunityIcons';

import {API, Channel, Server, User} from 'revolt.js';
Expand Down Expand Up @@ -45,7 +46,6 @@ export const Modals = observer(() => {
const [deletableObject, setDeletableObject] = React.useState(
null as DeletableObject | null,
);

setFunction('openDirectMessage', async (dm: Channel) => {
app.openProfile(null);
app.openChannel(dm);
Expand Down
16 changes: 15 additions & 1 deletion src/components/common/messaging/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ import {enGB, enUS} from 'date-fns/locale';
import {Message as RevoltMessage} from 'revolt.js';
import {decodeTime} from 'ulid';

import {InviteEmbed, MessageEmbed, MessageReactions, PlatformModerationMessage, ReplyMessage} from './';
import {
InviteEmbed,
MessageEmbed,
MessageReactions,
PlatformModerationMessage,
ReplyMessage,
VideoEmbed,
} from './';
import {app, client, openUrl} from '../../../Generic';
import {Avatar} from '../../../Profile';
import {currentTheme, styles} from '../../../Theme';
Expand Down Expand Up @@ -391,6 +398,13 @@ export const Message = observer((props: MessageProps) => {
/>
</Pressable>
);
} else if (a.metadata?.type == 'Video') {
return (
<VideoEmbed
key={`message-${props.message._id}-video-${a._id}`}
attachment={a}
/>
);
} else {
return (
<Pressable
Expand Down
52 changes: 52 additions & 0 deletions src/components/common/messaging/VideoEmbed.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import {useState, useRef, useEffect} from 'react';
import {Dimensions, Pressable} from 'react-native';
import {observer} from 'mobx-react-lite';

import {Attachment} from 'revolt.js';
import VideoPlayer from 'react-native-video-controls';

import {app, client} from '../../../Generic';

export const VideoEmbed = observer(
({attachment: a}: {attachment: Attachment}) => {
const [expand, setExpand] = useState(false);
const video = useRef(null);
let width = a.metadata.width,
height = a.metadata.height;
if (width > Dimensions.get('screen').width - 75) {
const sizeFactor = (Dimensions.get('screen').width - 75) / width;
width = width * sizeFactor;
height = height * sizeFactor;
}
const uri = client.generateFileURL(a);
useEffect(() => {
expand &&
video.current &&
video.current.setState({isFullscreen: false, paused: true}),
setExpand(false);
}, [expand]);
return (
<Pressable>
<VideoPlayer
ref={ref => (video.current = ref)}
source={{uri}}
tapAnywhereToPause
disableBack
onEnterFullscreen={() => {
app.openVideo(uri, video.current);
setExpand(false);
}}
onLoad={() => {
video.current && video.current.setState({paused: true});
}}
style={{
width: width,
height: height,
marginBottom: 4,
borderRadius: 3,
}}
/>
</Pressable>
);
},
);
2 changes: 2 additions & 0 deletions src/components/common/messaging/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ export {MessageEmbed} from './MessageEmbed';
export {MessageReactions} from './MessageReactions';
export {PlatformModerationMessage} from './PlatformModerationMessage';
export {ReplyMessage} from './ReplyMessage';
export {VideoEmbed} from './VideoEmbed';
export {AudioPlayer} from './AudioPlayer';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the splitting of this PR, this needs to be removed

3 changes: 2 additions & 1 deletion src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {ToastAndroid} from 'react-native';
import TrackPlayer, {Event} from 'react-native-track-player';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto


import {differenceInMinutes} from 'date-fns';
import {Channel, Message} from 'revolt.js';
Expand Down Expand Up @@ -185,4 +186,4 @@ export async function fetchMessages(

export function showToast(badgeName: string) {
ToastAndroid.show(badgeName, ToastAndroid.SHORT);
}
}
162 changes: 162 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2631,6 +2631,50 @@
prompts "^2.4.0"
semver "^7.5.2"

"@react-native-community/slider@^4.4.3":
version "4.4.3"
resolved "https://registry.yarnpkg.com/@react-native-community/slider/-/slider-4.4.3.tgz#9b9dc639b88f5bfda72bd72a9dff55cbf9f777ed"
integrity sha512-WdjvGtqJfqcCiLwtbzie53Z/H6w6dIfRHhlW832D89ySAdE5DxLAsqRhDOG0eacuAxxEB+T9sGCkVMD0fa3aBg==

"@react-native-windows/cli@0.72.0":
version "0.72.0"
resolved "https://registry.yarnpkg.com/@react-native-windows/cli/-/cli-0.72.0.tgz#b7a66f6c16db80a0bf9e40a4b085f26608ad4fed"
integrity sha512-EdWFFrbnDdi1FWGARzlZtKJy1rWePn+3VogsRBNYHCOWS4m7BP/1/+F0g7504fniws3n8qDKTqCtgQ2TL6U+Qw==
dependencies:
"@react-native-windows/codegen" "0.72.0"
"@react-native-windows/fs" "0.72.0"
"@react-native-windows/package-utils" "0.72.0"
"@react-native-windows/telemetry" "0.72.0"
"@xmldom/xmldom" "^0.7.7"
chalk "^4.1.0"
cli-spinners "^2.2.0"
envinfo "^7.5.0"
find-up "^4.1.0"
glob "^7.1.1"
lodash "^4.17.15"
mustache "^4.0.1"
ora "^3.4.0"
prompts "^2.4.1"
semver "^7.3.2"
shelljs "^0.8.4"
username "^5.1.0"
uuid "^3.3.2"
xml-formatter "^2.4.0"
xml-parser "^1.2.1"
xpath "^0.0.27"

"@react-native-windows/codegen@0.72.0":
version "0.72.0"
resolved "https://registry.yarnpkg.com/@react-native-windows/codegen/-/codegen-0.72.0.tgz#687a4f2d053346d5266ce2311235ad6bcc3b3da2"
integrity sha512-kDr6Qeb7TWjpC1DEIqkVMkmfr2fsG2iF+vAxK36R2pIHI4yvKQSgujYktMU1+FW0h5fl3433F9ne8kW6KZbIGw==
dependencies:
"@react-native-windows/fs" "0.72.0"
chalk "^4.1.0"
globby "^11.0.4"
mustache "^4.0.1"
source-map-support "^0.5.19"
yargs "^16.2.0"

"@react-native-community/hooks@^3.0.0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@react-native-community/hooks/-/hooks-3.0.0.tgz#af5f2ca32eea59b792ce9e3d9a4cf0354f9b195f"
Expand Down Expand Up @@ -2766,6 +2810,11 @@
hermes-parser "0.15.0"
nullthrows "^1.1.1"

"@react-native/normalize-color@*", "@react-native/normalize-color@^2.1.0":
version "2.1.0"
resolved "https://registry.yarnpkg.com/@react-native/normalize-color/-/normalize-color-2.1.0.tgz#939b87a9849e81687d3640c5efa2a486ac266f91"
integrity sha512-Z1jQI2NpdFJCVgpY+8Dq/Bt3d+YUi1928Q+/CZm/oh66fzM0RUl54vvuXlPJKybH4pdCZey1eDTPaLHkMPNgWA==

"@react-native/metro-config@^0.73.1":
version "0.73.1"
resolved "https://registry.yarnpkg.com/@react-native/metro-config/-/metro-config-0.73.1.tgz#653da799d126d667bdc4499d1ca17acc011523e7"
Expand All @@ -2776,6 +2825,7 @@
metro-config "0.79.1"
metro-runtime "0.79.1"


"@react-native/normalize-colors@*":
version "0.73.0"
resolved "https://registry.yarnpkg.com/@react-native/normalize-colors/-/normalize-colors-0.73.0.tgz#23e15cf2a2b73ac7e5e6df8d5b86b173cfb35a3f"
Expand Down Expand Up @@ -4825,6 +4875,15 @@ deprecated-react-native-prop-types@4.1.0:
invariant "*"
prop-types "*"

deprecated-react-native-prop-types@^2.2.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/deprecated-react-native-prop-types/-/deprecated-react-native-prop-types-2.3.0.tgz#c10c6ee75ff2b6de94bb127f142b814e6e08d9ab"
integrity sha512-pWD0voFtNYxrVqvBMYf5gq3NA2GCpfodS1yNynTPc93AYA/KEMGeWDqqeUB6R2Z9ZofVhks2aeJXiuQqKNpesA==
dependencies:
"@react-native/normalize-color" "*"
invariant "*"
prop-types "*"

des.js@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/des.js/-/des.js-1.0.1.tgz#5382142e1bdc53f85d86d53e5f4aa7deb91e0843"
Expand Down Expand Up @@ -4980,6 +5039,18 @@ elliptic@^6.5.3:
minimalistic-assert "^1.0.1"
minimalistic-crypto-utils "^1.0.1"

eme-encryption-scheme-polyfill@^2.0.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/eme-encryption-scheme-polyfill/-/eme-encryption-scheme-polyfill-2.1.1.tgz#91c823ed584e8ec5a9f03a6a676def8f80c57a4c"
integrity sha512-njD17wcUrbqCj0ArpLu5zWXtaiupHb/2fIUQGdInf83GlI+Q6mmqaPGLdrke4savKAu15J/z1Tg/ivDgl14g0g==

emitter-listener@^1.0.1, emitter-listener@^1.1.1:
version "1.1.2"
resolved "https://registry.yarnpkg.com/emitter-listener/-/emitter-listener-1.1.2.tgz#56b140e8f6992375b3d7cb2cab1cc7432d9632e8"
integrity sha512-Bt1sBAGFHY9DKY+4/2cV6izcKJUf5T7/gkdmkxzX/qv9CcGH8xSwVRW5mtX03SWJtRTWSOpzCuWN9rBFYZepZQ==
dependencies:
shimmer "^1.2.0"

emittery@^0.13.1:
version "0.13.1"
resolved "https://registry.yarnpkg.com/emittery/-/emittery-0.13.1.tgz#c04b8c3457490e0847ae51fced3af52d338e3dad"
Expand Down Expand Up @@ -7291,6 +7362,11 @@ jsonify@^0.0.1:
array-includes "^3.1.5"
object.assign "^4.1.3"

keymirror@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/keymirror/-/keymirror-0.1.1.tgz#918889ea13f8d0a42e7c557250eee713adc95c35"
integrity sha512-vIkZAFWoDijgQT/Nvl2AHCMmnegN2ehgTPYuyy2hWQkQSntI0S7ESYqdLkoSe1HyEBFHHkCgSIvVdSEiWwKvCg==

keyv@^4.0.0:
version "4.5.4"
resolved "https://registry.yarnpkg.com/keyv/-/keyv-4.5.4.tgz#a879a99e29452f942439f2a405e3af8b31d4de93"
Expand Down Expand Up @@ -7491,6 +7567,7 @@ lodash.throttle@^4.1.1:
resolved "https://registry.yarnpkg.com/lodash.throttle/-/lodash.throttle-4.1.1.tgz#c23e91b710242ac70c37f1e1cda9274cc39bf2f4"
integrity sha512-wIkUCfVKpVsWo3JSZlc+8MB5it+2AN5W8J7YVMST30UrvcQNZ1Okbj+rbVniijTWE6FGYy4XJq/rHkas8qJMLQ==


lodash@^4.17.21:
version "4.17.21"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
Expand Down Expand Up @@ -9605,10 +9682,88 @@ react-native-vector-icons@^10.0.0:
prop-types "^15.7.2"
yargs "^16.1.1"

react-native-video-controls@^2.8.1:
version "2.8.1"
resolved "https://registry.yarnpkg.com/react-native-video-controls/-/react-native-video-controls-2.8.1.tgz#30ae707d8d218fed34bba3fc027b3943c5f438d9"
integrity sha512-dBmrE3TAKaR1gYMfbukjAM6Xo8OMZyRrxPzZtnaUgWcvGo11PQwzaI/j8HPD5fLgO+rlweP2pDpEJyIBsJvJkw==
dependencies:
lodash "^4.16.4"

react-native-video@^5.2.1:
version "5.2.1"
resolved "https://registry.yarnpkg.com/react-native-video/-/react-native-video-5.2.1.tgz#a17e856759d7e17eee9cbd9df0d05ba22e88d457"
integrity sha512-aJlr9MeTuQ0LpZ4n+EC9RvhoKeiPbLtI2Rxy8u7zo/wzGevbRpWHSBj9xZ5YDBXnAVXzuqyNIkGhdw7bfdIBZw==
dependencies:
deprecated-react-native-prop-types "^2.2.0"
keymirror "^0.1.1"
prop-types "^15.7.2"
shaka-player "^2.5.9"

react-native-web@^0.19.8:
version "0.19.8"
resolved "https://registry.yarnpkg.com/react-native-web/-/react-native-web-0.19.8.tgz#46127f8b310148fde11e4fef67fe625603599d47"
integrity sha512-anqGGHowJdfkYqRxzoQj6DeetJf5hyBlahN6rwksw54gXxgjbsUOe4/PyxqvjwxYafgbVo0oow23BwpsRFdrpw==
dependencies:
"@babel/runtime" "^7.18.6"
"@react-native/normalize-color" "^2.1.0"
fbjs "^3.0.4"
inline-style-prefixer "^6.0.1"
memoize-one "^6.0.0"
nullthrows "^1.1.1"
postcss-value-parser "^4.2.0"
styleq "^0.1.3"

react-native-windows@^0.72.1:
version "0.72.1"
resolved "https://registry.yarnpkg.com/react-native-windows/-/react-native-windows-0.72.1.tgz#b3e08aebb9cafd8fe7490167b7599c87e3bc6782"
integrity sha512-Bv8syVPZqxCrUzwvuXOD3z8GyCVfZKGSE752rMREDGa3+LeusICX3qgdJnF6UE+uVJNNPGGKHpSXSeqZj1dIvg==
dependencies:
"@babel/runtime" "^7.0.0"
"@jest/create-cache-key-function" "^29.2.1"
"@react-native-community/cli" "11.3.2"
"@react-native-community/cli-platform-android" "11.3.2"
"@react-native-community/cli-platform-ios" "11.3.2"
"@react-native-windows/cli" "0.72.0"
"@react-native/assets" "1.0.0"
"@react-native/assets-registry" "^0.72.0"
"@react-native/codegen" "^0.72.6"
"@react-native/gradle-plugin" "^0.72.10"
"@react-native/js-polyfills" "^0.72.1"
"@react-native/normalize-colors" "^0.72.0"
"@react-native/virtualized-lists" "^0.72.5"
abort-controller "^3.0.0"
anser "^1.4.9"
base64-js "^1.1.2"
deprecated-react-native-prop-types "4.1.0"
event-target-shim "^5.0.1"
flow-enums-runtime "^0.0.5"
invariant "^2.2.4"
jest-environment-node "^29.2.1"
jsc-android "^250231.0.0"
memoize-one "^5.0.0"
metro-runtime "0.76.5"
metro-source-map "0.76.5"
mkdirp "^0.5.1"
nullthrows "^1.1.1"
pretty-format "^26.5.2"
promise "^8.3.0"
react-devtools-core "^4.27.2"
react-refresh "^0.4.0"
react-shallow-renderer "^16.15.0"
regenerator-runtime "^0.13.2"
scheduler "0.24.0-canary-efb381bbf-20230505"
source-map-support "^0.5.19"
stacktrace-parser "^0.1.10"
use-sync-external-store "^1.0.0"
whatwg-fetch "^3.0.0"
ws "^6.2.2"
yargs "^17.6.2"

react-native@^0.72.6:
version "0.72.6"
resolved "https://registry.yarnpkg.com/react-native/-/react-native-0.72.6.tgz#9f8d090694907e2f83af22e115cc0e4a3d5fa626"
integrity sha512-RafPY2gM7mcrFySS8TL8x+TIO3q7oAlHpzEmC7Im6pmXni6n1AuufGaVh0Narbr1daxstw7yW7T9BKW5dpVc2A==

dependencies:
"@jest/create-cache-key-function" "^29.2.1"
"@react-native-community/cli" "11.3.7"
Expand Down Expand Up @@ -10221,6 +10376,13 @@ sha.js@^2.4.0, sha.js@^2.4.8:
inherits "^2.0.1"
safe-buffer "^5.0.1"

shaka-player@^2.5.9:
version "2.5.23"
resolved "https://registry.yarnpkg.com/shaka-player/-/shaka-player-2.5.23.tgz#db92d1c6cf2314f0180a2cec11b0e2f2560336f5"
integrity sha512-3MC9k0OXJGw8AZ4n/ZNCZS2yDxx+3as5KgH6Tx4Q5TRboTBBCu6dYPI5vp1DxKeyU12MBN1Zcbs7AKzXv2EnCg==
dependencies:
eme-encryption-scheme-polyfill "^2.0.1"

shallow-clone@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/shallow-clone/-/shallow-clone-3.0.1.tgz#8f2981ad92531f55035b01fb230769a40e02efa3"
Expand Down