Make Youtube previews stop when the channel is changed

Этот коммит содержится в:
hmhealey
2016-01-04 17:45:06 -05:00
родитель 537b7a3b71
Коммит 5a21005475
3 изменённых файлов: 21 добавлений и 2 удалений

Просмотреть файл

@@ -120,7 +120,12 @@ export default class PostBody extends React.Component {
} }
if (YoutubeVideo.isYoutubeLink(link)) { if (YoutubeVideo.isYoutubeLink(link)) {
return <YoutubeVideo link={link} />; return (
<YoutubeVideo
channelId={post.channel_id}
link={link}
/>
);
} }
for (let i = 0; i < Constants.IMAGE_TYPES.length; i++) { for (let i = 0; i < Constants.IMAGE_TYPES.length; i++) {

Просмотреть файл

@@ -1,6 +1,8 @@
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. // Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information. // See License.txt for license information.
import ChannelStore from '../stores/channel_store.jsx';
const ytRegex = /(?:http|https):\/\/(?:www\.)?(?:(?:youtube\.com\/(?:(?:v\/)|(\/u\/\w\/)|(?:(?:watch|embed\/watch)(?:\/|.*v=))|(?:embed\/)|(?:user\/[^\/]+\/u\/[0-9]\/)))|(?:youtu\.be\/))([^#\&\?]*)/; const ytRegex = /(?:http|https):\/\/(?:www\.)?(?:(?:youtube\.com\/(?:(?:v\/)|(\/u\/\w\/)|(?:(?:watch|embed\/watch)(?:\/|.*v=))|(?:embed\/)|(?:user\/[^\/]+\/u\/[0-9]\/)))|(?:youtu\.be\/))([^#\&\?]*)/;
export default class YoutubeVideo extends React.Component { export default class YoutubeVideo extends React.Component {
@@ -12,6 +14,7 @@ export default class YoutubeVideo extends React.Component {
this.play = this.play.bind(this); this.play = this.play.bind(this);
this.stop = this.stop.bind(this); this.stop = this.stop.bind(this);
this.stopOnChannelChange = this.stopOnChannelChange.bind(this);
this.state = { this.state = {
playing: false, playing: false,
@@ -95,12 +98,22 @@ export default class YoutubeVideo extends React.Component {
play() { play() {
this.setState({playing: true}); this.setState({playing: true});
if (ChannelStore.getCurrentId() === this.props.channelId) {
ChannelStore.addChangeListener(this.stopOnChannelChange);
}
} }
stop() { stop() {
this.setState({playing: false}); this.setState({playing: false});
} }
stopOnChannelChange() {
if (ChannelStore.getCurrentId() !== this.props.channelId) {
this.stop();
}
}
render() { render() {
let header = 'Youtube'; let header = 'Youtube';
if (this.state.title) { if (this.state.title) {
@@ -157,5 +170,6 @@ export default class YoutubeVideo extends React.Component {
} }
YoutubeVideo.propTypes = { YoutubeVideo.propTypes = {
channelId: React.PropTypes.string.isRequired,
link: React.PropTypes.string.isRequired link: React.PropTypes.string.isRequired
}; };

Просмотреть файл

@@ -18,7 +18,7 @@ class ChannelStoreClass extends EventEmitter {
constructor(props) { constructor(props) {
super(props); super(props);
this.setMaxListeners(11); this.setMaxListeners(15);
this.emitChange = this.emitChange.bind(this); this.emitChange = this.emitChange.bind(this);
this.addChangeListener = this.addChangeListener.bind(this); this.addChangeListener = this.addChangeListener.bind(this);