2022-11-02 22:54:57 +08:00
|
|
|
import React from 'react';
|
|
|
|
import { withTracker } from 'meteor/react-meteor-data';
|
2024-01-19 21:44:27 +08:00
|
|
|
import { useMutation } from '@apollo/client';
|
2022-11-02 22:54:57 +08:00
|
|
|
import { SmartMediaShare } from './component';
|
2024-01-19 21:44:27 +08:00
|
|
|
import Panopto from '../../../external-video-player/custom-players/panopto';
|
2022-11-02 22:54:57 +08:00
|
|
|
import { layoutSelect } from '/imports/ui/components/layout/context';
|
|
|
|
import { isMobile } from '/imports/ui/components/layout/utils';
|
2024-01-19 21:44:27 +08:00
|
|
|
import { EXTERNAL_VIDEO_START } from '../../../external-video-player/mutations';
|
|
|
|
|
|
|
|
const YOUTUBE_SHORTS_REGEX = new RegExp(/^(?:https?:\/\/)?(?:www\.)?(youtube\.com\/shorts)\/.+$/);
|
|
|
|
|
|
|
|
const SmartMediaShareContainer = (props) => {
|
|
|
|
const [startExternalVideo] = useMutation(EXTERNAL_VIDEO_START);
|
|
|
|
|
|
|
|
const startWatching = (url) => {
|
|
|
|
let externalVideoUrl = url;
|
|
|
|
|
|
|
|
if (YOUTUBE_SHORTS_REGEX.test(url)) {
|
|
|
|
const shortsUrl = url.replace('shorts/', 'watch?v=');
|
|
|
|
externalVideoUrl = shortsUrl;
|
|
|
|
} else if (Panopto.canPlay(url)) {
|
|
|
|
externalVideoUrl = Panopto.getSocialUrl(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
startExternalVideo({ variables: { externalVideoUrl } });
|
|
|
|
};
|
2022-11-02 22:54:57 +08:00
|
|
|
|
2024-01-19 21:44:27 +08:00
|
|
|
return (
|
|
|
|
<SmartMediaShare {...{
|
|
|
|
startWatching,
|
|
|
|
...props,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
2022-11-02 22:54:57 +08:00
|
|
|
|
|
|
|
export default withTracker(() => {
|
|
|
|
const isRTL = layoutSelect((i) => i.isRTL);
|
|
|
|
return {
|
|
|
|
isRTL,
|
|
|
|
isMobile: isMobile(),
|
|
|
|
};
|
|
|
|
})(SmartMediaShareContainer);
|