From 6f3eeec009ef3d233e7b022d9c13bfd2cd3b534b Mon Sep 17 00:00:00 2001 From: gabriellsh <40830821+gabriellsh@users.noreply.github.com> Date: Tue, 27 Jun 2023 19:40:00 -0300 Subject: [PATCH] fix(meteor): Video Record button disabled on iOS browsers (#29649) Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .changeset/itchy-hotels-care.md | 5 +++++ .../ui/client/lib/recorderjs/videoRecorder.ts | 18 +++++++++++------- .../VideoMessageRecorder.tsx | 16 ++++++++++++---- .../actions/VideoMessageAction.tsx | 3 ++- 4 files changed, 30 insertions(+), 12 deletions(-) create mode 100644 .changeset/itchy-hotels-care.md diff --git a/.changeset/itchy-hotels-care.md b/.changeset/itchy-hotels-care.md new file mode 100644 index 000000000000..93aed3ed6dce --- /dev/null +++ b/.changeset/itchy-hotels-care.md @@ -0,0 +1,5 @@ +--- +"@rocket.chat/meteor": patch +--- + +fixed video message button disabled on iOS browsers diff --git a/apps/meteor/app/ui/client/lib/recorderjs/videoRecorder.ts b/apps/meteor/app/ui/client/lib/recorderjs/videoRecorder.ts index 9d6a44521894..10424c5b3f86 100644 --- a/apps/meteor/app/ui/client/lib/recorderjs/videoRecorder.ts +++ b/apps/meteor/app/ui/client/lib/recorderjs/videoRecorder.ts @@ -17,6 +17,16 @@ class VideoRecorder { private mediaRecorder: MediaRecorder | undefined; + public getSupportedMimeTypes() { + if (window.MediaRecorder.isTypeSupported('video/webm')) { + return 'video/webm; codecs=vp8,opus'; + } + if (window.MediaRecorder.isTypeSupported('video/mp4')) { + return 'video/mp4'; + } + return ''; + } + public start(videoel?: HTMLVideoElement, cb?: (this: this, success: boolean) => void) { this.videoel = videoel; @@ -51,7 +61,7 @@ class VideoRecorder { return; } - this.mediaRecorder = new MediaRecorder(this.stream, { mimeType: 'video/webm; codecs=vp8,opus' }); + this.mediaRecorder = new MediaRecorder(this.stream, { mimeType: this.getSupportedMimeTypes() }); this.mediaRecorder.ondataavailable = (blobev) => { this.chunks.push(blobev.data); if (!this.recordingAvailable.get()) { @@ -66,7 +76,6 @@ class VideoRecorder { if (!this.videoel) { return; } - this.stream = stream; try { @@ -76,11 +85,6 @@ class VideoRecorder { this.videoel.src = URL.createObjectURL(stream as unknown as MediaSource | Blob); } - this.videoel.muted = true; - this.videoel.onloadedmetadata = () => { - void this.videoel?.play(); - }; - this.started = true; return this.cameraStarted.set(true); } diff --git a/apps/meteor/client/views/composer/VideoMessageRecorder/VideoMessageRecorder.tsx b/apps/meteor/client/views/composer/VideoMessageRecorder/VideoMessageRecorder.tsx index f9c1f2ed5a97..5d43a07d8b0b 100644 --- a/apps/meteor/client/views/composer/VideoMessageRecorder/VideoMessageRecorder.tsx +++ b/apps/meteor/client/views/composer/VideoMessageRecorder/VideoMessageRecorder.tsx @@ -29,6 +29,14 @@ const videoContainerClass = css` } `; +const getVideoRecordingExtension = () => { + const supported = VideoRecorder.getSupportedMimeTypes(); + if (supported.match(/video\/webm/)) { + return 'webm'; + } + return 'mp4'; +}; + const VideoMessageRecorder = ({ rid, tmid, chatContext, reference }: VideoMessageRecorderProps) => { const t = useTranslation(); const videoRef = useRef(null); @@ -75,8 +83,8 @@ const VideoMessageRecorder = ({ rid, tmid, chatContext, reference }: VideoMessag const handleSendRecord = async () => { const cb = async (blob: Blob) => { - const fileName = `${t('Video_record')}.webm`; - const file = new File([blob], fileName, { type: 'video/webm' }); + const fileName = `${t('Video_record')}.${getVideoRecordingExtension()}`; + const file = new File([blob], fileName, { type: VideoRecorder.getSupportedMimeTypes().split(';')[0] }); await chat?.flows.uploadFiles([file]); chat?.composer?.setRecordingVideo(false); }; @@ -94,7 +102,7 @@ const VideoMessageRecorder = ({ rid, tmid, chatContext, reference }: VideoMessag }; useEffect(() => { - if (!window.MediaRecorder.isTypeSupported('video/webm; codecs=vp8,opus')) { + if (!VideoRecorder.getSupportedMimeTypes()) { return dispatchToastMessage({ type: 'error', message: t('Browser_does_not_support_recording_video') }); } @@ -109,7 +117,7 @@ const VideoMessageRecorder = ({ rid, tmid, chatContext, reference }: VideoMessag -