From 90b7e573c7b6935a634f8bc52956229a84b1dfdc Mon Sep 17 00:00:00 2001 From: philip-luther Date: Sun, 28 Jun 2020 15:36:23 +0100 Subject: [PATCH] Add Cloudflare Stream support to file player Closes https://github.com/CookPete/react-player/pull/944 --- src/players/FilePlayer.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/players/FilePlayer.js b/src/players/FilePlayer.js index 318cb02..b6032ca 100644 --- a/src/players/FilePlayer.js +++ b/src/players/FilePlayer.js @@ -9,6 +9,8 @@ const HLS_GLOBAL = 'Hls' const DASH_SDK_URL = 'https://cdnjs.cloudflare.com/ajax/libs/dashjs/VERSION/dash.all.min.js' const DASH_GLOBAL = 'dashjs' const MATCH_DROPBOX_URL = /www\.dropbox\.com\/.+/ +const MATCH_CLOUDFLARE_STREAM = /https:\/\/watch\.cloudflarestream\.com\/([a-z0-9]+)/ +const REPLACE_CLOUDFLARE_STREAM = 'https://videodelivery.net/{id}/manifest/video.m3u8' export default class FilePlayer extends Component { static displayName = 'FilePlayer' @@ -114,7 +116,13 @@ export default class FilePlayer extends Component { } shouldUseHLS (url) { - return (HLS_EXTENSIONS.test(url) && !IOS) || this.props.config.forceHLS + if (this.props.config.forceHLS) { + return true + } + if (IOS) { + return false + } + return HLS_EXTENSIONS.test(url) || MATCH_CLOUDFLARE_STREAM.test(url) } shouldUseDASH (url) { @@ -135,7 +143,13 @@ export default class FilePlayer extends Component { this.hls.on(Hls.Events.ERROR, (e, data) => { this.props.onError(e, data, this.hls, Hls) }) - this.hls.loadSource(url) + if (MATCH_CLOUDFLARE_STREAM.test(url)) { + const id = url.match(MATCH_CLOUDFLARE_STREAM)[1] + console.log(REPLACE_CLOUDFLARE_STREAM.replace('{id}', id)) + this.hls.loadSource(REPLACE_CLOUDFLARE_STREAM.replace('{id}', id)) + } else { + this.hls.loadSource(url) + } this.hls.attachMedia(this.player) }) }