1
0
Fork 0
mirror of https://github.com/FrankerFaceZ/FrankerFaceZ.git synced 2025-09-15 17:46:55 +00:00
This commit is contained in:
SirStendec 2016-09-30 13:09:03 -04:00
parent 8db999a8a8
commit 8280b93c97
28 changed files with 2140 additions and 603 deletions

View file

@ -17,9 +17,16 @@ FFZ.prototype.setup_channel = function() {
// Settings stuff!
document.body.classList.toggle("ffz-hide-view-count", !this.settings.channel_views);
document.body.classList.toggle('ffz-theater-stats', this.settings.theater_stats);
document.body.classList.toggle('ffz-channel-bar-bottom', this.settings.channel_bar_bottom);
utils.toggle_cls('ffz-minimal-channel-title')(this.settings.channel_title_top === 2);
utils.toggle_cls('ffz-channel-title-top')(this.settings.channel_title_top > 0);
utils.toggle_cls('ffz-minimal-channel-bar')(this.settings.channel_bar_collapse);
this.log("Hooking the Ember Channel Index view.");
if ( ! this.update_views('view:channel/index', this.modify_channel_index) )
this.log("Hooking the Ember Channel Index redesign.");
this.update_views('component:channel-redesign', this.modify_channel_redesign);
this.log("Hooking the Ember Channel Index component.");
if ( ! this.update_views('component:legacy-channel', this.modify_channel_index) )
return;
this.log("Hooking the Ember Channel model.");
@ -71,52 +78,52 @@ FFZ.prototype.setup_channel = function() {
}.property('content.id', 'login.userData', 'login.userData.login'),*/
ffzUpdateUptime: function() {
/*ffzUpdateUptime: function() {
if ( f._cindex )
f._cindex.ffzUpdateUptime();
}.observes("isLive", "content.id"),
}.observes("isLive", "channel.id"),*/
ffzUpdateInfo: function() {
if ( this._ffz_update_timer )
clearTimeout(this._ffz_update_timer);
if ( ! this.get('content.id') )
if ( ! this.get('channel.id') )
return;
this._ffz_update_timer = setTimeout(this.ffzCheckUpdate.bind(this), 55000 + (Math.random() * 10000));
}.observes("content.id"),
}.observes("channel.id"),
ffzCheckUpdate: function() {
var t = this,
id = t.get('content.id');
id = t.get('channel.id');
id && utils.api.get("streams/" + id, {}, {version:3})
.done(function(data) {
if ( ! data || ! data.stream ) {
// If the stream is offline, clear its created_at time and set it to zero viewers.
t.set('content.stream.created_at', null);
t.set('content.stream.viewers', 0);
t.set('channel.stream.createdAt', null);
t.set('channel.stream.viewers', 0);
return;
}
t.set('content.stream.created_at', data.stream.created_at || null);
t.set('content.stream.viewers', data.stream.viewers || 0);
t.set('channel.stream.createdAt', utils.parse_date(data.stream.created_at) || null);
t.set('channel.stream.viewers', data.stream.viewers || 0);
var game = data.stream.game || (data.stream.channel && data.stream.channel.game);
if ( game ) {
t.set('content.game', game);
t.set('channel.game', game);
}
if ( data.stream.channel ) {
if ( data.stream.channel.status )
t.set('content.status', data.stream.channel.status);
t.set('channel.status', data.stream.channel.status);
if ( data.stream.channel.views )
t.set('content.views', data.stream.channel.views);
t.set('channel.views', data.stream.channel.views);
if ( data.stream.channel.followers && t.get('content.followers.isLoaded') )
t.set('content.followers.total', data.stream.channel.followers);
if ( data.stream.channel.followers && t.get('channel.followers.isLoaded') )
t.set('channel.followers.total', data.stream.channel.followers);
}
})
@ -125,19 +132,19 @@ FFZ.prototype.setup_channel = function() {
});
},
ffzUpdateTitle: function() {
var name = this.get('content.name'),
display_name = this.get('content.display_name');
/*ffzUpdateTitle: function() {
var name = this.get('channel.name'),
display_name = this.get('channel.display_name');
if ( display_name )
FFZ.capitalization[name] = [display_name, Date.now()];
if ( f._cindex )
f._cindex.ffzFixTitle();
}.observes("content.status", "content.game", "content.id", "hostModeTarget.status", "hostModeTarget.id", "hostModeTarget.game"),
}.observes("channel.status", "channel.game", "channel.id", "channel.hostModeTarget.status", "channel.hostModeTarget.id", "channel.hostModeTarget.game"),*/
ffzHostTarget: function() {
var target = this.get('content.hostModeTarget'),
var target = this.get('channel.hostModeTarget'),
name = target && target.get('name'),
id = target && target.get('id'),
display_name = target && target.get('display_name');
@ -165,10 +172,9 @@ FFZ.prototype.setup_channel = function() {
if ( f.settings.srl_races )
f.rebuild_race_ui();
}.observes("content.hostModeTarget")
}.observes("channel.hostModeTarget")
});
Ember.propertyDidChange(Channel, 'isEditable');
Channel.ffzUpdateInfo();
}
@ -191,17 +197,345 @@ FFZ.prototype._modify_cmodel = function(model) {
}
FFZ.prototype.modify_channel_redesign = function(view) {
var f = this;
utils.ember_reopen_view(view, {
ffz_init: function() {
var channel_id = this.get("channel.id"),
el = this.get("element");
f._cindex = this;
f.ws_send("sub", "channel." + channel_id);
el.setAttribute('data-channel', channel_id);
el.classList.add('ffz-channel');
this.ffzFixTitle();
this.ffzUpdateUptime();
this.ffzUpdateChatters();
this.ffzUpdateHostButton();
this.ffzUpdatePlayerStats();
this.ffzUpdateCoverHeight();
if ( f.settings.auto_theater ) {
var player = f.players && f.players[channel_id] && f.players[channel_id].get('player');
if ( player )
player.setTheatre(true);
}
this.$().on("click", ".ffz-creative-tag-link", function(e) {
if ( e.button !== 0 || e.altKey || e.ctrlKey || e.shiftKey || e.metaKey )
return;
utils.ember_lookup("router:main").transitionTo('creative.hashtag.index', this.getAttribute('data-tag'));
e.preventDefault();
return false;
});
},
ffzUpdateCoverHeight: function() {
var old_height = this.get('channelCoverHeight'),
new_height = f.settings.channel_bar_bottom ? 0 : 380;
this.set('channelCoverHeight', new_height);
this.$("#channel").toggleClass('ffz-bar-fixed', this.get('isFixed'));
if ( old_height !== new_height )
this.scrollTo(this.$scrollContainer.scrollTop() + (new_height - old_height));
}.observes('isFixed'),
ffzFixTitle: function() {
if ( ! f.settings.stream_title )
return;
var channel_id = this.get("channel.id"),
status = this.get("channel.status"),
game = this.get("channel.game"),
tokens = f.tokenize_line(channel_id, channel_id, status, true);
if ( game === 'Creative' )
tokens = f.tokenize_ctags(tokens);
var el = this.$(".cn-metabar__title .card__title");
el && el.html(f.render_tokens(tokens));
}.observes('channel.id', 'channel.status', 'channel.game'),
ffzUpdateUptime: function() {
if ( this._ffz_update_uptime ) {
clearTimeout(this._ffz_update_uptime);
delete this._ffz_update_uptime;
}
var container = this.get('element');
if ( this.isDestroyed || ! container || ! f.settings.stream_uptime || ! this.get('isLiveAccordingToKraken') )
return container && this.$("#ffz-uptime-display").remove();
// Schedule an update.
this._ffz_update_uptime = setTimeout(this.ffzUpdateUptime.bind(this), 1000);
// Determine when the channel last went live.
var online = this.get("channel.stream.createdAt"),
now = Date.now() - (f._ws_server_offset || 0);
var uptime = online && Math.floor((now - online.getTime()) / 1000) || -1;
if ( uptime < 0 )
return this.$("#ffz-uptime-display").remove();
var el = container.querySelector('#ffz-uptime-display span');
if ( ! el ) {
var cont = container.querySelector('.cn-metabar__more');
if ( ! cont )
return;
var stat = utils.createElement('span'),
figure = utils.createElement('figure', 'icon cn-metabar__icon', constants.CLOCK + ' '),
balloon = utils.createElement('div', 'balloon balloon--tooltip balloon--down balloon--center'),
balloon_wrapper = utils.createElement('div', 'balloon-wrapper', figure),
stat_wrapper = utils.createElement('div', 'cn-metabar__ffz flex__item mg-l-1', balloon_wrapper);
balloon_wrapper.appendChild(stat);
balloon_wrapper.appendChild(balloon);
stat_wrapper.id = 'ffz-uptime-display';
balloon.innerHTML = 'Stream Uptime <nobr>(since ' + online.toLocaleString() + ')</nobr>';
var viewers = cont.querySelector(".cn-metabar__livecount");
if ( viewers )
cont.insertBefore(stat_wrapper, viewers.nextSibling);
else
cont.appendChild(stat_wrapper);
el = stat;
}
el.innerHTML = utils.time_to_string(uptime, false, false, false, f.settings.stream_uptime === 1 || f.settings.stream_uptime === 3);
}.observes('channel.stream.createdAt', 'isLiveAccordingToKraken'),
ffzUpdatePlayerStats: function() {
if ( this._ffz_update_stats ) {
clearTimeout(this._ffz_update_stats);
this._ffz_update_stats = null;
}
// Stop scheduling this so it can die.
if ( this.isDestroyed )
return;
// Schedule an update.
if ( f.settings.player_stats )
this._ffz_update_stats = setTimeout(this.ffzUpdatePlayerStats.bind(this), 1000);
var channel_id = this.get("channel.id"),
container = this.get("element"),
player_cont = f.players && f.players[channel_id],
player, stats;
try {
player = player_cont && player_cont.get('player');
stats = player && player.getVideoInfo();
} catch(err) {
f.error("Channel ffzUpdatePlayerStats: player.getVideoInfo", err);
}
if ( ! container || ! f.settings.player_stats || ! stats || ! stats.hls_latency_broadcaster )
return container && this.$("#ffz-player-stats").remove();
var el = container.querySelector("#ffz-player-stats");
if ( ! el ) {
var cont = container.querySelector('.cn-metabar__more');
if ( ! cont )
return;
var stat = utils.createElement('span'),
figure = utils.createElement('figure', 'icon cn-metabar__icon', constants.GRAPH + ' '),
balloon = utils.createElement('div', 'balloon balloon--tooltip balloon--up balloon--center'),
balloon_wrapper = utils.createElement('div', 'balloon-wrapper', figure);
el = utils.createElement('div', 'cn-metabar__ffz flex__item mg-l-1', balloon_wrapper);
balloon_wrapper.appendChild(stat);
balloon_wrapper.appendChild(balloon);
el.id = 'ffz-player-stats';
var viewers = cont.querySelector('#ffz-uptime-display') || cont.querySelector(".cn-metabar__livecount");
if ( viewers )
cont.insertBefore(el, viewers.nextSibling);
else
cont.appendChild(el);
}
var stat = el.querySelector('span'),
balloon = el.querySelector('.balloon');
var delay = Math.round(stats.hls_latency_broadcaster / 10) / 100,
dropped = utils.number_commas(stats.dropped_frames || 0),
bitrate;
if ( stats.playback_bytes_per_second )
bitrate = Math.round(stats.playback_bytes_per_second * 8 / 10.24) / 100;
else
bitrate = Math.round(stats.current_bitrate * 100) / 100;
var is_old = delay > 180;
if ( is_old ) {
delay = Math.floor(delay);
stat.textContent = utils.time_to_string(delay, true, delay > 172800) + ' old';
} else {
delay = delay.toString();
var ind = delay.indexOf('.');
delay += (ind === -1 ? '.00' : (ind >= delay.length - 2 ? '0' : '')) + 's';
stat.textContent = delay;
}
balloon.innerHTML = (is_old ? 'Video Information<br>' +
'Broadcast ' + utils.time_to_string(delay, true) + ' Ago<br><br>' : 'Stream Latency<br>') +
'Video: ' + stats.vid_width + 'x' + stats.vid_height + 'p ' + stats.current_fps + ' fps<br>' +
'Playback Rate: ' + bitrate + ' Kbps<br>' +
'Dropped Frames: ' + dropped;
},
ffzUpdateChatters: function() {
var channel_id = this.get("channel.id"),
room = f.rooms && f.rooms[channel_id],
container = this.get('element');
if ( ! container || ! room || ! f.settings.chatter_count )
return container && this.$("#ffz-chatter-display").remove();
var chatter_count = Object.keys(room.room.get('ffz_chatters') || {}).length,
el = container.querySelector('#ffz-chatter-display span');
if ( ! el ) {
var cont = container.querySelector('.cn-metabar__more');
if ( ! cont )
return;
var stat = utils.createElement('span'),
figure = utils.createElement('figure', 'icon cn-metabar__icon', constants.ROOMS + ' '),
balloon = utils.createElement('div', 'balloon balloon--tooltip balloon--down balloon--center', 'Currently in Chat'),
balloon_wrapper = utils.createElement('div', 'balloon-wrapper', figure),
stat_wrapper = utils.createElement('div', 'cn-metabar__ffz flex__item mg-l-1', balloon_wrapper);
balloon_wrapper.appendChild(stat);
balloon_wrapper.appendChild(balloon);
stat_wrapper.id = 'ffz-chatter-display';
var viewers = cont.querySelector('#ffz-player-stats') || cont.querySelector('#ffz-uptime-display') || cont.querySelector(".cn-metabar__livecount") || cont.querySelector(".cn-metabar__viewcount");
if ( viewers )
cont.insertBefore(stat_wrapper, viewers.nextSibling);
else
cont.appendChild(stat_wrapper);
el = stat;
}
el.innerHTML = utils.number_commas(chatter_count);
}.observes('channel.id'),
ffzUpdateHostButton: function() {
var t = this,
channel_id = this.get("channel.id"),
hosted_id = this.get("channel.hostModeTarget.id"),
user = f.get_user(),
room = user && f.rooms && f.rooms[user.login] && f.rooms[user.login].room,
now_hosting = room && room.ffz_host_target,
hosts_left = room && room.ffz_hosts_left,
el = this.get("element"),
update_button = function(channel, container, before) {
if ( ! container )
return;
var btn = container.querySelector('#ffz-ui-host-button');
if ( ! f.settings.stream_host_button || ! user || user.login === channel ) {
if ( btn )
btn.parentElement.removeChild(btn);
return;
}
if ( ! btn ) {
btn = utils.createElement('button', 'button button--hollow mg-l-1'),
btn.id = 'ffz-ui-host-button';
btn.addEventListener('click', t.ffzClickHost.bind(t, channel !== channel_id));
if ( before )
container.insertBefore(btn, before);
else
container.appendChild(btn);
jQuery(btn).tipsy({html: true, gravity: utils.tooltip_placement(constants.TOOLTIP_DISTANCE, 'n')});
}
btn.classList.remove('disabled');
btn.innerHTML = channel === now_hosting ? 'Unhost' : 'Host';
if ( now_hosting ) {
var name = FFZ.get_capitalization(now_hosting);
btn.title = 'You are now hosting ' + f.format_display_name(name, now_hosting, true)[0] + '.';
} else
btn.title = 'You are not hosting any channel.';
if ( typeof hosts_left === 'number' )
btn.title += ' You have ' + hosts_left + ' host command' + utils.pluralize(hosts_left) + ' remaining this half hour.';
};
if ( ! el )
return;
this.set("ffz_host_updating", false);
if ( channel_id ) {
var container = el.querySelector('.cn-metabar__more'),
share = container && container.querySelector('.js-share-box');
update_button(channel_id, container, share ? share.parentElement : null);
}
if ( hosted_id )
update_button(hosted_id, el.querySelector('.cn-hosting--bottom'));
}.observes('channel.id', 'channel.hostModeTarget.id'),
ffzClickHost: function(is_host, e) {
var btn = e.target,
target = this.get(is_host ? 'channel.hostModeTarget.id' : 'channel.id'),
user = f.get_user(),
room = user && f.rooms && f.rooms[user.login] && f.rooms[user.login].room,
now_hosting = room && room.ffz_host_target;
if ( ! room || this.get('ffz_host_updating') )
return;
btn.classList.add('disabled');
btn.title = 'Updating...';
this.set('ffz_host_updating', true);
if ( now_hosting === target )
room.send('/unhost', true);
else
room.send('/host ' + target, true);
}
})
}
FFZ.prototype.modify_channel_index = function(view) {
var f = this;
utils.ember_reopen_view(view, {
ffz_init: function() {
var id = this.get('controller.content.id') || this.get('controller.id'),
var channel_id = this.get('model.id'),
el = this.get('element');
f._cindex = this;
f.ws_send("sub", "channel." + id);
f.ws_send("sub", "channel." + channel_id);
el.setAttribute('data-channel', id);
el.setAttribute('data-channel', channel_id);
el.classList.add('ffz-channel');
this.ffzFixTitle();
@ -225,7 +559,7 @@ FFZ.prototype.modify_channel_index = function(view) {
f.rebuild_race_ui();
if ( f.settings.auto_theater ) {
var player = f.players && f.players[id] && f.players[id].get('player');
var player = f.players && f.players[channel_id] && f.players[channel_id].get('player');
if ( player )
player.setTheatre(true);
}
@ -241,12 +575,15 @@ FFZ.prototype.modify_channel_index = function(view) {
},
ffz_destroy: function() {
var id = this.get('controller.content.id') || this.get('controller.id');
if ( id )
f.ws_send("unsub", "channel." + id);
var channel_id = this.get('model.id');
if ( channel_id )
f.ws_send("unsub", "channel." + channel_id);
this.get('element').setAttribute('data-channel', '');
f._cindex = undefined;
if ( f._cindex === this )
f._cindex = null;
if ( this._ffz_update_uptime )
clearTimeout(this._ffz_update_uptime);
@ -259,7 +596,7 @@ FFZ.prototype.modify_channel_index = function(view) {
}
document.body.classList.remove('ffz-small-player');
utils.update_css(f._channel_style, id, null);
utils.update_css(f._channel_style, channel_id, null);
},
@ -279,23 +616,23 @@ FFZ.prototype.modify_channel_index = function(view) {
if ( f.has_bttv || ! f.settings.stream_title )
return;
var status = this.get("controller.content.status"),
channel = this.get("controller.content.id"),
game = this.get("controller.content.game"),
var channel_id = this.get('model.id'),
status = this.get('model.status'),
game = this.get('model.game'),
tokens = f.tokenize_line(channel, channel, status, true);
tokens = f.tokenize_line(channel_id, channel_id, status, true);
if ( game === 'Creative' )
tokens = f.tokenize_ctags(tokens);
this.$("#broadcast-meta .title").html(f.render_tokens(tokens));
status = this.get('controller.hostModeTarget.status');
channel = this.get('controller.hostModeTarget.id');
game = this.get('controller.hostModeTarget.game');
status = this.get('hostModeTarget.status');
channel_id = this.get('hostModeTarget.id');
game = this.get('hostModeTarget.game');
if ( channel ) {
tokens = f.tokenize_line(channel, channel, status, true);
if ( channel_id ) {
tokens = f.tokenize_line(channel_id, channel_id, status, true);
if ( game === 'Creative' )
tokens = f.tokenize_ctags(tokens);
@ -305,8 +642,8 @@ FFZ.prototype.modify_channel_index = function(view) {
ffzUpdateHostButton: function() {
var channel_id = this.get('controller.content.id') || this.get('controller.id'),
hosted_id = this.get('controller.hostModeTarget.id'),
var channel_id = this.get('model.id'),
hosted_id = this.get('hostModeTarget.id'),
user = f.get_user(),
room = user && f.rooms && f.rooms[user.login] && f.rooms[user.login].room,
@ -399,7 +736,7 @@ FFZ.prototype.modify_channel_index = function(view) {
ffzClickHost: function(is_host, e) {
var btn = e.target,
target = is_host ? this.get('controller.hostModeTarget.id') : (this.get('controller.content.id') || this.get('controller.id')),
target = is_host ? this.get('hostModeTarget.id') : this.get('model.id'),
user = f.get_user(),
room = user && f.rooms && f.rooms[user.login] && f.rooms[user.login].room,
now_hosting = room && room.ffz_host_target;
@ -420,7 +757,7 @@ FFZ.prototype.modify_channel_index = function(view) {
ffzUpdateChatters: function() {
// Get the counts.
var room_id = this.get('controller.content.id') || this.get('controller.id'),
var room_id = this.get('model.id'),
room = f.rooms && f.rooms[room_id];
if ( ! room || ! f.settings.chatter_count ) {
@ -505,8 +842,8 @@ FFZ.prototype.modify_channel_index = function(view) {
if ( f.settings.player_stats )
this._ffz_update_stats = setTimeout(this.ffzUpdatePlayerStats.bind(this), 1000);
var channel_id = this.get('controller.content.id') || this.get('controller.id'),
hosted_id = this.get('controller.hostModeTarget.id'),
var channel_id = this.get('model.id'),
hosted_id = this.get('hostModeTarget.id'),
el = this.get('element');
@ -667,7 +1004,8 @@ FFZ.prototype.modify_channel_index = function(view) {
delete this._ffz_update_uptime;
}
if ( ! f.settings.stream_uptime || ! this.get("controller.isLiveAccordingToKraken") ) {
var controller = utils.ember_lookup('controller:channel');
if ( ! f.settings.stream_uptime || ! (controller && controller.get('isLiveAccordingToKraken')) ) {
var el = this.get('element').querySelector('#ffz-uptime-display');
if ( el )
el.parentElement.removeChild(el);
@ -678,7 +1016,7 @@ FFZ.prototype.modify_channel_index = function(view) {
this._ffz_update_uptime = setTimeout(this.ffzUpdateUptime.bind(this), 1000);
// Determine when the channel last went live.
var online = this.get("controller.content.stream.created_at"),
var online = this.get("model.stream.created_at"),
now = Date.now() - (f._ws_server_offset || 0);
online = online && utils.parse_date(online);
@ -894,6 +1232,93 @@ FFZ.settings_info.stream_title = {
};
FFZ.settings_info.channel_bar_bottom = {
type: "boolean",
value: false,
no_bttv: true,
no_mobile: true,
category: "Appearance",
name: "Channel Bar on Bottom",
help: "Hide the profile banner and position the channel bar at the bottom of the screen.",
on_update: function(val) {
if ( this.has_bttv )
return;
utils.toggle_cls('ffz-channel-bar-bottom')(val);
if ( this._cindex )
this._cindex.ffzUpdateCoverHeight();
var Layout = utils.ember_lookup('service:layout');
if ( Layout )
Ember.propertyDidChange(Layout, 'windowHeight');
}
}
FFZ.settings_info.channel_bar_collapse = {
type: "boolean",
value: false,
no_bttv: true,
no_mobile: true,
category: "Appearance",
name: "Minimal Channel Bar",
help: "Slide the channel bar mostly out of view when it's not being used.",
on_update: function(val) {
if ( this.has_bttv )
return;
utils.toggle_cls('ffz-minimal-channel-bar')(val);
var Layout = utils.ember_lookup('service:layout');
if ( Layout )
Ember.propertyDidChange(Layout, 'windowHeight');
}
}
FFZ.settings_info.channel_title_top = {
type: "select",
options: {
0: "Disabled",
1: "On Top",
2: "On Top, Minimal"
},
value: 0,
process_value: function(val) {
if ( typeof val === "string" ) {
val = parseInt(val);
if ( isNaN(val) || ! isFinite(val) )
val = 0;
}
return val;
},
no_bttv: true,
no_mobile: true,
category: "Appearance",
name: "Channel Title on Top",
help: "Display the channel title and game above the player rather than below.",
on_update: function(val) {
if ( this.has_bttv )
return;
document.body.classList.toggle('ffz-minimal-channel-title', val === 2);
document.body.classList.toggle('ffz-channel-title-top', val > 0);
var Layout = utils.ember_lookup('service:layout');
if ( Layout )
Ember.propertyDidChange(Layout, 'windowHeight');
}
}
FFZ.settings_info.theater_stats = {
type: "boolean",
value: true,