Commit 7519b8b7 authored by Wojciech Barcik's avatar Wojciech Barcik
Browse files

Implement sandbox in "reactish" way

parent 7f0131e9
......@@ -31,25 +31,38 @@ export const sandboxConfig = {
* @param h
* @returns {*}
*/
export function genIframeMd(idx, dtubeId, w, h) {
export function genIframeMd(idx, dtubeId, width, height) {
const url = `https://emb.d.tube/#!/${dtubeId}`;
let sandbox = sandboxConfig.useSandbox;
if (sandbox) {
if (
Object.prototype.hasOwnProperty.call(
sandboxConfig,
'sandboxAttributes'
)
) {
sandbox = sandboxConfig.sandboxAttributes.join(' ');
}
}
const iframeProps = {
key: idx,
src: url,
width,
height,
frameBorder: '0',
allowFullScreen: 'allowFullScreen',
};
if (sandbox) {
iframeProps.sandbox = sandbox;
}
return (
<div key={`dtube-${dtubeId}-${idx}`} className="videoWrapper">
<iframe
title="DTube embedded player"
key={idx}
src={url}
width={w}
height={h}
frameBorder="0"
allowFullScreen
sandbox={
sandboxConfig.useSandbox
? sandboxConfig.sandboxAttributes
? sandboxConfig.sandboxAttributes.join(' ')
: true
: ''
}
// eslint-disable-next-line react/jsx-props-no-spreading
{...iframeProps}
/>
</div>
);
......
......@@ -56,8 +56,6 @@ https://twitter.com/missybahia/status/1281295770298318849
## vimeo iframe embedded from link
Looks it's broken here, but works at production site.
https://player.vimeo.com/video/179213493
......
......@@ -33,25 +33,38 @@ export const sandboxConfig = {
* @param h
* @returns {*}
*/
export function genIframeMd(idx, threespeakId, w, h) {
export function genIframeMd(idx, threespeakId, width, height) {
const url = `https://3speak.online/embed?v=${threespeakId}`;
let sandbox = sandboxConfig.useSandbox;
if (sandbox) {
if (
Object.prototype.hasOwnProperty.call(
sandboxConfig,
'sandboxAttributes'
)
) {
sandbox = sandboxConfig.sandboxAttributes.join(' ');
}
}
const iframeProps = {
key: idx,
src: url,
width,
height,
frameBorder: '0',
allowFullScreen: 'allowFullScreen',
};
if (sandbox) {
iframeProps.sandbox = sandbox;
}
return (
<div key={`threespeak-${threespeakId}-${idx}`} className="videoWrapper">
<iframe
title="3Speak embedded player"
key={idx}
src={url}
width={w}
height={h}
frameBorder="0"
allowFullScreen
sandbox={
sandboxConfig.useSandbox
? sandboxConfig.sandboxAttributes
? sandboxConfig.sandboxAttributes.join(' ')
: true
: ''
}
// eslint-disable-next-line react/jsx-props-no-spreading
{...iframeProps}
/>
</div>
);
......
......@@ -105,28 +105,41 @@ export function embedNode(child, links /*images*/) {
* @param h
* @returns {*}
*/
export function genIframeMd(idx, id, w, h) {
export function genIframeMd(idx, id, width, height) {
let parentDomain = $STM_Config.site_domain;
if (typeof window !== 'undefined') {
parentDomain = window.location.hostname;
}
const url = `https://player.twitch.tv/${id}&parent=${parentDomain}`;
let sandbox = sandboxConfig.useSandbox;
if (sandbox) {
if (
Object.prototype.hasOwnProperty.call(
sandboxConfig,
'sandboxAttributes'
)
) {
sandbox = sandboxConfig.sandboxAttributes.join(' ');
}
}
const iframeProps = {
src: url,
width,
height,
frameBorder: '0',
allowFullScreen: 'allowFullScreen',
};
if (sandbox) {
iframeProps.sandbox = sandbox;
}
return (
<div key={`twitch-${id}-${idx}`} className="videoWrapper">
<iframe
title="Twitch embedded player"
src={url}
width={w}
height={h}
frameBorder="0"
allowFullScreen
sandbox={
sandboxConfig.useSandbox
? sandboxConfig.sandboxAttributes
? sandboxConfig.sandboxAttributes.join(' ')
: true
: ''
}
// eslint-disable-next-line react/jsx-props-no-spreading
{...iframeProps}
/>
</div>
);
......
......@@ -113,26 +113,39 @@ export function embedNode(child, links /*images*/) {
* @param h
* @returns {*}
*/
export function genIframeMd(idx, id, w, h, startTime) {
export function genIframeMd(idx, id, width, height, startTime) {
const url = `https://player.vimeo.com/video/${id}#t=${startTime}s`;
let sandbox = sandboxConfig.useSandbox;
if (sandbox) {
if (
Object.prototype.hasOwnProperty.call(
sandboxConfig,
'sandboxAttributes'
)
) {
sandbox = sandboxConfig.sandboxAttributes.join(' ');
}
}
const iframeProps = {
src: url,
width,
height,
frameBorder: '0',
webkitallowfullscreen: 'webkitallowfullscreen',
mozallowfullscreen: 'mozallowfullscreen',
allowFullScreen: 'allowFullScreen',
};
if (sandbox) {
iframeProps.sandbox = sandbox;
}
return (
<div key={`vimeo-${id}-${idx}`} className="videoWrapper">
<iframe
title="Vimeo embedded player"
src={url}
width={w}
height={h}
frameBorder="0"
webkitallowfullscreen
mozallowfullscreen
allowFullScreen
sandbox={
sandboxConfig.useSandbox
? sandboxConfig.sandboxAttributes
? sandboxConfig.sandboxAttributes.join(' ')
: true
: ''
}
// eslint-disable-next-line react/jsx-props-no-spreading
{...iframeProps}
/>
</div>
);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment