2018-04-28 17:56:03 -04:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// Channel
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
import Module from 'utilities/module';
|
2018-06-27 14:13:59 -04:00
|
|
|
import { has } from 'utilities/object';
|
2018-04-28 17:56:03 -04:00
|
|
|
|
|
|
|
|
|
|
|
export default class Channel extends Module {
|
|
|
|
constructor(...args) {
|
|
|
|
super(...args);
|
|
|
|
|
|
|
|
this.should_enable = true;
|
|
|
|
|
|
|
|
this.inject('settings');
|
|
|
|
this.inject('site.fine');
|
|
|
|
|
2018-05-10 19:56:39 -04:00
|
|
|
this.left_raids = new Set;
|
|
|
|
|
2018-04-28 17:56:03 -04:00
|
|
|
this.settings.add('channel.hosting.enable', {
|
|
|
|
default: true,
|
|
|
|
ui: {
|
|
|
|
path: 'Channel > Behavior >> Hosting',
|
|
|
|
title: 'Enable Channel Hosting',
|
|
|
|
component: 'setting-check-box'
|
|
|
|
},
|
|
|
|
changed: val => this.updateChannelHosting(val)
|
|
|
|
});
|
|
|
|
|
2018-05-10 19:56:39 -04:00
|
|
|
|
|
|
|
this.settings.add('channel.raids.no-autojoin', {
|
|
|
|
default: false,
|
|
|
|
ui: {
|
|
|
|
path: 'Channel > Behavior >> Raids',
|
|
|
|
title: 'Do not automatically join raids.',
|
|
|
|
component: 'setting-check-box'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2018-04-28 17:56:03 -04:00
|
|
|
this.ChannelPage = this.fine.define(
|
|
|
|
'channel-page',
|
2018-06-27 14:13:59 -04:00
|
|
|
n => n.hostModeFromGraphQL,
|
2018-04-28 17:56:03 -04:00
|
|
|
['user']
|
|
|
|
);
|
2018-05-10 19:56:39 -04:00
|
|
|
|
|
|
|
this.RaidController = this.fine.define(
|
|
|
|
'raid-controller',
|
|
|
|
n => n.handleLeaveRaid && n.handleJoinRaid,
|
|
|
|
['user']
|
|
|
|
);
|
2018-04-28 17:56:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
onEnable() {
|
|
|
|
this.ChannelPage.on('mount', this.wrapChannelPage, this);
|
2018-05-10 19:56:39 -04:00
|
|
|
this.RaidController.on('mount', this.noAutoRaids, this);
|
|
|
|
this.RaidController.on('update', this.noAutoRaids, this);
|
|
|
|
|
|
|
|
this.RaidController.ready((cls, instances) => {
|
|
|
|
for(const inst of instances)
|
|
|
|
this.noAutoRaids(inst);
|
|
|
|
});
|
|
|
|
|
|
|
|
this.ChannelPage.on('update', inst => {
|
2018-05-18 02:10:00 -04:00
|
|
|
if ( this.settings.get('channel.hosting.enable') )
|
2018-05-10 19:56:39 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
// We can't do this immediately because the player state
|
|
|
|
// occasionally screws up if we do.
|
|
|
|
setTimeout(() => {
|
2018-06-27 14:13:59 -04:00
|
|
|
if ( inst.state.hostMode ) {
|
|
|
|
inst.ffzExpectedHost = inst.state.hostMode;
|
|
|
|
inst.ffzOldSetState({hostMode: null});
|
2018-05-18 02:10:00 -04:00
|
|
|
}
|
2018-05-10 19:56:39 -04:00
|
|
|
});
|
|
|
|
});
|
2018-04-28 17:56:03 -04:00
|
|
|
|
|
|
|
this.ChannelPage.ready((cls, instances) => {
|
|
|
|
for(const inst of instances)
|
|
|
|
this.wrapChannelPage(inst);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-10 19:56:39 -04:00
|
|
|
noAutoRaids(inst) {
|
|
|
|
if ( this.settings.get('channel.raids.no-autojoin') )
|
|
|
|
setTimeout(() => {
|
|
|
|
if ( inst.state.raid && inst.hasJoinedCurrentRaid ) {
|
|
|
|
const id = inst.state.raid.id;
|
|
|
|
if ( this.left_raids.has(id) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
this.log.info('Automatically leaving raid:', id);
|
|
|
|
this.left_raids.add(id);
|
|
|
|
inst.handleLeaveRaid();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-28 17:56:03 -04:00
|
|
|
wrapChannelPage(inst) {
|
|
|
|
if ( inst._ffz_hosting_wrapped )
|
|
|
|
return;
|
|
|
|
|
|
|
|
const t = this;
|
|
|
|
|
2018-06-27 14:13:59 -04:00
|
|
|
inst.ffzOldSetState = inst.setState;
|
|
|
|
inst.setState = function(state, ...args) {
|
|
|
|
try {
|
|
|
|
if ( has(state, 'hostMode') ) {
|
|
|
|
inst.ffzExpectedHost = state.hostMode;
|
|
|
|
if ( state.hostMode && ! t.settings.get('channel.hosting.enable') ) {
|
|
|
|
state.hostMode = null;
|
|
|
|
state.videoPlayerSource = inst.props.match.params.channelName;
|
|
|
|
}
|
|
|
|
}
|
2018-04-28 17:56:03 -04:00
|
|
|
|
2018-06-27 14:13:59 -04:00
|
|
|
} catch(err) {
|
|
|
|
t.log.capture(err, {extra: {props: inst.props, state}});
|
|
|
|
}
|
2018-04-28 17:56:03 -04:00
|
|
|
|
2018-06-27 14:13:59 -04:00
|
|
|
return inst.ffzOldSetState(state, ...args);
|
2018-04-28 17:56:03 -04:00
|
|
|
}
|
|
|
|
|
2018-06-27 14:13:59 -04:00
|
|
|
inst._ffz_hosting_wrapped = true;
|
2018-04-28 17:56:03 -04:00
|
|
|
|
2018-06-27 14:13:59 -04:00
|
|
|
const hosted = inst.ffzExpectedHost = inst.state.hostMode;
|
|
|
|
if ( hosted && ! this.settings.get('channel.hosting.enable') )
|
|
|
|
inst.ffzOldSetState({
|
|
|
|
hostMode: null,
|
|
|
|
videoPlayerSource: inst.props.match.params.channelName
|
|
|
|
});
|
2018-04-28 17:56:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
updateChannelHosting(val) {
|
|
|
|
if ( val === undefined )
|
|
|
|
val = this.settings.get('channel.hosting.enable');
|
|
|
|
|
2018-06-27 14:13:59 -04:00
|
|
|
for(const inst of this.ChannelPage.instances) {
|
|
|
|
const host = val ? inst.ffzExpectedHost : null,
|
|
|
|
target = host && host.hostedChannel && host.hostedChannel.login || inst.props.match.params.channelName;
|
|
|
|
|
|
|
|
inst.ffzOldSetState({
|
|
|
|
hostMode: host,
|
|
|
|
videoPlayerSource: target
|
|
|
|
});
|
|
|
|
}
|
2018-04-28 17:56:03 -04:00
|
|
|
}
|
|
|
|
}
|