2020-10-05 03:43:31 +02:00
|
|
|
import { h, Component } from '/js/web_modules/preact.js';
|
|
|
|
import htm from '/js/web_modules/htm.js';
|
2020-08-24 06:23:16 +02:00
|
|
|
const html = htm.bind(h);
|
|
|
|
|
2022-03-07 02:11:51 +01:00
|
|
|
import { URL_WEBSOCKET } from './utils/constants.js';
|
|
|
|
|
2020-08-24 06:23:16 +02:00
|
|
|
import { OwncastPlayer } from './components/player.js';
|
2020-12-23 02:43:35 +01:00
|
|
|
import SocialIconsList from './components/platform-logos-list.js';
|
2020-08-24 06:23:16 +02:00
|
|
|
import UsernameForm from './components/chat/username.js';
|
2020-10-22 23:14:44 +02:00
|
|
|
import VideoPoster from './components/video-poster.js';
|
2022-01-12 22:53:10 +01:00
|
|
|
import Followers from './components/federation/followers.js';
|
|
|
|
|
2020-08-24 06:23:16 +02:00
|
|
|
import Chat from './components/chat/chat.js';
|
2021-07-20 04:23:06 +02:00
|
|
|
import Websocket, {
|
|
|
|
CALLBACKS,
|
|
|
|
SOCKET_MESSAGE_TYPES,
|
|
|
|
} from './utils/websocket.js';
|
2021-07-20 04:22:29 +02:00
|
|
|
import { registerChat } from './chat/register.js';
|
|
|
|
|
2021-03-15 23:32:52 +01:00
|
|
|
import ExternalActionModal, {
|
|
|
|
ExternalActionButton,
|
|
|
|
} from './components/external-action-modal.js';
|
2020-08-24 06:23:16 +02:00
|
|
|
|
2022-01-12 22:53:10 +01:00
|
|
|
import FediverseFollowModal, {
|
|
|
|
FediverseFollowButton,
|
|
|
|
} from './components/fediverse-follow-modal.js';
|
|
|
|
|
2022-03-18 21:33:23 +01:00
|
|
|
import { NotifyButton, NotifyModal } from './components/notification.js';
|
|
|
|
import { isPushNotificationSupported } from './notification/registerWeb.js';
|
2020-08-24 06:23:16 +02:00
|
|
|
import {
|
2020-08-24 12:30:42 +02:00
|
|
|
addNewlines,
|
2022-01-12 22:53:10 +01:00
|
|
|
checkUrlPathForDisplay,
|
2020-08-24 12:30:42 +02:00
|
|
|
classNames,
|
|
|
|
debounce,
|
|
|
|
getLocalStorage,
|
2021-06-20 19:49:16 +02:00
|
|
|
getOrientation,
|
|
|
|
hasTouchScreen,
|
|
|
|
makeLastOnlineString,
|
|
|
|
parseSecondsToDurationString,
|
2020-08-24 06:23:16 +02:00
|
|
|
pluralize,
|
2022-01-12 22:53:10 +01:00
|
|
|
ROUTE_RECORDINGS,
|
2020-08-24 12:30:42 +02:00
|
|
|
setLocalStorage,
|
2020-08-24 06:23:16 +02:00
|
|
|
} from './utils/helpers.js';
|
|
|
|
import {
|
2021-07-20 04:22:29 +02:00
|
|
|
CHAT_MAX_MESSAGE_LENGTH,
|
|
|
|
EST_SOCKET_PAYLOAD_BUFFER,
|
2020-08-24 12:30:42 +02:00
|
|
|
HEIGHT_SHORT_WIDE,
|
2021-07-20 04:22:29 +02:00
|
|
|
KEY_ACCESS_TOKEN,
|
2020-08-24 06:23:16 +02:00
|
|
|
KEY_CHAT_DISPLAYED,
|
2020-08-24 12:30:42 +02:00
|
|
|
KEY_USERNAME,
|
|
|
|
MESSAGE_OFFLINE,
|
|
|
|
MESSAGE_ONLINE,
|
2020-11-18 00:12:54 +01:00
|
|
|
ORIENTATION_PORTRAIT,
|
|
|
|
OWNCAST_LOGO_LOCAL,
|
2020-08-24 12:30:42 +02:00
|
|
|
TEMP_IMAGE,
|
|
|
|
TIMER_DISABLE_CHAT_AFTER_OFFLINE,
|
|
|
|
TIMER_STATUS_UPDATE,
|
|
|
|
TIMER_STREAM_DURATION_COUNTER,
|
|
|
|
URL_CONFIG,
|
|
|
|
URL_OWNCAST,
|
|
|
|
URL_STATUS,
|
2021-06-21 02:26:23 +02:00
|
|
|
URL_VIEWER_PING,
|
2020-08-24 12:30:42 +02:00
|
|
|
WIDTH_SINGLE_COL,
|
2022-03-18 21:33:23 +01:00
|
|
|
USER_VISIT_COUNT_KEY,
|
2020-08-24 06:23:16 +02:00
|
|
|
} from './utils/constants.js';
|
2021-11-03 03:27:41 +01:00
|
|
|
import { checkIsModerator } from './utils/chat.js';
|
2022-03-18 21:33:23 +01:00
|
|
|
|
2022-01-12 22:53:10 +01:00
|
|
|
import TabBar from './components/tab-bar.js';
|
2020-08-24 06:23:16 +02:00
|
|
|
|
|
|
|
export default class App extends Component {
|
|
|
|
constructor(props, context) {
|
|
|
|
super(props, context);
|
|
|
|
|
2020-09-21 04:27:26 +02:00
|
|
|
const chatStorage = getLocalStorage(KEY_CHAT_DISPLAYED);
|
2020-09-23 02:09:55 +02:00
|
|
|
this.hasTouchScreen = hasTouchScreen();
|
2020-12-23 02:43:35 +01:00
|
|
|
this.windowBlurred = false;
|
2020-09-21 04:27:26 +02:00
|
|
|
|
2020-08-24 06:23:16 +02:00
|
|
|
this.state = {
|
2021-07-20 04:22:29 +02:00
|
|
|
websocket: null,
|
|
|
|
canChat: false, // all of chat functionality (panel + username)
|
2021-07-20 04:23:06 +02:00
|
|
|
displayChatPanel: chatStorage === null ? true : chatStorage === 'true', // just the chat panel
|
2020-09-13 03:46:08 +02:00
|
|
|
chatInputEnabled: false, // chat input box state
|
2021-07-20 04:22:29 +02:00
|
|
|
accessToken: null,
|
|
|
|
username: getLocalStorage(KEY_USERNAME),
|
2021-11-03 03:27:41 +01:00
|
|
|
isModerator: false,
|
|
|
|
|
2021-07-20 04:22:29 +02:00
|
|
|
isRegistering: false,
|
2020-12-12 20:08:23 +01:00
|
|
|
touchKeyboardActive: false,
|
2020-08-24 06:23:16 +02:00
|
|
|
|
2021-05-29 22:08:10 +02:00
|
|
|
configData: {
|
|
|
|
loading: true,
|
|
|
|
},
|
2020-10-14 18:38:48 +02:00
|
|
|
extraPageContent: '',
|
2020-08-24 06:23:16 +02:00
|
|
|
|
|
|
|
playerActive: false, // player object is active
|
2021-08-16 03:22:13 +02:00
|
|
|
streamOnline: null, // stream is active/online
|
2020-10-22 23:14:44 +02:00
|
|
|
isPlaying: false, // player is actively playing video
|
2020-08-24 06:23:16 +02:00
|
|
|
|
2020-08-24 12:30:42 +02:00
|
|
|
// status
|
2020-08-24 06:23:16 +02:00
|
|
|
streamStatusMessage: MESSAGE_OFFLINE,
|
|
|
|
viewerCount: '',
|
2021-06-20 19:49:16 +02:00
|
|
|
lastDisconnectTime: null,
|
2020-08-24 12:30:42 +02:00
|
|
|
|
|
|
|
// dom
|
|
|
|
windowWidth: window.innerWidth,
|
|
|
|
windowHeight: window.innerHeight,
|
2020-09-23 02:09:55 +02:00
|
|
|
orientation: getOrientation(this.hasTouchScreen),
|
2021-03-15 23:32:52 +01:00
|
|
|
|
2022-01-12 22:53:10 +01:00
|
|
|
// modals
|
|
|
|
externalActionModalData: null,
|
|
|
|
fediverseModalData: null,
|
|
|
|
|
|
|
|
// routing & tabbing
|
|
|
|
section: '',
|
|
|
|
sectionId: '',
|
2020-08-24 06:23:16 +02:00
|
|
|
};
|
2020-07-16 21:17:05 +02:00
|
|
|
|
|
|
|
// timers
|
|
|
|
this.playerRestartTimer = null;
|
|
|
|
this.offlineTimer = null;
|
|
|
|
this.statusTimer = null;
|
2021-07-20 04:22:29 +02:00
|
|
|
this.disableChatInputTimer = null;
|
2020-07-20 01:06:55 +02:00
|
|
|
this.streamDurationTimer = null;
|
2020-07-16 21:17:05 +02:00
|
|
|
|
2020-08-24 06:23:16 +02:00
|
|
|
// misc dom events
|
|
|
|
this.handleChatPanelToggle = this.handleChatPanelToggle.bind(this);
|
|
|
|
this.handleUsernameChange = this.handleUsernameChange.bind(this);
|
2020-12-12 20:08:23 +01:00
|
|
|
this.handleFormFocus = this.handleFormFocus.bind(this);
|
|
|
|
this.handleFormBlur = this.handleFormBlur.bind(this);
|
2020-12-23 02:43:35 +01:00
|
|
|
this.handleWindowBlur = this.handleWindowBlur.bind(this);
|
|
|
|
this.handleWindowFocus = this.handleWindowFocus.bind(this);
|
2020-09-22 05:11:09 +02:00
|
|
|
this.handleWindowResize = debounce(this.handleWindowResize.bind(this), 250);
|
2020-07-16 21:17:05 +02:00
|
|
|
|
|
|
|
this.handleOfflineMode = this.handleOfflineMode.bind(this);
|
|
|
|
this.handleOnlineMode = this.handleOnlineMode.bind(this);
|
2020-08-24 06:23:16 +02:00
|
|
|
this.disableChatInput = this.disableChatInput.bind(this);
|
2020-09-11 05:57:51 +02:00
|
|
|
this.setCurrentStreamDuration = this.setCurrentStreamDuration.bind(this);
|
2020-08-24 06:23:16 +02:00
|
|
|
|
2021-01-27 08:03:25 +01:00
|
|
|
this.handleKeyPressed = this.handleKeyPressed.bind(this);
|
2021-03-15 23:32:52 +01:00
|
|
|
this.displayExternalAction = this.displayExternalAction.bind(this);
|
|
|
|
this.closeExternalActionModal = this.closeExternalActionModal.bind(this);
|
2022-01-12 22:53:10 +01:00
|
|
|
this.displayFediverseFollowModal =
|
|
|
|
this.displayFediverseFollowModal.bind(this);
|
|
|
|
this.closeFediverseFollowModal = this.closeFediverseFollowModal.bind(this);
|
2022-03-18 21:33:23 +01:00
|
|
|
this.displayNotificationModal = this.displayNotificationModal.bind(this);
|
|
|
|
this.closeNotificationModal = this.closeNotificationModal.bind(this);
|
2021-01-27 08:03:25 +01:00
|
|
|
|
2020-08-24 06:23:16 +02:00
|
|
|
// player events
|
2020-07-16 21:17:05 +02:00
|
|
|
this.handlePlayerReady = this.handlePlayerReady.bind(this);
|
|
|
|
this.handlePlayerPlaying = this.handlePlayerPlaying.bind(this);
|
|
|
|
this.handlePlayerEnded = this.handlePlayerEnded.bind(this);
|
|
|
|
this.handlePlayerError = this.handlePlayerError.bind(this);
|
|
|
|
|
2020-08-24 06:23:16 +02:00
|
|
|
// fetch events
|
|
|
|
this.getConfig = this.getConfig.bind(this);
|
|
|
|
this.getStreamStatus = this.getStreamStatus.bind(this);
|
2021-07-20 04:22:29 +02:00
|
|
|
|
|
|
|
// user events
|
|
|
|
this.handleWebsocketMessage = this.handleWebsocketMessage.bind(this);
|
|
|
|
|
|
|
|
// chat
|
|
|
|
this.hasConfiguredChat = false;
|
|
|
|
this.setupChatAuth = this.setupChatAuth.bind(this);
|
|
|
|
this.disableChat = this.disableChat.bind(this);
|
2022-03-07 02:11:51 +01:00
|
|
|
this.socketHostOverride = null;
|
2020-07-16 21:17:05 +02:00
|
|
|
}
|
2020-08-24 06:23:16 +02:00
|
|
|
|
|
|
|
componentDidMount() {
|
2020-07-16 21:17:05 +02:00
|
|
|
this.getConfig();
|
2021-01-24 01:02:29 +01:00
|
|
|
if (!this.hasTouchScreen) {
|
|
|
|
window.addEventListener('resize', this.handleWindowResize);
|
|
|
|
}
|
2020-12-23 02:43:35 +01:00
|
|
|
window.addEventListener('blur', this.handleWindowBlur);
|
|
|
|
window.addEventListener('focus', this.handleWindowFocus);
|
2020-09-22 05:11:09 +02:00
|
|
|
if (this.hasTouchScreen) {
|
|
|
|
window.addEventListener('orientationchange', this.handleWindowResize);
|
|
|
|
}
|
2021-01-27 08:03:25 +01:00
|
|
|
window.addEventListener('keypress', this.handleKeyPressed);
|
2020-07-16 21:17:05 +02:00
|
|
|
this.player = new OwncastPlayer();
|
|
|
|
this.player.setupPlayerCallbacks({
|
|
|
|
onReady: this.handlePlayerReady,
|
|
|
|
onPlaying: this.handlePlayerPlaying,
|
|
|
|
onEnded: this.handlePlayerEnded,
|
|
|
|
onError: this.handlePlayerError,
|
|
|
|
});
|
|
|
|
this.player.init();
|
2022-01-12 22:53:10 +01:00
|
|
|
|
2022-03-18 21:33:23 +01:00
|
|
|
this.registerServiceWorker();
|
|
|
|
|
2022-01-12 22:53:10 +01:00
|
|
|
// check routing
|
|
|
|
this.getRoute();
|
2022-03-18 21:33:23 +01:00
|
|
|
|
|
|
|
// Increment the visit counter
|
|
|
|
this.incrementVisitCounter();
|
|
|
|
}
|
|
|
|
|
|
|
|
incrementVisitCounter() {
|
|
|
|
let visits = parseInt(getLocalStorage(USER_VISIT_COUNT_KEY));
|
|
|
|
if (isNaN(visits)) {
|
|
|
|
visits = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
setLocalStorage(USER_VISIT_COUNT_KEY, visits + 1);
|
2020-07-29 06:30:03 +02:00
|
|
|
}
|
|
|
|
|
2020-08-24 06:23:16 +02:00
|
|
|
componentWillUnmount() {
|
|
|
|
// clear all the timers
|
|
|
|
clearInterval(this.playerRestartTimer);
|
|
|
|
clearInterval(this.offlineTimer);
|
|
|
|
clearInterval(this.statusTimer);
|
2021-07-20 04:22:29 +02:00
|
|
|
clearTimeout(this.disableChatInputTimer);
|
2020-08-24 06:23:16 +02:00
|
|
|
clearInterval(this.streamDurationTimer);
|
2020-08-24 21:34:36 +02:00
|
|
|
window.removeEventListener('resize', this.handleWindowResize);
|
2020-12-23 02:43:35 +01:00
|
|
|
window.removeEventListener('blur', this.handleWindowBlur);
|
|
|
|
window.removeEventListener('focus', this.handleWindowFocus);
|
2021-01-27 08:03:25 +01:00
|
|
|
window.removeEventListener('keypress', this.handleKeyPressed);
|
2020-09-22 05:11:09 +02:00
|
|
|
if (this.hasTouchScreen) {
|
|
|
|
window.removeEventListener('orientationchange', this.handleWindowResize);
|
|
|
|
}
|
2020-07-19 02:27:04 +02:00
|
|
|
}
|
|
|
|
|
2022-01-12 22:53:10 +01:00
|
|
|
getRoute() {
|
|
|
|
const routeInfo = checkUrlPathForDisplay();
|
|
|
|
this.setState({
|
|
|
|
...routeInfo,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-07-16 21:17:05 +02:00
|
|
|
// fetch /config data
|
|
|
|
getConfig() {
|
|
|
|
fetch(URL_CONFIG)
|
2020-09-11 05:57:51 +02:00
|
|
|
.then((response) => {
|
|
|
|
if (!response.ok) {
|
|
|
|
throw new Error(`Network response was not ok ${response.ok}`);
|
|
|
|
}
|
|
|
|
return response.json();
|
|
|
|
})
|
|
|
|
.then((json) => {
|
|
|
|
this.setConfigData(json);
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
this.handleNetworkingError(`Fetch config: ${error}`);
|
|
|
|
});
|
2020-07-16 21:17:05 +02:00
|
|
|
}
|
2020-06-18 05:20:28 +02:00
|
|
|
|
2020-07-16 21:17:05 +02:00
|
|
|
// fetch stream status
|
|
|
|
getStreamStatus() {
|
|
|
|
fetch(URL_STATUS)
|
2020-09-11 05:57:51 +02:00
|
|
|
.then((response) => {
|
2020-07-16 21:17:05 +02:00
|
|
|
if (!response.ok) {
|
|
|
|
throw new Error(`Network response was not ok ${response.ok}`);
|
|
|
|
}
|
|
|
|
return response.json();
|
|
|
|
})
|
2020-09-11 05:57:51 +02:00
|
|
|
.then((json) => {
|
2020-07-16 21:17:05 +02:00
|
|
|
this.updateStreamStatus(json);
|
|
|
|
})
|
2020-09-11 05:57:51 +02:00
|
|
|
.catch((error) => {
|
2020-07-16 21:17:05 +02:00
|
|
|
this.handleOfflineMode();
|
|
|
|
this.handleNetworkingError(`Stream status: ${error}`);
|
|
|
|
});
|
2021-06-21 02:26:23 +02:00
|
|
|
|
|
|
|
// Ping the API to let them know we're an active viewer
|
|
|
|
fetch(URL_VIEWER_PING).catch((error) => {
|
|
|
|
this.handleOfflineMode();
|
|
|
|
this.handleNetworkingError(`Viewer PING error: ${error}`);
|
|
|
|
});
|
2020-08-24 06:23:16 +02:00
|
|
|
}
|
2020-06-02 22:56:59 +02:00
|
|
|
|
2020-08-24 06:23:16 +02:00
|
|
|
setConfigData(data = {}) {
|
2022-03-18 21:33:23 +01:00
|
|
|
const { name, summary, chatDisabled, socketHostOverride, notifications } =
|
|
|
|
data;
|
2021-02-19 08:05:52 +01:00
|
|
|
window.document.title = name;
|
2020-08-24 06:23:16 +02:00
|
|
|
|
2022-03-07 02:11:51 +01:00
|
|
|
this.socketHostOverride = socketHostOverride;
|
|
|
|
|
2021-07-20 04:22:29 +02:00
|
|
|
// If this is the first time setting the config
|
|
|
|
// then setup chat if it's enabled.
|
2021-11-12 00:39:56 +01:00
|
|
|
if (!this.hasConfiguredChat && !chatDisabled) {
|
2021-07-20 04:22:29 +02:00
|
|
|
this.setupChatAuth();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.hasConfiguredChat = true;
|
|
|
|
|
2020-08-24 06:23:16 +02:00
|
|
|
this.setState({
|
2021-11-12 00:39:56 +01:00
|
|
|
canChat: !chatDisabled,
|
2022-03-18 21:33:23 +01:00
|
|
|
notifications,
|
2020-08-24 06:23:16 +02:00
|
|
|
configData: {
|
|
|
|
...data,
|
|
|
|
summary: summary && addNewlines(summary),
|
|
|
|
},
|
2020-07-20 01:11:29 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-07-16 21:17:05 +02:00
|
|
|
// handle UI things from stream status result
|
2020-07-20 01:06:55 +02:00
|
|
|
updateStreamStatus(status = {}) {
|
2020-08-24 06:23:16 +02:00
|
|
|
const { streamOnline: curStreamOnline } = this.state;
|
|
|
|
|
2020-07-20 01:06:55 +02:00
|
|
|
if (!status) {
|
|
|
|
return;
|
|
|
|
}
|
2021-06-20 19:49:54 +02:00
|
|
|
const {
|
|
|
|
viewerCount,
|
|
|
|
online,
|
|
|
|
lastConnectTime,
|
|
|
|
streamTitle,
|
|
|
|
lastDisconnectTime,
|
|
|
|
} = status;
|
2020-06-15 01:44:38 +02:00
|
|
|
|
2020-08-24 06:23:16 +02:00
|
|
|
this.setState({
|
|
|
|
viewerCount,
|
2020-09-11 05:57:51 +02:00
|
|
|
lastConnectTime,
|
2020-08-24 06:23:16 +02:00
|
|
|
streamOnline: online,
|
2021-02-19 08:05:52 +01:00
|
|
|
streamTitle,
|
2021-06-20 19:49:16 +02:00
|
|
|
lastDisconnectTime,
|
2020-08-24 06:23:16 +02:00
|
|
|
});
|
2021-08-13 08:24:43 +02:00
|
|
|
|
2021-08-16 03:22:13 +02:00
|
|
|
if (status.online !== curStreamOnline) {
|
|
|
|
if (status.online) {
|
|
|
|
// stream has just come online.
|
|
|
|
this.handleOnlineMode();
|
|
|
|
} else {
|
|
|
|
// stream has just flipped offline or app just got loaded and stream is offline.
|
|
|
|
this.handleOfflineMode(lastDisconnectTime);
|
|
|
|
}
|
2021-08-13 08:24:43 +02:00
|
|
|
}
|
2020-08-24 06:23:16 +02:00
|
|
|
}
|
2020-08-14 13:19:19 +02:00
|
|
|
|
2020-08-24 06:23:16 +02:00
|
|
|
// when videojs player is ready, start polling for stream
|
|
|
|
handlePlayerReady() {
|
|
|
|
this.getStreamStatus();
|
|
|
|
this.statusTimer = setInterval(this.getStreamStatus, TIMER_STATUS_UPDATE);
|
|
|
|
}
|
2020-07-19 00:06:54 +02:00
|
|
|
|
2020-08-24 06:23:16 +02:00
|
|
|
handlePlayerPlaying() {
|
2020-10-22 23:14:44 +02:00
|
|
|
this.setState({
|
|
|
|
isPlaying: true,
|
|
|
|
});
|
2020-07-19 00:06:54 +02:00
|
|
|
}
|
2020-08-14 13:19:19 +02:00
|
|
|
|
2020-08-24 06:23:16 +02:00
|
|
|
// likely called some time after stream status has gone offline.
|
|
|
|
// basically hide video and show underlying "poster"
|
|
|
|
handlePlayerEnded() {
|
|
|
|
this.setState({
|
|
|
|
playerActive: false,
|
2020-10-22 23:14:44 +02:00
|
|
|
isPlaying: false,
|
2020-08-24 06:23:16 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
handlePlayerError() {
|
|
|
|
// do something?
|
|
|
|
this.handleOfflineMode();
|
|
|
|
this.handlePlayerEnded();
|
|
|
|
}
|
2020-07-16 21:17:05 +02:00
|
|
|
|
2020-07-20 01:11:29 +02:00
|
|
|
// stop status timer and disable chat after some time.
|
2021-08-13 08:24:43 +02:00
|
|
|
handleOfflineMode(lastDisconnectTime) {
|
2020-07-20 01:06:55 +02:00
|
|
|
clearInterval(this.streamDurationTimer);
|
2021-08-13 08:24:43 +02:00
|
|
|
|
|
|
|
if (lastDisconnectTime) {
|
|
|
|
const remainingChatTime =
|
|
|
|
TIMER_DISABLE_CHAT_AFTER_OFFLINE -
|
|
|
|
(Date.now() - new Date(lastDisconnectTime));
|
|
|
|
const countdown = remainingChatTime < 0 ? 0 : remainingChatTime;
|
2021-08-16 03:22:13 +02:00
|
|
|
if (countdown > 0) {
|
|
|
|
this.setState({
|
|
|
|
chatInputEnabled: true,
|
|
|
|
});
|
|
|
|
}
|
2021-08-13 08:24:43 +02:00
|
|
|
this.disableChatInputTimer = setTimeout(this.disableChatInput, countdown);
|
|
|
|
}
|
|
|
|
|
2020-08-24 06:23:16 +02:00
|
|
|
this.setState({
|
|
|
|
streamOnline: false,
|
|
|
|
streamStatusMessage: MESSAGE_OFFLINE,
|
|
|
|
});
|
2020-08-30 02:35:19 +02:00
|
|
|
|
|
|
|
if (this.player.vjsPlayer && this.player.vjsPlayer.paused()) {
|
|
|
|
this.handlePlayerEnded();
|
|
|
|
}
|
2020-12-23 02:43:35 +01:00
|
|
|
|
|
|
|
if (this.windowBlurred) {
|
2021-03-14 19:46:27 +01:00
|
|
|
document.title = ` 🔴 ${
|
|
|
|
this.state.configData && this.state.configData.name
|
|
|
|
}`;
|
2020-12-23 02:43:35 +01:00
|
|
|
}
|
2020-08-24 06:23:16 +02:00
|
|
|
}
|
2020-06-03 02:35:49 +02:00
|
|
|
|
2020-07-16 21:17:05 +02:00
|
|
|
// play video!
|
|
|
|
handleOnlineMode() {
|
|
|
|
this.player.startPlayer();
|
2021-07-20 04:22:29 +02:00
|
|
|
clearTimeout(this.disableChatInputTimer);
|
|
|
|
this.disableChatInputTimer = null;
|
2020-07-19 00:06:54 +02:00
|
|
|
|
2020-09-11 05:57:51 +02:00
|
|
|
this.streamDurationTimer = setInterval(
|
|
|
|
this.setCurrentStreamDuration,
|
|
|
|
TIMER_STREAM_DURATION_COUNTER
|
|
|
|
);
|
2020-08-24 06:23:16 +02:00
|
|
|
|
|
|
|
this.setState({
|
|
|
|
playerActive: true,
|
|
|
|
streamOnline: true,
|
2020-09-13 03:46:08 +02:00
|
|
|
chatInputEnabled: true,
|
2021-02-19 08:05:52 +01:00
|
|
|
streamTitle: '',
|
2020-08-24 06:23:16 +02:00
|
|
|
streamStatusMessage: MESSAGE_ONLINE,
|
|
|
|
});
|
2020-12-23 02:43:35 +01:00
|
|
|
|
|
|
|
if (this.windowBlurred) {
|
2021-03-14 19:46:27 +01:00
|
|
|
document.title = ` 🟢 ${
|
|
|
|
this.state.configData && this.state.configData.name
|
|
|
|
}`;
|
2020-12-23 02:43:35 +01:00
|
|
|
}
|
2020-06-03 02:35:49 +02:00
|
|
|
}
|
|
|
|
|
2020-09-11 05:57:51 +02:00
|
|
|
setCurrentStreamDuration() {
|
|
|
|
let streamDurationString = '';
|
|
|
|
if (this.state.lastConnectTime) {
|
|
|
|
const diff = (Date.now() - Date.parse(this.state.lastConnectTime)) / 1000;
|
2020-10-29 12:46:54 +01:00
|
|
|
streamDurationString = parseSecondsToDurationString(diff);
|
2020-09-11 05:57:51 +02:00
|
|
|
}
|
|
|
|
this.setState({
|
|
|
|
streamStatusMessage: `${MESSAGE_ONLINE} ${streamDurationString}`,
|
|
|
|
});
|
|
|
|
}
|
2020-07-16 21:17:05 +02:00
|
|
|
|
2020-10-14 13:33:55 +02:00
|
|
|
handleUsernameChange(newName) {
|
2020-08-24 06:23:16 +02:00
|
|
|
this.setState({
|
|
|
|
username: newName,
|
|
|
|
});
|
2021-07-20 04:22:29 +02:00
|
|
|
|
|
|
|
this.sendUsernameChange(newName);
|
2020-08-24 06:23:16 +02:00
|
|
|
}
|
2020-07-16 21:17:05 +02:00
|
|
|
|
2020-12-12 20:08:23 +01:00
|
|
|
handleFormFocus() {
|
|
|
|
if (this.hasTouchScreen) {
|
|
|
|
this.setState({
|
|
|
|
touchKeyboardActive: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleFormBlur() {
|
|
|
|
if (this.hasTouchScreen) {
|
|
|
|
this.setState({
|
|
|
|
touchKeyboardActive: false,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-24 06:23:16 +02:00
|
|
|
handleChatPanelToggle() {
|
2021-07-20 04:22:29 +02:00
|
|
|
const { displayChatPanel: curDisplayed } = this.state;
|
2020-08-24 06:23:16 +02:00
|
|
|
|
|
|
|
const displayChat = !curDisplayed;
|
2021-07-20 04:22:29 +02:00
|
|
|
setLocalStorage(KEY_CHAT_DISPLAYED, displayChat);
|
2020-08-24 06:23:16 +02:00
|
|
|
this.setState({
|
2021-07-20 04:22:29 +02:00
|
|
|
displayChatPanel: displayChat,
|
2020-08-24 06:23:16 +02:00
|
|
|
});
|
|
|
|
}
|
2020-06-02 22:56:59 +02:00
|
|
|
|
2020-08-24 06:23:16 +02:00
|
|
|
disableChatInput() {
|
|
|
|
this.setState({
|
2020-09-13 03:46:08 +02:00
|
|
|
chatInputEnabled: false,
|
2020-08-24 06:23:16 +02:00
|
|
|
});
|
|
|
|
}
|
2020-06-17 06:05:54 +02:00
|
|
|
|
2020-08-24 06:23:16 +02:00
|
|
|
handleNetworkingError(error) {
|
2021-07-20 04:22:29 +02:00
|
|
|
console.error(`>>> App Error: ${error}`);
|
2020-08-24 06:23:16 +02:00
|
|
|
}
|
2020-06-02 22:56:59 +02:00
|
|
|
|
2020-08-24 12:30:42 +02:00
|
|
|
handleWindowResize() {
|
|
|
|
this.setState({
|
|
|
|
windowWidth: window.innerWidth,
|
|
|
|
windowHeight: window.innerHeight,
|
2020-09-23 02:09:55 +02:00
|
|
|
orientation: getOrientation(this.hasTouchScreen),
|
2020-08-24 12:30:42 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-12-23 02:43:35 +01:00
|
|
|
handleWindowBlur() {
|
|
|
|
this.windowBlurred = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
handleWindowFocus() {
|
|
|
|
this.windowBlurred = false;
|
2021-02-19 08:05:52 +01:00
|
|
|
window.document.title = this.state.configData && this.state.configData.name;
|
2020-12-23 02:43:35 +01:00
|
|
|
}
|
|
|
|
|
2021-01-27 08:03:25 +01:00
|
|
|
handleSpaceBarPressed(e) {
|
|
|
|
e.preventDefault();
|
2021-03-14 19:46:27 +01:00
|
|
|
if (this.state.isPlaying) {
|
2021-01-27 08:03:25 +01:00
|
|
|
this.setState({
|
|
|
|
isPlaying: false,
|
|
|
|
});
|
2021-09-17 23:04:09 +02:00
|
|
|
try {
|
|
|
|
this.player.vjsPlayer.pause();
|
|
|
|
} catch (err) {
|
|
|
|
console.warn(err);
|
|
|
|
}
|
2021-01-27 08:03:25 +01:00
|
|
|
} else {
|
|
|
|
this.setState({
|
|
|
|
isPlaying: true,
|
|
|
|
});
|
|
|
|
this.player.vjsPlayer.play();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-01 23:09:02 +02:00
|
|
|
handleMuteKeyPressed() {
|
|
|
|
const muted = this.player.vjsPlayer.muted();
|
|
|
|
const volume = this.player.vjsPlayer.volume();
|
|
|
|
|
2021-09-17 23:04:09 +02:00
|
|
|
try {
|
|
|
|
if (volume === 0) {
|
|
|
|
this.player.vjsPlayer.volume(0.5);
|
|
|
|
this.player.vjsPlayer.muted(false);
|
|
|
|
} else {
|
|
|
|
this.player.vjsPlayer.muted(!muted);
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
console.warn(err);
|
2021-04-01 23:09:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleFullScreenKeyPressed() {
|
|
|
|
if (this.player.vjsPlayer.isFullscreen()) {
|
|
|
|
this.player.vjsPlayer.exitFullscreen();
|
|
|
|
} else {
|
|
|
|
this.player.vjsPlayer.requestFullscreen();
|
2021-03-15 23:32:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-01 23:09:02 +02:00
|
|
|
handleVolumeSet(factor) {
|
|
|
|
this.player.vjsPlayer.volume(this.player.vjsPlayer.volume() + factor);
|
|
|
|
}
|
|
|
|
|
2021-01-27 08:03:25 +01:00
|
|
|
handleKeyPressed(e) {
|
2022-01-12 22:53:10 +01:00
|
|
|
// Only handle shortcuts if the focus is on the general page body,
|
|
|
|
// not a specific input field.
|
|
|
|
if (e.target !== document.getElementById('app-body')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.state.streamOnline) {
|
2021-04-01 23:09:02 +02:00
|
|
|
switch (e.code) {
|
|
|
|
case 'MediaPlayPause':
|
|
|
|
case 'KeyP':
|
|
|
|
case 'Space':
|
|
|
|
this.handleSpaceBarPressed(e);
|
|
|
|
break;
|
|
|
|
case 'KeyM':
|
|
|
|
this.handleMuteKeyPressed(e);
|
|
|
|
break;
|
|
|
|
case 'KeyF':
|
|
|
|
this.handleFullScreenKeyPressed(e);
|
|
|
|
break;
|
|
|
|
case 'KeyC':
|
|
|
|
this.handleChatPanelToggle();
|
|
|
|
break;
|
|
|
|
case 'Digit9':
|
|
|
|
this.handleVolumeSet(-0.1);
|
|
|
|
break;
|
|
|
|
case 'Digit0':
|
|
|
|
this.handleVolumeSet(0.1);
|
|
|
|
}
|
2021-01-27 08:03:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-21 02:23:39 +02:00
|
|
|
displayExternalAction(action) {
|
|
|
|
const { username } = this.state;
|
2021-03-15 23:32:52 +01:00
|
|
|
if (!action) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const { url: actionUrl, openExternally } = action || {};
|
|
|
|
let url = new URL(actionUrl);
|
|
|
|
// Append url and username to params so the link knows where we came from and who we are.
|
|
|
|
url.searchParams.append('username', username);
|
|
|
|
url.searchParams.append('instance', window.location);
|
|
|
|
|
2021-04-20 01:03:25 +02:00
|
|
|
const fullUrl = url.toString();
|
|
|
|
|
2021-03-15 23:32:52 +01:00
|
|
|
if (openExternally) {
|
2021-04-20 01:03:25 +02:00
|
|
|
var win = window.open(fullUrl, '_blank');
|
2021-03-15 23:32:52 +01:00
|
|
|
win.focus();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.setState({
|
2022-01-12 22:53:10 +01:00
|
|
|
externalActionModalData: {
|
2021-06-21 02:23:39 +02:00
|
|
|
...action,
|
|
|
|
url: fullUrl,
|
|
|
|
},
|
2021-03-15 23:32:52 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
closeExternalActionModal() {
|
|
|
|
this.setState({
|
2022-01-12 22:53:10 +01:00
|
|
|
externalActionModalData: null,
|
2021-03-15 23:32:52 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-01-12 22:53:10 +01:00
|
|
|
displayFediverseFollowModal(data) {
|
|
|
|
this.setState({ fediverseModalData: data });
|
|
|
|
}
|
|
|
|
closeFediverseFollowModal() {
|
|
|
|
this.setState({ fediverseModalData: null });
|
|
|
|
}
|
|
|
|
|
2022-03-18 21:33:23 +01:00
|
|
|
displayNotificationModal(data) {
|
|
|
|
this.setState({ notificationModalData: data });
|
|
|
|
}
|
|
|
|
closeNotificationModal() {
|
|
|
|
this.setState({ notificationModalData: null });
|
|
|
|
}
|
|
|
|
|
|
|
|
async registerServiceWorker() {
|
|
|
|
try {
|
|
|
|
const reg = await navigator.serviceWorker.register('/serviceWorker.js', {
|
|
|
|
scope: '/',
|
|
|
|
});
|
|
|
|
} catch (err) {
|
|
|
|
console.error('Owncast service worker registration failed!', err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-20 04:22:29 +02:00
|
|
|
handleWebsocketMessage(e) {
|
|
|
|
if (e.type === SOCKET_MESSAGE_TYPES.ERROR_USER_DISABLED) {
|
|
|
|
// User has been actively disabled on the backend. Turn off chat for them.
|
|
|
|
this.handleBlockedChat();
|
2021-07-20 04:23:06 +02:00
|
|
|
} else if (
|
|
|
|
e.type === SOCKET_MESSAGE_TYPES.ERROR_NEEDS_REGISTRATION &&
|
|
|
|
!this.isRegistering
|
|
|
|
) {
|
2021-07-20 04:22:29 +02:00
|
|
|
// User needs an access token, so start the user auth flow.
|
|
|
|
this.state.websocket.shutdown();
|
2021-07-20 04:23:06 +02:00
|
|
|
this.setState({ websocket: null });
|
2021-07-20 04:22:29 +02:00
|
|
|
this.setupChatAuth(true);
|
|
|
|
} else if (e.type === SOCKET_MESSAGE_TYPES.ERROR_MAX_CONNECTIONS_EXCEEDED) {
|
|
|
|
// Chat server cannot support any more chat clients. Turn off chat for them.
|
|
|
|
this.disableChat();
|
|
|
|
} else if (e.type === SOCKET_MESSAGE_TYPES.CONNECTED_USER_INFO) {
|
|
|
|
// When connected the user will return an event letting us know what our
|
|
|
|
// user details are so we can display them properly.
|
2021-07-20 04:23:06 +02:00
|
|
|
const { user } = e;
|
|
|
|
const { displayName } = user;
|
2021-07-20 04:22:29 +02:00
|
|
|
|
2021-11-03 03:27:41 +01:00
|
|
|
this.setState({
|
|
|
|
username: displayName,
|
|
|
|
isModerator: checkIsModerator(e),
|
|
|
|
});
|
2021-07-20 04:22:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleBlockedChat() {
|
|
|
|
this.disableChat();
|
|
|
|
}
|
|
|
|
|
|
|
|
disableChat() {
|
|
|
|
this.state.websocket.shutdown();
|
|
|
|
this.setState({ websocket: null, canChat: false });
|
|
|
|
}
|
|
|
|
|
|
|
|
async setupChatAuth(force) {
|
|
|
|
var accessToken = getLocalStorage(KEY_ACCESS_TOKEN);
|
|
|
|
var username = getLocalStorage(KEY_USERNAME);
|
|
|
|
|
|
|
|
if (!accessToken || force) {
|
|
|
|
try {
|
|
|
|
this.isRegistering = true;
|
|
|
|
const registration = await registerChat(this.state.username);
|
|
|
|
accessToken = registration.accessToken;
|
|
|
|
username = registration.displayName;
|
|
|
|
|
|
|
|
setLocalStorage(KEY_ACCESS_TOKEN, accessToken);
|
|
|
|
setLocalStorage(KEY_USERNAME, username);
|
|
|
|
|
|
|
|
this.isRegistering = false;
|
|
|
|
} catch (e) {
|
|
|
|
console.error('registration error:', e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.state.websocket) {
|
|
|
|
this.state.websocket.shutdown();
|
|
|
|
this.setState({
|
2021-07-20 04:23:06 +02:00
|
|
|
websocket: null,
|
2021-07-20 04:22:29 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-03-07 02:11:51 +01:00
|
|
|
// Without a valid access token the websocket connection will be rejected.
|
|
|
|
const websocket = new Websocket(
|
|
|
|
accessToken,
|
|
|
|
this.socketHostOverride || URL_WEBSOCKET
|
|
|
|
);
|
2021-07-20 04:22:29 +02:00
|
|
|
websocket.addListener(
|
|
|
|
CALLBACKS.RAW_WEBSOCKET_MESSAGE_RECEIVED,
|
|
|
|
this.handleWebsocketMessage
|
|
|
|
);
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
username,
|
|
|
|
websocket,
|
|
|
|
accessToken,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
sendUsernameChange(newName) {
|
2021-07-20 04:23:06 +02:00
|
|
|
const nameChange = {
|
|
|
|
type: SOCKET_MESSAGE_TYPES.NAME_CHANGE,
|
|
|
|
newName,
|
|
|
|
};
|
|
|
|
this.state.websocket.send(nameChange);
|
2021-07-20 04:22:29 +02:00
|
|
|
}
|
|
|
|
|
2020-08-24 06:23:16 +02:00
|
|
|
render(props, state) {
|
|
|
|
const {
|
2022-03-18 21:33:23 +01:00
|
|
|
accessToken,
|
2020-09-13 03:46:08 +02:00
|
|
|
chatInputEnabled,
|
2020-08-24 06:23:16 +02:00
|
|
|
configData,
|
2021-07-20 04:22:29 +02:00
|
|
|
displayChatPanel,
|
|
|
|
canChat,
|
2021-11-03 03:27:41 +01:00
|
|
|
isModerator,
|
2021-07-20 04:22:29 +02:00
|
|
|
|
2020-10-22 23:14:44 +02:00
|
|
|
isPlaying,
|
2020-09-23 02:09:55 +02:00
|
|
|
orientation,
|
2020-08-24 06:23:16 +02:00
|
|
|
playerActive,
|
|
|
|
streamOnline,
|
|
|
|
streamStatusMessage,
|
2021-02-19 08:05:52 +01:00
|
|
|
streamTitle,
|
2020-12-12 20:08:23 +01:00
|
|
|
touchKeyboardActive,
|
2020-08-24 12:30:42 +02:00
|
|
|
username,
|
|
|
|
viewerCount,
|
|
|
|
websocket,
|
|
|
|
windowHeight,
|
|
|
|
windowWidth,
|
2022-01-12 22:53:10 +01:00
|
|
|
fediverseModalData,
|
|
|
|
externalActionModalData,
|
2022-03-18 21:33:23 +01:00
|
|
|
notificationModalData,
|
|
|
|
notifications,
|
2021-06-20 19:49:16 +02:00
|
|
|
lastDisconnectTime,
|
2022-01-12 22:53:10 +01:00
|
|
|
section,
|
|
|
|
sectionId,
|
2020-08-24 06:23:16 +02:00
|
|
|
} = state;
|
2022-01-12 22:53:10 +01:00
|
|
|
|
2020-08-24 06:23:16 +02:00
|
|
|
const {
|
|
|
|
version: appVersion,
|
2020-11-18 00:12:54 +01:00
|
|
|
logo = TEMP_IMAGE,
|
2020-08-24 06:23:16 +02:00
|
|
|
socialHandles = [],
|
|
|
|
summary,
|
|
|
|
tags = [],
|
2021-02-19 08:05:52 +01:00
|
|
|
name,
|
2020-10-14 18:38:48 +02:00
|
|
|
extraPageContent,
|
2021-03-14 19:46:27 +01:00
|
|
|
chatDisabled,
|
2021-03-15 23:32:52 +01:00
|
|
|
externalActions,
|
2021-04-16 07:00:46 +02:00
|
|
|
customStyles,
|
2021-07-20 04:22:29 +02:00
|
|
|
maxSocketPayloadSize,
|
2022-01-12 22:53:10 +01:00
|
|
|
federation = {},
|
2020-08-24 06:23:16 +02:00
|
|
|
} = configData;
|
2020-11-18 00:12:54 +01:00
|
|
|
|
|
|
|
const bgUserLogo = { backgroundImage: `url(${logo})` };
|
2020-08-24 06:23:16 +02:00
|
|
|
|
2021-03-15 23:32:52 +01:00
|
|
|
const tagList = tags !== null && tags.length > 0 && tags.join(' #');
|
2020-08-24 06:23:16 +02:00
|
|
|
|
2021-06-20 19:49:16 +02:00
|
|
|
let viewerCountMessage = '';
|
|
|
|
if (streamOnline && viewerCount > 0) {
|
2021-06-20 19:49:54 +02:00
|
|
|
viewerCountMessage = html`${viewerCount}
|
2021-06-21 05:15:08 +02:00
|
|
|
${pluralize(' viewer', viewerCount)}`;
|
2021-06-20 19:49:16 +02:00
|
|
|
} else if (lastDisconnectTime) {
|
|
|
|
viewerCountMessage = makeLastOnlineString(lastDisconnectTime);
|
|
|
|
}
|
|
|
|
|
2020-08-24 06:23:16 +02:00
|
|
|
const mainClass = playerActive ? 'online' : '';
|
2021-03-14 19:46:27 +01:00
|
|
|
const isPortrait =
|
|
|
|
this.hasTouchScreen && orientation === ORIENTATION_PORTRAIT;
|
2020-09-23 02:09:55 +02:00
|
|
|
const shortHeight = windowHeight <= HEIGHT_SHORT_WIDE && !isPortrait;
|
2020-08-24 12:30:42 +02:00
|
|
|
const singleColMode = windowWidth <= WIDTH_SINGLE_COL && !shortHeight;
|
2020-09-22 05:11:09 +02:00
|
|
|
|
2022-01-12 22:53:10 +01:00
|
|
|
const noVideoContent =
|
|
|
|
!playerActive || (section === ROUTE_RECORDINGS && sectionId !== '');
|
|
|
|
const shouldDisplayChat =
|
2022-01-13 22:37:23 +01:00
|
|
|
displayChatPanel && !chatDisabled && chatInputEnabled;
|
2021-03-14 19:46:27 +01:00
|
|
|
|
2020-08-24 12:30:42 +02:00
|
|
|
const extraAppClasses = classNames({
|
2021-05-29 22:08:10 +02:00
|
|
|
'config-loading': configData.loading,
|
2022-01-12 22:53:10 +01:00
|
|
|
|
2021-03-14 19:46:27 +01:00
|
|
|
chat: shouldDisplayChat,
|
2022-01-12 22:53:10 +01:00
|
|
|
'no-chat': !shouldDisplayChat,
|
|
|
|
'no-video': noVideoContent,
|
2021-07-20 04:22:29 +02:00
|
|
|
'chat-hidden': !displayChatPanel && canChat && !chatDisabled, // hide panel
|
|
|
|
'chat-disabled': !canChat || chatDisabled,
|
2020-08-24 12:30:42 +02:00
|
|
|
'single-col': singleColMode,
|
2021-03-14 19:46:27 +01:00
|
|
|
'bg-gray-800': singleColMode && shouldDisplayChat,
|
2020-09-22 05:11:09 +02:00
|
|
|
'short-wide': shortHeight && windowWidth > WIDTH_SINGLE_COL,
|
|
|
|
'touch-screen': this.hasTouchScreen,
|
2020-12-12 20:08:23 +01:00
|
|
|
'touch-keyboard-active': touchKeyboardActive,
|
2020-09-11 05:57:51 +02:00
|
|
|
});
|
2020-08-24 06:23:16 +02:00
|
|
|
|
2021-03-14 19:46:27 +01:00
|
|
|
const poster = isPlaying
|
|
|
|
? null
|
|
|
|
: html` <${VideoPoster} offlineImage=${logo} active=${streamOnline} /> `;
|
2020-10-22 23:14:44 +02:00
|
|
|
|
2021-06-21 02:23:39 +02:00
|
|
|
// modal buttons
|
2022-03-18 21:33:23 +01:00
|
|
|
const notificationsButton =
|
|
|
|
notifications &&
|
|
|
|
notifications.browser.enabled &&
|
|
|
|
isPushNotificationSupported() &&
|
|
|
|
html`<${NotifyButton}
|
|
|
|
serverName=${name}
|
|
|
|
onClick=${this.displayNotificationModal}
|
|
|
|
/>`;
|
2022-01-12 22:53:10 +01:00
|
|
|
const externalActionButtons = html`<div
|
|
|
|
id="external-actions-container"
|
|
|
|
class="flex flex-row flex-wrap justify-end"
|
|
|
|
>
|
|
|
|
${externalActions &&
|
|
|
|
externalActions.map(
|
|
|
|
function (action) {
|
|
|
|
return html`<${ExternalActionButton}
|
|
|
|
onClick=${this.displayExternalAction}
|
|
|
|
action=${action}
|
|
|
|
/>`;
|
|
|
|
}.bind(this)
|
|
|
|
)}
|
|
|
|
|
|
|
|
<!-- fediverse follow button -->
|
|
|
|
${federation.enabled &&
|
|
|
|
html`<${FediverseFollowButton}
|
|
|
|
onClick=${this.displayFediverseFollowModal}
|
|
|
|
federationInfo=${federation}
|
|
|
|
serverName=${name}
|
|
|
|
/>`}
|
2022-03-18 21:33:23 +01:00
|
|
|
${notificationsButton}
|
2022-01-12 22:53:10 +01:00
|
|
|
</div>`;
|
2021-06-21 02:23:39 +02:00
|
|
|
|
|
|
|
// modal component
|
2021-06-21 02:24:12 +02:00
|
|
|
const externalActionModal =
|
2022-01-12 22:53:10 +01:00
|
|
|
externalActionModalData &&
|
2021-06-21 02:24:12 +02:00
|
|
|
html`<${ExternalActionModal}
|
2022-01-12 22:53:10 +01:00
|
|
|
action=${externalActionModalData}
|
2021-06-21 02:24:12 +02:00
|
|
|
onClose=${this.closeExternalActionModal}
|
|
|
|
/>`;
|
2021-03-15 23:32:52 +01:00
|
|
|
|
2022-01-12 22:53:10 +01:00
|
|
|
const fediverseFollowModal =
|
|
|
|
fediverseModalData &&
|
|
|
|
html`
|
|
|
|
<${ExternalActionModal}
|
|
|
|
onClose=${this.closeFediverseFollowModal}
|
|
|
|
action=${fediverseModalData}
|
|
|
|
useIframe=${false}
|
|
|
|
customContent=${html`<${FediverseFollowModal}
|
|
|
|
name=${name}
|
|
|
|
logo=${logo}
|
|
|
|
federationInfo=${federation}
|
|
|
|
onClose=${this.closeFediverseFollowModal}
|
|
|
|
/>`}
|
|
|
|
/>
|
|
|
|
`;
|
|
|
|
|
2022-03-18 21:33:23 +01:00
|
|
|
const notificationModal =
|
|
|
|
notificationModalData &&
|
|
|
|
html` <${ExternalActionModal}
|
|
|
|
onClose=${this.closeNotificationModal}
|
|
|
|
action=${notificationModalData}
|
|
|
|
useIframe=${false}
|
|
|
|
customContent=${html`<${NotifyModal}
|
|
|
|
notifications=${notifications}
|
|
|
|
streamName=${name}
|
|
|
|
accessToken=${accessToken}
|
|
|
|
/>`}
|
|
|
|
/>`;
|
|
|
|
|
2021-07-20 04:22:29 +02:00
|
|
|
const chat = this.state.websocket
|
|
|
|
? html`
|
|
|
|
<${Chat}
|
|
|
|
websocket=${websocket}
|
|
|
|
username=${username}
|
|
|
|
chatInputEnabled=${chatInputEnabled && !chatDisabled}
|
|
|
|
instanceTitle=${name}
|
2022-03-18 21:33:23 +01:00
|
|
|
accessToken=${accessToken}
|
2021-07-20 04:23:06 +02:00
|
|
|
inputMaxBytes=${maxSocketPayloadSize - EST_SOCKET_PAYLOAD_BUFFER ||
|
|
|
|
CHAT_MAX_MESSAGE_LENGTH}
|
2021-07-20 04:22:29 +02:00
|
|
|
/>
|
|
|
|
`
|
|
|
|
: null;
|
|
|
|
|
2022-01-12 22:53:10 +01:00
|
|
|
const TAB_CONTENT = [
|
|
|
|
{
|
|
|
|
label: 'About',
|
|
|
|
content: html`
|
|
|
|
<div>
|
|
|
|
<div
|
|
|
|
id="stream-summary"
|
|
|
|
class="stream-summary my-4"
|
|
|
|
dangerouslySetInnerHTML=${{ __html: summary }}
|
|
|
|
></div>
|
|
|
|
<div id="tag-list" class="tag-list text-gray-600 mb-3">
|
|
|
|
${tagList && `#${tagList}`}
|
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
id="extra-user-content"
|
|
|
|
class="extra-user-content"
|
|
|
|
dangerouslySetInnerHTML=${{ __html: extraPageContent }}
|
|
|
|
></div>
|
|
|
|
</div>
|
|
|
|
`,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
if (federation.enabled) {
|
|
|
|
TAB_CONTENT.push({
|
2022-01-24 23:35:15 +01:00
|
|
|
label: html`Followers
|
|
|
|
${federation.followerCount > 10
|
|
|
|
? `${' '}(${federation.followerCount})`
|
|
|
|
: null}`,
|
2022-01-12 22:53:10 +01:00
|
|
|
content: html`<${Followers} />`,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-09-11 05:57:51 +02:00
|
|
|
return html`
|
|
|
|
<div
|
|
|
|
id="app-container"
|
|
|
|
class="flex w-full flex-col justify-start relative ${extraAppClasses}"
|
|
|
|
>
|
2021-04-16 07:01:28 +02:00
|
|
|
<style>
|
|
|
|
${customStyles}
|
|
|
|
</style>
|
2021-04-16 07:00:46 +02:00
|
|
|
|
2020-09-11 05:57:51 +02:00
|
|
|
<div id="top-content" class="z-50">
|
|
|
|
<header
|
|
|
|
class="flex border-b border-gray-900 border-solid shadow-md fixed z-10 w-full top-0 left-0 flex flex-row justify-between flex-no-wrap"
|
|
|
|
>
|
|
|
|
<h1
|
|
|
|
class="flex flex-row items-center justify-start p-2 uppercase text-gray-400 text-xl font-thin tracking-wider overflow-hidden whitespace-no-wrap"
|
|
|
|
>
|
|
|
|
<span
|
|
|
|
id="logo-container"
|
2020-11-18 00:12:54 +01:00
|
|
|
class="inline-block rounded-full bg-white w-8 min-w-8 min-h-8 h-8 mr-2 bg-no-repeat bg-center"
|
2020-09-11 05:57:51 +02:00
|
|
|
>
|
2021-03-14 19:46:27 +01:00
|
|
|
<img
|
|
|
|
class="logo visually-hidden"
|
|
|
|
src=${OWNCAST_LOGO_LOCAL}
|
|
|
|
alt="owncast logo"
|
|
|
|
/>
|
2020-09-11 05:57:51 +02:00
|
|
|
</span>
|
|
|
|
<span class="instance-title overflow-hidden truncate"
|
2021-03-14 19:46:27 +01:00
|
|
|
>${streamOnline && streamTitle ? streamTitle : name}</span
|
2020-09-11 05:57:51 +02:00
|
|
|
>
|
|
|
|
</h1>
|
2020-08-24 06:23:16 +02:00
|
|
|
<div
|
2020-09-11 05:57:51 +02:00
|
|
|
id="user-options-container"
|
|
|
|
class="flex flex-row justify-end items-center flex-no-wrap"
|
2020-08-24 06:23:16 +02:00
|
|
|
>
|
2020-09-11 05:57:51 +02:00
|
|
|
<${UsernameForm}
|
|
|
|
username=${username}
|
2021-11-03 03:27:41 +01:00
|
|
|
isModerator=${isModerator}
|
2020-12-12 20:08:23 +01:00
|
|
|
onUsernameChange=${this.handleUsernameChange}
|
|
|
|
onFocus=${this.handleFormFocus}
|
|
|
|
onBlur=${this.handleFormBlur}
|
2020-09-11 05:57:51 +02:00
|
|
|
/>
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
id="chat-toggle"
|
|
|
|
onClick=${this.handleChatPanelToggle}
|
|
|
|
class="flex cursor-pointer text-center justify-center items-center min-w-12 h-full bg-gray-800 hover:bg-gray-700"
|
2022-01-12 22:53:10 +01:00
|
|
|
style=${{
|
|
|
|
display: chatDisabled || noVideoContent ? 'none' : 'block',
|
|
|
|
}}
|
2020-09-11 05:57:51 +02:00
|
|
|
>
|
|
|
|
💬
|
|
|
|
</button>
|
2020-08-24 06:23:16 +02:00
|
|
|
</div>
|
2020-09-11 05:57:51 +02:00
|
|
|
</header>
|
|
|
|
</div>
|
2020-08-24 06:23:16 +02:00
|
|
|
|
2020-09-11 05:57:51 +02:00
|
|
|
<main class=${mainClass}>
|
|
|
|
<div
|
|
|
|
id="video-container"
|
|
|
|
class="flex owncast-video-container bg-black w-full bg-center bg-no-repeat flex flex-col items-center justify-start"
|
|
|
|
>
|
|
|
|
<video
|
|
|
|
class="video-js vjs-big-play-centered display-block w-full h-full"
|
|
|
|
id="video"
|
|
|
|
preload="auto"
|
|
|
|
controls
|
|
|
|
playsinline
|
|
|
|
></video>
|
2020-10-22 23:14:44 +02:00
|
|
|
${poster}
|
2020-09-11 05:57:51 +02:00
|
|
|
</div>
|
2020-08-24 06:23:16 +02:00
|
|
|
|
2020-09-11 05:57:51 +02:00
|
|
|
<section
|
|
|
|
id="stream-info"
|
|
|
|
aria-label="Stream status"
|
2021-06-20 19:49:16 +02:00
|
|
|
class="flex text-center flex-row justify-between font-mono py-2 px-4 bg-gray-900 text-indigo-200 shadow-md border-b border-gray-100 border-solid"
|
2020-09-11 05:57:51 +02:00
|
|
|
>
|
2021-06-20 19:49:16 +02:00
|
|
|
<span class="text-xs">${streamStatusMessage}</span>
|
2021-06-20 19:49:54 +02:00
|
|
|
<span id="stream-viewer-count" class="text-xs text-right"
|
|
|
|
>${viewerCountMessage}</span
|
|
|
|
>
|
2020-08-24 06:23:16 +02:00
|
|
|
</section>
|
2020-09-11 05:57:51 +02:00
|
|
|
</main>
|
2020-08-24 06:23:16 +02:00
|
|
|
|
2022-01-12 22:53:10 +01:00
|
|
|
<section
|
|
|
|
id="user-content"
|
|
|
|
aria-label="Owncast server information"
|
|
|
|
class="p-2"
|
|
|
|
>
|
|
|
|
${externalActionButtons && html`${externalActionButtons}`}
|
|
|
|
|
2020-09-11 05:57:51 +02:00
|
|
|
<div class="user-content flex flex-row p-8">
|
|
|
|
<div
|
2022-01-12 22:53:10 +01:00
|
|
|
class="user-logo-icons flex flex-col items-center justify-start mr-8"
|
2020-09-11 05:57:51 +02:00
|
|
|
>
|
2022-01-12 22:53:10 +01:00
|
|
|
<div
|
|
|
|
class="user-image rounded-full bg-white p-4 bg-no-repeat bg-center"
|
|
|
|
style=${bgUserLogo}
|
|
|
|
>
|
|
|
|
<img class="logo visually-hidden" alt="" src=${logo} />
|
|
|
|
</div>
|
|
|
|
<div class="social-actions">
|
|
|
|
<${SocialIconsList} handles=${socialHandles} />
|
|
|
|
</div>
|
2020-09-11 05:57:51 +02:00
|
|
|
</div>
|
2022-01-12 22:53:10 +01:00
|
|
|
|
|
|
|
<div class="user-content-header">
|
|
|
|
<h2 class="server-name font-semibold text-5xl">
|
2021-03-14 19:46:27 +01:00
|
|
|
<span class="streamer-name text-indigo-600">${name}</span>
|
2020-09-11 05:57:51 +02:00
|
|
|
</h2>
|
2021-02-19 08:05:52 +01:00
|
|
|
<h3 class="font-semibold text-3xl">
|
|
|
|
${streamOnline && streamTitle}
|
|
|
|
</h3>
|
2022-01-12 22:53:10 +01:00
|
|
|
|
|
|
|
<!-- tab bar -->
|
|
|
|
<div class="${TAB_CONTENT.length > 1 ? 'my-8' : 'my-3'}">
|
|
|
|
<${TabBar} tabs=${TAB_CONTENT} ariaLabel="User Content" />
|
2021-03-15 23:32:52 +01:00
|
|
|
</div>
|
2020-09-11 05:57:51 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
|
|
|
|
<footer class="flex flex-row justify-start p-8 opacity-50 text-xs">
|
|
|
|
<span class="mx-1 inline-block">
|
2021-03-24 07:51:47 +01:00
|
|
|
<a href="${URL_OWNCAST}" rel="noopener noreferrer" target="_blank"
|
2021-04-21 18:46:48 +02:00
|
|
|
>${appVersion}</a
|
2021-03-24 07:51:47 +01:00
|
|
|
>
|
2020-09-11 05:57:51 +02:00
|
|
|
</span>
|
|
|
|
</footer>
|
|
|
|
|
2022-01-12 22:53:10 +01:00
|
|
|
${chat} ${externalActionModal} ${fediverseFollowModal}
|
2022-03-18 21:33:23 +01:00
|
|
|
${notificationModal}
|
2020-09-11 05:57:51 +02:00
|
|
|
</div>
|
|
|
|
`;
|
2020-08-24 06:23:16 +02:00
|
|
|
}
|
|
|
|
}
|