2021-08-05 09:47:00 -04:00
|
|
|
/* eslint-disable react-hooks/rules-of-hooks */
|
2021-07-30 17:40:49 -04:00
|
|
|
import { Embed } from "revolt-api/types/January";
|
2021-07-05 06:23:23 -04:00
|
|
|
|
|
|
|
import styles from "./Embed.module.scss";
|
|
|
|
|
|
|
|
import { useIntermediate } from "../../../../context/intermediate/Intermediate";
|
2021-07-24 06:22:08 -04:00
|
|
|
import { useClient } from "../../../../context/revoltjs/RevoltClient";
|
2021-06-20 17:09:18 -04:00
|
|
|
|
|
|
|
interface Props {
|
2021-07-05 06:25:20 -04:00
|
|
|
embed: Embed;
|
|
|
|
width?: number;
|
|
|
|
height: number;
|
2021-06-20 17:09:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export default function EmbedMedia({ embed, width, height }: Props) {
|
2021-07-05 06:25:20 -04:00
|
|
|
if (embed.type !== "Website") return null;
|
|
|
|
const { openScreen } = useIntermediate();
|
2021-07-24 06:22:08 -04:00
|
|
|
const client = useClient();
|
2021-06-20 17:09:18 -04:00
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
switch (embed.special?.type) {
|
|
|
|
case "YouTube":
|
|
|
|
return (
|
|
|
|
<iframe
|
2021-07-24 06:22:08 -04:00
|
|
|
loading="lazy"
|
2021-07-05 06:25:20 -04:00
|
|
|
src={`https://www.youtube-nocookie.com/embed/${embed.special.id}?modestbranding=1`}
|
|
|
|
allowFullScreen
|
|
|
|
style={{ height }}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
case "Twitch":
|
|
|
|
return (
|
|
|
|
<iframe
|
|
|
|
src={`https://player.twitch.tv/?${embed.special.content_type.toLowerCase()}=${
|
|
|
|
embed.special.id
|
|
|
|
}&parent=${window.location.hostname}&autoplay=false`}
|
|
|
|
frameBorder="0"
|
|
|
|
allowFullScreen
|
|
|
|
scrolling="no"
|
2021-07-24 06:22:08 -04:00
|
|
|
loading="lazy"
|
2021-07-05 06:25:20 -04:00
|
|
|
style={{ height }}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
case "Spotify":
|
|
|
|
return (
|
|
|
|
<iframe
|
|
|
|
src={`https://open.spotify.com/embed/${embed.special.content_type}/${embed.special.id}`}
|
2021-07-24 06:22:08 -04:00
|
|
|
loading="lazy"
|
2021-07-05 06:25:20 -04:00
|
|
|
frameBorder="0"
|
|
|
|
allowFullScreen
|
|
|
|
allowTransparency
|
|
|
|
style={{ height }}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
case "Soundcloud":
|
|
|
|
return (
|
|
|
|
<iframe
|
|
|
|
src={`https://w.soundcloud.com/player/?url=${encodeURIComponent(
|
|
|
|
embed.url!,
|
|
|
|
)}&color=%23FF7F50&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false&show_teaser=true&visual=true`}
|
|
|
|
frameBorder="0"
|
|
|
|
scrolling="no"
|
2021-07-24 06:22:08 -04:00
|
|
|
loading="lazy"
|
2021-07-05 06:25:20 -04:00
|
|
|
style={{ height }}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
case "Bandcamp": {
|
|
|
|
return (
|
|
|
|
<iframe
|
|
|
|
src={`https://bandcamp.com/EmbeddedPlayer/${embed.special.content_type.toLowerCase()}=${
|
|
|
|
embed.special.id
|
|
|
|
}/size=large/bgcol=181a1b/linkcol=056cc4/tracklist=false/transparent=true/`}
|
|
|
|
seamless
|
2021-07-24 06:22:08 -04:00
|
|
|
loading="lazy"
|
2021-07-05 06:25:20 -04:00
|
|
|
style={{ height }}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
if (embed.image) {
|
2021-07-10 10:57:29 -04:00
|
|
|
const url = embed.image.url;
|
2021-07-05 06:25:20 -04:00
|
|
|
return (
|
|
|
|
<img
|
|
|
|
className={styles.image}
|
2021-07-24 06:22:08 -04:00
|
|
|
src={client.proxyFile(url)}
|
|
|
|
loading="lazy"
|
2021-07-05 06:25:20 -04:00
|
|
|
style={{ width, height }}
|
|
|
|
onClick={() =>
|
|
|
|
openScreen({
|
|
|
|
id: "image_viewer",
|
|
|
|
embed: embed.image,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
onMouseDown={(ev) =>
|
|
|
|
ev.button === 1 && window.open(url, "_blank")
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-06-20 17:09:18 -04:00
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
return null;
|
2021-06-20 17:09:18 -04:00
|
|
|
}
|