diff --git a/webroot/index.html b/webroot/index.html index 32c97a59e..4263caa4c 100644 --- a/webroot/index.html +++ b/webroot/index.html @@ -1,10 +1,3 @@ - -
@@ -36,10 +29,10 @@ - + diff --git a/webroot/js/app.js b/webroot/js/app.js index d0151b8f8..56ff53b86 100644 --- a/webroot/js/app.js +++ b/webroot/js/app.js @@ -9,27 +9,31 @@ import Chat from './components/chat/chat.js'; import Websocket from './utils/websocket.js'; import { - getLocalStorage, - setLocalStorage, + addNewlines, + classNames, clearLocalStorage, + debounce, generateAvatar, generateUsername, - addNewlines, + getLocalStorage, pluralize, + setLocalStorage, } from './utils/helpers.js'; import { - URL_OWNCAST, - URL_CONFIG, - URL_STATUS, - TIMER_STATUS_UPDATE, - TIMER_DISABLE_CHAT_AFTER_OFFLINE, - TIMER_STREAM_DURATION_COUNTER, - TEMP_IMAGE, - MESSAGE_OFFLINE, - MESSAGE_ONLINE, - KEY_USERNAME, + HEIGHT_SHORT_WIDE, KEY_AVATAR, KEY_CHAT_DISPLAYED, + KEY_USERNAME, + MESSAGE_OFFLINE, + MESSAGE_ONLINE, + TEMP_IMAGE, + TIMER_DISABLE_CHAT_AFTER_OFFLINE, + TIMER_STATUS_UPDATE, + TIMER_STREAM_DURATION_COUNTER, + URL_CONFIG, + URL_OWNCAST, + URL_STATUS, + WIDTH_SINGLE_COL, } from './utils/constants.js'; export default class App extends Component { @@ -41,7 +45,8 @@ export default class App extends Component { displayChat: getLocalStorage(KEY_CHAT_DISPLAYED), // chat panel state chatEnabled: false, // chat input box state username: getLocalStorage(KEY_USERNAME) || generateUsername(), - userAvatarImage: getLocalStorage(KEY_AVATAR) || generateAvatar(`${this.username}${Date.now()}`), + userAvatarImage: + getLocalStorage(KEY_AVATAR) || generateAvatar(`${this.username}${Date.now()}`), configData: {}, extraUserContent: '', @@ -49,11 +54,15 @@ export default class App extends Component { playerActive: false, // player object is active streamOnline: false, // stream is active/online - //status + // status streamStatusMessage: MESSAGE_OFFLINE, viewerCount: '', sessionMaxViewerCount: '', overallMaxViewerCount: '', + + // dom + windowWidth: window.innerWidth, + windowHeight: window.innerHeight, }; // timers @@ -66,6 +75,7 @@ export default class App extends Component { // misc dom events this.handleChatPanelToggle = this.handleChatPanelToggle.bind(this); this.handleUsernameChange = this.handleUsernameChange.bind(this); + this.handleWindowResize = debounce(this.handleWindowResize.bind(this), 400); this.handleOfflineMode = this.handleOfflineMode.bind(this); this.handleOnlineMode = this.handleOnlineMode.bind(this); @@ -81,12 +91,11 @@ export default class App extends Component { this.getConfig = this.getConfig.bind(this); this.getStreamStatus = this.getStreamStatus.bind(this); this.getExtraUserContent = this.getExtraUserContent.bind(this); - - } componentDidMount() { this.getConfig(); + window.addEventListener('resize', this.handleWindowResize); this.player = new OwncastPlayer(); this.player.setupPlayerCallbacks({ @@ -161,7 +170,6 @@ export default class App extends Component { }); } - setConfigData(data = {}) { const { title, extraUserInfoFileName, summary } = data; @@ -301,21 +309,30 @@ export default class App extends Component { console.log(`>>> App Error: ${error}`); } + handleWindowResize() { + this.setState({ + windowWidth: window.innerWidth, + windowHeight: window.innerHeight, + }); + } + render(props, state) { const { - username, - userAvatarImage, - websocket, + chatEnabled, configData, - extraUserContent, displayChat, - viewerCount, - sessionMaxViewerCount, + extraUserContent, overallMaxViewerCount, playerActive, + sessionMaxViewerCount, streamOnline, streamStatusMessage, - chatEnabled, + userAvatarImage, + username, + viewerCount, + websocket, + windowHeight, + windowWidth, } = state; const { @@ -347,14 +364,23 @@ export default class App extends Component { `); - - const chatClass = displayChat ? 'chat' : 'no-chat'; const mainClass = playerActive ? 'online' : ''; - const streamInfoClass = streamOnline ? 'online' : ''; + const streamInfoClass = streamOnline ? 'online' : ''; // need? + + const shortHeight = windowHeight <= HEIGHT_SHORT_WIDE; + const singleColMode = windowWidth <= WIDTH_SINGLE_COL && !shortHeight; + const extraAppClasses = classNames({ + 'chat': displayChat, + 'no-chat': !displayChat, + 'single-col': singleColMode, + 'bg-gray-800': singleColMode && displayChat, + 'short-wide': shortHeight, + }) + return ( html` -