Skip to content

Commit

Permalink
use the window hostname on web for twitch embeds (#2311)
Browse files Browse the repository at this point in the history
  • Loading branch information
haileyok authored Dec 26, 2023
1 parent cd7a25f commit 7e3e6ca
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/lib/strings/embed-player.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {Platform} from 'react-native'

export type EmbedPlayerParams =
| {type: 'youtube_video'; videoId: string; playerUri: string}
| {type: 'twitch_live'; channelId: string; playerUri: string}
Expand Down Expand Up @@ -48,12 +50,15 @@ export function parseEmbedPlayerFromUrl(

// twitch
if (urlp.hostname === 'twitch.tv' || urlp.hostname === 'www.twitch.tv') {
const parent =
Platform.OS === 'web' ? window.location.hostname : 'localhost'

const parts = urlp.pathname.split('/')
if (parts.length === 2 && parts[1]) {
return {
type: 'twitch_live',
channelId: parts[1],
playerUri: `https://player.twitch.tv/?volume=0.5&!muted&autoplay&channel=${parts[1]}&parent=localhost`,
playerUri: `https://player.twitch.tv/?volume=0.5&!muted&autoplay&channel=${parts[1]}&parent=${parent}`,
}
}
}
Expand Down

0 comments on commit 7e3e6ca

Please sign in to comment.