diff --git a/src/experiments.ts b/src/experiments.ts index 50d6285..ba72287 100644 --- a/src/experiments.ts +++ b/src/experiments.ts @@ -4,7 +4,8 @@ export enum Experiment { TWEET_DETAIL_API = 'TWEET_DETAIL_API', DISCORD_NATIVE_MULTI_IMAGE = 'DISCORD_NATIVE_MULTI_IMAGE', TRANSCODE_GIFS = 'TRANSCODE_GIFS', - IV_FORCE_THREAD_UNROLL = 'IV_FORCE_THREAD_UNROLL' + IV_FORCE_THREAD_UNROLL = 'IV_FORCE_THREAD_UNROLL', + DISCORD_VIDEO_REDIRECT_WORKAROUND = 'DISCORD_VIDEO_REDIRECT_WORKAROUND' } type ExperimentConfig = { @@ -43,6 +44,11 @@ const Experiments: { [key in Experiment]: ExperimentConfig } = { name: 'IV force thread unroll', description: 'Force thread unroll for Telegram Instant View', percentage: 1 + }, + [Experiment.DISCORD_VIDEO_REDIRECT_WORKAROUND]: { + name: 'Video redirect workaround', + description: 'Workaround for video playback issues on Discord', + percentage: 1 } }; diff --git a/src/render/video.ts b/src/render/video.ts index bd00b8c..271fbbe 100644 --- a/src/render/video.ts +++ b/src/render/video.ts @@ -62,6 +62,11 @@ export const renderVideo = ( `https://${Constants.GIF_TRANSCODE_DOMAIN}` ); console.log('We passed checks for transcoding GIFs, feeding embed url', url); + } else if ( + userAgent?.includes('Discord') && + experimentCheck(Experiment.DISCORD_VIDEO_REDIRECT_WORKAROUND, !!Constants.API_HOST_LIST) + ) { + url = `https://${Constants.API_HOST_LIST[0]}/2/hit?url=${encodeURIComponent(url)}`; } /* Push the raw video-related headers */