2018-04-28 17:56:03 -04:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// Channel
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
import Module from 'utilities/module';
|
2018-08-01 15:11:03 -04:00
|
|
|
import { get, has } from 'utilities/object';
|
2018-04-28 17:56:03 -04:00
|
|
|
|
2018-07-18 17:06:14 -04:00
|
|
|
import Twilight from 'site';
|
|
|
|
|
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-07-09 21:35:31 -04:00
|
|
|
this.joined_raids = new Set;
|
2018-05-10 19:56:39 -04:00
|
|
|
|
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'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-10-28 01:06:02 -04:00
|
|
|
/*this.settings.add('channel.squads.no-autojoin', {
|
2019-06-18 19:48:51 -04:00
|
|
|
default: false,
|
|
|
|
ui: {
|
|
|
|
path: 'Channel > Behavior >> Squads',
|
|
|
|
title: 'Do not automatically redirect to Squad Streams.',
|
|
|
|
component: 'setting-check-box'
|
|
|
|
}
|
2019-10-28 01:06:02 -04:00
|
|
|
});*/
|
2019-06-18 19:48:51 -04:00
|
|
|
|
2018-05-10 19:56:39 -04:00
|
|
|
|
2018-04-28 17:56:03 -04:00
|
|
|
this.ChannelPage = this.fine.define(
|
|
|
|
'channel-page',
|
2019-10-05 20:55:32 -04:00
|
|
|
n => (n.updateHost && n.updateChannel && n.state && has(n.state, 'hostedChannel')) || (n.getHostedChannelLogin && n.handleHostingChange) || (n.onChatHostingChange && n.state && has(n.state, 'hostMode')),
|
2018-08-03 15:25:50 -04:00
|
|
|
['user', 'video', 'user-video', 'user-clip', 'user-videos', 'user-clips', 'user-collections', 'user-events', 'user-followers', 'user-following']
|
2018-04-28 17:56:03 -04:00
|
|
|
);
|
2018-05-10 19:56:39 -04:00
|
|
|
|
|
|
|
this.RaidController = this.fine.define(
|
|
|
|
'raid-controller',
|
|
|
|
n => n.handleLeaveRaid && n.handleJoinRaid,
|
2018-07-18 17:06:14 -04:00
|
|
|
Twilight.CHAT_ROUTES
|
2018-05-10 19:56:39 -04:00
|
|
|
);
|
2019-06-18 19:48:51 -04:00
|
|
|
|
2019-10-28 01:06:02 -04:00
|
|
|
/*this.SquadController = this.fine.define(
|
2019-06-18 19:48:51 -04:00
|
|
|
'squad-controller',
|
|
|
|
n => n.onSquadPage && n.isValidSquad && n.handleLeaveSquad,
|
|
|
|
Twilight.CHAT_ROUTES
|
2019-10-28 01:06:02 -04:00
|
|
|
);*/
|
2018-04-28 17:56:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
onEnable() {
|
|
|
|
this.ChannelPage.on('mount', this.wrapChannelPage, this);
|
2018-07-09 21:35:31 -04:00
|
|
|
this.RaidController.on('mount', this.wrapRaidController, this);
|
2018-05-10 19:56:39 -04:00
|
|
|
this.RaidController.on('update', this.noAutoRaids, this);
|
|
|
|
|
2019-10-28 01:06:02 -04:00
|
|
|
//this.SquadController.on('mount', this.noAutoSquads, this);
|
|
|
|
//this.SquadController.on('update', this.noAutoSquads, this);
|
2019-06-18 19:48:51 -04:00
|
|
|
|
2018-05-10 19:56:39 -04:00
|
|
|
this.RaidController.ready((cls, instances) => {
|
|
|
|
for(const inst of instances)
|
2018-07-09 21:35:31 -04:00
|
|
|
this.wrapRaidController(inst);
|
2018-05-10 19:56:39 -04:00
|
|
|
});
|
|
|
|
|
2019-06-14 21:24:48 -04:00
|
|
|
this.ChannelPage.on('mount', inst => {
|
2019-10-22 18:32:56 -04:00
|
|
|
const category = get('state.video.game', inst) || get('state.clip.game', inst) || get('state.channel.broadcastSettings.game', inst);
|
|
|
|
|
2019-06-14 21:24:48 -04:00
|
|
|
this.settings.updateContext({
|
|
|
|
channel: get('state.channel.login', inst),
|
2019-10-22 18:32:56 -04:00
|
|
|
channelID: get('state.channel.id', inst),
|
|
|
|
channelColor: get('state.primaryColorHex', inst),
|
|
|
|
category: category?.name,
|
|
|
|
categoryID: category?.id
|
2019-06-14 21:24:48 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
this.ChannelPage.on('unmount', () => {
|
|
|
|
this.settings.updateContext({
|
|
|
|
channel: null,
|
2019-10-22 18:32:56 -04:00
|
|
|
channelID: null,
|
|
|
|
channelColor: null,
|
|
|
|
category: null,
|
|
|
|
categoryID: null
|
2019-06-14 21:24:48 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-05-10 19:56:39 -04:00
|
|
|
this.ChannelPage.on('update', inst => {
|
2019-10-22 18:32:56 -04:00
|
|
|
const category = get('state.video.game', inst) || get('state.clip.game', inst) || get('state.channel.broadcastSettings.game', inst);
|
|
|
|
|
2019-06-14 21:24:48 -04:00
|
|
|
this.settings.updateContext({
|
|
|
|
channel: get('state.channel.login', inst),
|
2019-10-22 18:32:56 -04:00
|
|
|
channelID: get('state.channel.id', inst),
|
|
|
|
channelColor: get('state.primaryColorHex', inst),
|
|
|
|
category: category?.name,
|
|
|
|
categoryID: category?.id
|
2019-06-14 21:24:48 -04:00
|
|
|
});
|
|
|
|
|
2018-11-13 14:50:17 -05:00
|
|
|
if ( this.settings.get('channel.hosting.enable') || has(inst.state, 'hostMode') || has(inst.state, 'hostedChannel') )
|
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-07-18 18:58:05 -04:00
|
|
|
const current_channel = inst.props.data && inst.props.data.variables && inst.props.data.variables.currentChannelLogin;
|
|
|
|
if ( current_channel && current_channel !== inst.state.videoPlayerSource ) {
|
|
|
|
inst.ffzExpectedHost = inst.state.videoPlayerSource;
|
|
|
|
inst.ffzOldHostHandler(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-07-09 21:35:31 -04:00
|
|
|
wrapRaidController(inst) {
|
|
|
|
if ( inst._ffz_wrapped )
|
|
|
|
return this.noAutoRaids(inst);
|
|
|
|
|
|
|
|
inst._ffz_wrapped = true;
|
|
|
|
|
|
|
|
const t = this,
|
|
|
|
old_handle_join = inst.handleJoinRaid;
|
|
|
|
|
|
|
|
inst.handleJoinRaid = function(event, ...args) {
|
2018-09-26 17:35:22 -04:00
|
|
|
const raid_id = inst.props && inst.props.raid && inst.props.raid.id;
|
2018-07-09 21:35:31 -04:00
|
|
|
if ( event && event.type && raid_id )
|
|
|
|
t.joined_raids.add(raid_id);
|
|
|
|
|
|
|
|
return old_handle_join.call(this, event, ...args);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.noAutoRaids(inst);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-18 19:48:51 -04:00
|
|
|
noAutoSquads(inst) {
|
|
|
|
if ( this.settings.get('channel.squads.no-autojoin') )
|
|
|
|
setTimeout(() => {
|
|
|
|
if ( inst.isValidSquad() && inst.state && inst.state.hasJoined ) {
|
|
|
|
this.log.info('Automatically opting out of Squad Stream.');
|
|
|
|
inst.handleLeaveSquad();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-10 19:56:39 -04:00
|
|
|
noAutoRaids(inst) {
|
|
|
|
if ( this.settings.get('channel.raids.no-autojoin') )
|
|
|
|
setTimeout(() => {
|
2018-09-26 17:35:22 -04:00
|
|
|
if ( inst.props && inst.props.raid && ! inst.isRaidCreator && inst.hasJoinedCurrentRaid ) {
|
|
|
|
const id = inst.props.raid.id;
|
2018-07-09 21:35:31 -04:00
|
|
|
if ( this.joined_raids.has(id) )
|
2018-05-10 19:56:39 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
this.log.info('Automatically leaving raid:', id);
|
|
|
|
inst.handleLeaveRaid();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-28 17:56:03 -04:00
|
|
|
wrapChannelPage(inst) {
|
|
|
|
if ( inst._ffz_hosting_wrapped )
|
|
|
|
return;
|
|
|
|
|
2018-08-01 15:11:03 -04:00
|
|
|
const t = this,
|
2018-11-13 14:50:17 -05:00
|
|
|
new_new_style = inst.updateChannel && has(inst.state, 'hostedChannel'),
|
|
|
|
new_style = ! new_new_style && ! inst.handleHostingChange || has(inst.state, 'hostMode');
|
2018-08-01 15:11:03 -04:00
|
|
|
|
|
|
|
inst.ffzGetChannel = () => {
|
|
|
|
const params = inst.props.match.params
|
|
|
|
if ( ! params )
|
|
|
|
return get('props.data.variables.currentChannelLogin', inst)
|
|
|
|
|
|
|
|
return params.channelName || params.channelLogin
|
|
|
|
}
|
2018-04-28 17:56:03 -04:00
|
|
|
|
2018-06-27 14:13:59 -04:00
|
|
|
inst.ffzOldSetState = inst.setState;
|
|
|
|
inst.setState = function(state, ...args) {
|
|
|
|
try {
|
2018-11-13 14:50:17 -05:00
|
|
|
if ( new_new_style ) {
|
|
|
|
const expected = inst.ffzGetChannel();
|
|
|
|
if ( has(state, 'hostedChannel') ) {
|
|
|
|
inst.ffzExpectedHost = state.hostedChannel;
|
|
|
|
if ( state.hostedChannel && ! t.settings.get('channel.hosting.enable') ) {
|
|
|
|
state.hostedChannel = null;
|
|
|
|
state.videoPlayerSource = expected;
|
|
|
|
}
|
|
|
|
|
|
|
|
t.settings.updateContext({hosting: !!state.hostedChannel});
|
|
|
|
|
|
|
|
} else if ( has(state, 'videoPlayerSource') ) {
|
|
|
|
if ( state.videoPlayerSource !== expected && ! t.settings.get('channel.hosting.enable') ) {
|
|
|
|
state.videoPlayerSource = expected;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if ( new_style ) {
|
2018-08-02 14:29:18 -04:00
|
|
|
const expected = inst.ffzGetChannel();
|
2018-08-01 15:11:03 -04:00
|
|
|
if ( has(state, 'hostMode') ) {
|
|
|
|
inst.ffzExpectedHost = state.hostMode;
|
|
|
|
if ( state.hostMode && ! t.settings.get('channel.hosting.enable') ) {
|
|
|
|
state.hostMode = null;
|
2018-08-02 14:29:18 -04:00
|
|
|
state.videoPlayerSource = expected;
|
2018-08-01 15:11:03 -04:00
|
|
|
}
|
2018-08-02 14:29:18 -04:00
|
|
|
|
2018-08-04 15:01:00 -04:00
|
|
|
t.settings.updateContext({hosting: !!state.hostMode});
|
|
|
|
|
2018-08-02 14:29:18 -04:00
|
|
|
} else if ( has(state, 'videoPlayerSource') ) {
|
|
|
|
if ( state.videoPlayerSource !== expected && ! t.settings.get('channel.hosting.enable') )
|
|
|
|
state.videoPlayerSource = expected;
|
2018-08-01 15:11:03 -04:00
|
|
|
}
|
2018-07-18 18:58:05 -04:00
|
|
|
|
2018-08-01 15:11:03 -04:00
|
|
|
} else {
|
|
|
|
if ( ! t.settings.get('channel.hosting.enable') ) {
|
|
|
|
if ( has(state, 'isHosting') )
|
|
|
|
state.isHosting = false;
|
2018-07-18 18:58:05 -04:00
|
|
|
|
2018-08-01 15:11:03 -04:00
|
|
|
if ( has(state, 'videoPlayerSource') )
|
|
|
|
state.videoPlayerSource = inst.ffzGetChannel();
|
2018-06-27 14:13:59 -04:00
|
|
|
}
|
2018-08-04 15:01:00 -04:00
|
|
|
|
|
|
|
if ( has(state, 'isHosting') )
|
|
|
|
t.settings.updateContext({hosting: state.isHosting});
|
2018-08-01 15:11:03 -04:00
|
|
|
}
|
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-11-13 14:50:17 -05:00
|
|
|
if ( new_new_style ) {
|
|
|
|
const hosted = inst.ffzExpectedHost = inst.state.hostedChannel;
|
|
|
|
this.settings.updateContext({hosting: this.settings.get('channel.hosting.enable') && !!hosted});
|
|
|
|
|
|
|
|
if ( hosted && ! this.settings.get('channel.hosting.enable') ) {
|
|
|
|
inst.ffzOldSetState({
|
|
|
|
hostedChannel: null,
|
|
|
|
videoPlayerSource: inst.ffzGetChannel()
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if ( new_style ) {
|
2018-08-01 15:11:03 -04:00
|
|
|
const hosted = inst.ffzExpectedHost = inst.state.hostMode;
|
2018-08-04 15:01:00 -04:00
|
|
|
this.settings.updateContext({hosting: this.settings.get('channel.hosting.enable') && !!inst.state.hostMode});
|
|
|
|
|
2018-08-02 14:29:18 -04:00
|
|
|
if ( hosted && ! this.settings.get('channel.hosting.enable') ) {
|
2018-08-01 15:11:03 -04:00
|
|
|
inst.ffzOldSetState({
|
|
|
|
hostMode: null,
|
2018-08-02 14:29:18 -04:00
|
|
|
videoPlayerSource: inst.ffzGetChannel()
|
2018-08-01 15:11:03 -04:00
|
|
|
});
|
2018-08-02 14:29:18 -04:00
|
|
|
}
|
2018-08-01 15:11:03 -04:00
|
|
|
|
|
|
|
} else {
|
2018-08-04 15:01:00 -04:00
|
|
|
inst.ffzOldGetHostedLogin = () => get('props.data.user.hosting.login', inst) || null;
|
2018-08-01 15:11:03 -04:00
|
|
|
inst.getHostedChannelLogin = function() {
|
|
|
|
return t.settings.get('channel.hosting.enable') ?
|
|
|
|
inst.ffzOldGetHostedLogin() : null;
|
|
|
|
}
|
2018-07-18 18:58:05 -04:00
|
|
|
|
2018-08-01 15:11:03 -04:00
|
|
|
inst.ffzOldHostHandler = inst.handleHostingChange;
|
|
|
|
inst.handleHostingChange = function(channel) {
|
|
|
|
inst.ffzExpectedHost = channel;
|
|
|
|
if ( t.settings.get('channel.hosting.enable') )
|
|
|
|
return inst.ffzOldHostHandler(channel);
|
|
|
|
}
|
2018-07-18 18:58:05 -04:00
|
|
|
|
2018-08-01 15:11:03 -04:00
|
|
|
// Store the current state and disable the current host if needed.
|
|
|
|
inst.ffzExpectedHost = inst.state.isHosting ? inst.state.videoPlayerSource : null;
|
2018-08-04 15:01:00 -04:00
|
|
|
this.settings.updateContext({hosting: this.settings.get('channel.hosting.enable') && inst.state.isHosting});
|
|
|
|
if ( ! this.settings.get('channel.hosting.enable') ) {
|
2018-08-01 15:11:03 -04:00
|
|
|
inst.ffzOldHostHandler(null);
|
2018-08-04 15:01:00 -04:00
|
|
|
}
|
2018-08-01 15:11:03 -04:00
|
|
|
}
|
2018-07-18 18:58:05 -04:00
|
|
|
|
|
|
|
// Finally, we force an update so that any child components
|
|
|
|
// receive our updated handler.
|
|
|
|
inst.forceUpdate();
|
2019-10-13 00:41:09 -04:00
|
|
|
this.emit('site:dom-update', 'channel-page', inst);
|
2018-04-28 17:56:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
updateChannelHosting(val) {
|
|
|
|
if ( val === undefined )
|
|
|
|
val = this.settings.get('channel.hosting.enable');
|
|
|
|
|
2018-08-04 15:01:00 -04:00
|
|
|
let hosting = val;
|
|
|
|
|
2018-06-27 14:13:59 -04:00
|
|
|
for(const inst of this.ChannelPage.instances) {
|
2018-08-04 15:01:00 -04:00
|
|
|
if ( ! inst.ffzExpectedHost )
|
|
|
|
hosting = false;
|
|
|
|
|
2018-11-13 14:50:17 -05:00
|
|
|
if ( has(inst.state, 'hostedChannel') ) {
|
|
|
|
const host = val ? inst.ffzExpectedHost : null,
|
|
|
|
target = host && host.login || inst.ffzGetChannel();
|
|
|
|
|
|
|
|
inst.ffzOldSetState({
|
|
|
|
hostedChannel: host,
|
|
|
|
videoPlayerSource: target
|
|
|
|
});
|
|
|
|
|
|
|
|
} else if ( has(inst.state, 'hostMode') ) {
|
2018-08-01 15:11:03 -04:00
|
|
|
const host = val ? inst.ffzExpectedHost : null,
|
|
|
|
target = host && host.hostedChannel && host.hostedChannel.login || inst.ffzGetChannel();
|
2018-07-18 18:58:05 -04:00
|
|
|
|
2018-08-01 15:11:03 -04:00
|
|
|
inst.ffzOldSetState({
|
|
|
|
hostMode: host,
|
|
|
|
videoPlayerSource: target
|
|
|
|
});
|
2018-06-27 14:13:59 -04:00
|
|
|
|
2018-08-01 15:11:03 -04:00
|
|
|
} else
|
|
|
|
inst.ffzOldHostHandler(val ? inst.ffzExpectedHost : null);
|
2018-06-27 14:13:59 -04:00
|
|
|
}
|
2018-08-04 15:01:00 -04:00
|
|
|
|
|
|
|
this.settings.updateContext({hosting});
|
2018-04-28 17:56:03 -04:00
|
|
|
}
|
|
|
|
}
|