Skip to content
Open
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
37 changes: 24 additions & 13 deletions components/pages/posts/post/PostMedia.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@
() => props.mediaType === 'animated' || (props.mediaType === 'image' && props.mediaSrc.endsWith('.gif'))
)

const triedToLoadWithProxy = shallowRef(false)
const triedToLoadPosterWithProxy = shallowRef(false)
const maxProxyRetryAttempts = 3
const mediaProxyRetryAttempts = shallowRef(0)
const posterProxyRetryAttempts = shallowRef(0)
const proxyRetryNonce = shallowRef(0)

let videoPlayer: FluidPlayerInstance | undefined

Expand Down Expand Up @@ -270,6 +272,15 @@
})
}

function buildProxyRetryUrl(url: string) {
const proxiedUrl = new URL(proxyUrl(url))

proxyRetryNonce.value++
proxiedUrl.searchParams.set('retry', proxyRetryNonce.value.toString())

return proxiedUrl.toString()
}

function startPlayingAnimatedMedia() {
isAnimatedMediaLoading.value = true
isAnimatedMediaPlaying.value = true
Expand All @@ -291,13 +302,13 @@
isVideo.value &&
isPremium.value &&
//
!triedToLoadWithProxy.value
mediaProxyRetryAttempts.value < maxProxyRetryAttempts
) {
localSrc.value = proxyUrl(props.mediaSrc)
mediaProxyRetryAttempts.value++
localSrc.value = buildProxyRetryUrl(props.mediaSrc)

reloadVideoPlayer(true)

triedToLoadWithProxy.value = true
return
}

Expand All @@ -315,23 +326,23 @@
!isAnimatedMediaPlaying.value &&
target.src === localPosterSrc.value &&
//
!triedToLoadPosterWithProxy.value
posterProxyRetryAttempts.value < maxProxyRetryAttempts
) {
localPosterSrc.value = proxyUrl(props.mediaPosterSrc)
posterProxyRetryAttempts.value++
localPosterSrc.value = buildProxyRetryUrl(props.mediaPosterSrc)

triedToLoadPosterWithProxy.value = true
return
}

// Case 2: The actual GIF failed to load
if (
isAnimatedMediaPlaying.value &&
//
!triedToLoadWithProxy.value
mediaProxyRetryAttempts.value < maxProxyRetryAttempts
) {
localSrc.value = proxyUrl(props.mediaSrc)
mediaProxyRetryAttempts.value++
localSrc.value = buildProxyRetryUrl(props.mediaSrc)

triedToLoadWithProxy.value = true
return
}
}
Expand All @@ -341,8 +352,8 @@

function manuallyReloadMedia() {
// Reset state
triedToLoadWithProxy.value = false
triedToLoadPosterWithProxy.value = false
mediaProxyRetryAttempts.value = 0
posterProxyRetryAttempts.value = 0
error.value = null

// Reload media
Expand Down