Page MenuHomePhabricator

[web] Preload encrypted media
ClosedPublic

Authored by bartek on May 31 2023, 11:58 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Apr 18, 1:56 AM
Unknown Object (File)
Thu, Apr 18, 1:56 AM
Unknown Object (File)
Thu, Apr 18, 1:56 AM
Unknown Object (File)
Thu, Apr 18, 1:56 AM
Unknown Object (File)
Thu, Apr 18, 1:52 AM
Unknown Object (File)
Feb 27 2024, 6:07 AM
Unknown Object (File)
Feb 27 2024, 6:07 AM
Unknown Object (File)
Feb 27 2024, 6:07 AM
Subscribers

Details

Summary

Resolves ENG-3679.
Used fetch to preload encrypted media. The current preloadImage function used to preload them by creating a dummy <img /> element and setting the src property, which was not suitable for encrypted media.

The introduced function in fact preloads any request, including images, but I left the original because browser might have some optimizations for images. Also it is used in other places in the codebase e.g. to get the dimensions.

Test Plan

Entered an encrypted media chat and selected a photo to send. Observed the Dev Tools Network tab to see that the encrypted media was preloaded:

Screenshot 2023-06-01 at 08.35.07.png (216×1 px, 136 KB)

Note the two subsequent requests to b281...3d58. The first one is sent from the preload function (media-utils.js, 251ms), while the other is read from disk-cache. Remember to uncheck the "Disable cache" option in devtools.

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

bartek held this revision as a draft.
bartek published this revision for review.Jun 1 2023, 12:17 AM
bartek added inline comments.
web/media/media-utils.js
72 ↗(On Diff #27335)

Typo, I'll fix this before landing

Two concerns:

  1. Unlike native, it doesn't appear that we are waiting on the preload for anything. On native, we show the local URI until the preload completes. On web, for non-encrypted media we delete the local URI when the preload completes... but we don't wait for the preload to start showing the new URI, do we? It seems like we're likely to have a "flicker" still after landing this diff.
  2. It seems like there are two parts we could consider for a "preload": download and decrypt. To perfectly avoid a "flicker", it feels like we'd also probably want to wait for the decrypt before showing the remote URI (but this would require 1 to be done first).

Assuming you agree with my assessment, could you create a task (or multiple tasks) for these before landing?

web/media/media-utils.js
61 ↗(On Diff #27335)

Typo

This revision is now accepted and ready to land.Jun 1 2023, 7:58 AM

Fix typos. Rebase before landing

Two concerns:

  1. Unlike native, it doesn't appear that we are waiting on the preload for anything. On native, we show the local URI until the preload completes. On web, for non-encrypted media we delete the local URI when the preload completes... but we don't wait for the preload to start showing the new URI, do we? It seems like we're likely to have a "flicker" still after landing this diff.
  2. It seems like there are two parts we could consider for a "preload": download and decrypt. To perfectly avoid a "flicker", it feels like we'd also probably want to wait for the decrypt before showing the remote URI (but this would require 1 to be done first).

Assuming you agree with my assessment, could you create a task (or multiple tasks) for these before landing?

This diff is not intended to fix the flickering issue. We have ENG-3956 to track that. Your concerns are linked in that task.

This revision was automatically updated to reflect the committed changes.