v1.2.0-beta/fix file structure
@@ -0,0 +1,93 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
const paths = require('./paths');
|
||||||
|
|
||||||
|
// Make sure that including paths.js after env.js will read .env variables.
|
||||||
|
delete require.cache[require.resolve('./paths')];
|
||||||
|
|
||||||
|
const NODE_ENV = process.env.NODE_ENV;
|
||||||
|
if (!NODE_ENV) {
|
||||||
|
throw new Error(
|
||||||
|
'The NODE_ENV environment variable is required but was not specified.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
|
||||||
|
var dotenvFiles = [
|
||||||
|
`${paths.dotenv}.${NODE_ENV}.local`,
|
||||||
|
`${paths.dotenv}.${NODE_ENV}`,
|
||||||
|
// Don't include `.env.local` for `test` environment
|
||||||
|
// since normally you expect tests to produce the same
|
||||||
|
// results for everyone
|
||||||
|
NODE_ENV !== 'test' && `${paths.dotenv}.local`,
|
||||||
|
paths.dotenv,
|
||||||
|
].filter(Boolean);
|
||||||
|
|
||||||
|
// Load environment variables from .env* files. Suppress warnings using silent
|
||||||
|
// if this file is missing. dotenv will never modify any environment variables
|
||||||
|
// that have already been set. Variable expansion is supported in .env files.
|
||||||
|
// https://github.com/motdotla/dotenv
|
||||||
|
// https://github.com/motdotla/dotenv-expand
|
||||||
|
dotenvFiles.forEach(dotenvFile => {
|
||||||
|
if (fs.existsSync(dotenvFile)) {
|
||||||
|
require('dotenv-expand')(
|
||||||
|
require('dotenv').config({
|
||||||
|
path: dotenvFile,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// We support resolving modules according to `NODE_PATH`.
|
||||||
|
// This lets you use absolute paths in imports inside large monorepos:
|
||||||
|
// https://github.com/facebookincubator/create-react-app/issues/253.
|
||||||
|
// It works similar to `NODE_PATH` in Node itself:
|
||||||
|
// https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders
|
||||||
|
// Note that unlike in Node, only *relative* paths from `NODE_PATH` are honored.
|
||||||
|
// Otherwise, we risk importing Node.js core modules into an app instead of Webpack shims.
|
||||||
|
// https://github.com/facebookincubator/create-react-app/issues/1023#issuecomment-265344421
|
||||||
|
// We also resolve them to make sure all tools using them work consistently.
|
||||||
|
const appDirectory = fs.realpathSync(process.cwd());
|
||||||
|
process.env.NODE_PATH = (process.env.NODE_PATH || '')
|
||||||
|
.split(path.delimiter)
|
||||||
|
.filter(folder => folder && !path.isAbsolute(folder))
|
||||||
|
.map(folder => path.resolve(appDirectory, folder))
|
||||||
|
.join(path.delimiter);
|
||||||
|
|
||||||
|
// Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be
|
||||||
|
// injected into the application via DefinePlugin in Webpack configuration.
|
||||||
|
const REACT_APP = /^REACT_APP_/i;
|
||||||
|
|
||||||
|
function getClientEnvironment(publicUrl) {
|
||||||
|
const raw = Object.keys(process.env)
|
||||||
|
.filter(key => REACT_APP.test(key))
|
||||||
|
.reduce(
|
||||||
|
(env, key) => {
|
||||||
|
env[key] = process.env[key];
|
||||||
|
return env;
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// Useful for determining whether we’re running in production mode.
|
||||||
|
// Most importantly, it switches React into the correct mode.
|
||||||
|
NODE_ENV: process.env.NODE_ENV || 'development',
|
||||||
|
// Useful for resolving the correct path to static assets in `public`.
|
||||||
|
// For example, <img src={process.env.PUBLIC_URL + '/img/logo.png'} />.
|
||||||
|
// This should only be used as an escape hatch. Normally you would put
|
||||||
|
// images into the `src` and `import` them in code to get their paths.
|
||||||
|
PUBLIC_URL: publicUrl,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
// Stringify all values so we can feed into Webpack DefinePlugin
|
||||||
|
const stringified = {
|
||||||
|
'process.env': Object.keys(raw).reduce((env, key) => {
|
||||||
|
env[key] = JSON.stringify(raw[key]);
|
||||||
|
return env;
|
||||||
|
}, {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
return { raw, stringified };
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = getClientEnvironment;
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
// This is a custom Jest transformer turning style imports into empty objects.
|
||||||
|
// http://facebook.github.io/jest/docs/en/webpack.html
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
process() {
|
||||||
|
return 'module.exports = {};';
|
||||||
|
},
|
||||||
|
getCacheKey() {
|
||||||
|
// The output is always the same.
|
||||||
|
return 'cssTransform';
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
// This is a custom Jest transformer turning file imports into filenames.
|
||||||
|
// http://facebook.github.io/jest/docs/en/webpack.html
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
process(src, filename) {
|
||||||
|
return `module.exports = ${JSON.stringify(path.basename(filename))};`;
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const path = require('path');
|
||||||
|
const fs = require('fs');
|
||||||
|
const url = require('url');
|
||||||
|
|
||||||
|
// Make sure any symlinks in the project folder are resolved:
|
||||||
|
// https://github.com/facebookincubator/create-react-app/issues/637
|
||||||
|
const appDirectory = fs.realpathSync(process.cwd());
|
||||||
|
const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
|
||||||
|
|
||||||
|
const envPublicUrl = process.env.PUBLIC_URL;
|
||||||
|
|
||||||
|
function ensureSlash(path, needsSlash) {
|
||||||
|
const hasSlash = path.endsWith('/');
|
||||||
|
if (hasSlash && !needsSlash) {
|
||||||
|
return path.substr(path, path.length - 1);
|
||||||
|
} else if (!hasSlash && needsSlash) {
|
||||||
|
return `${path}/`;
|
||||||
|
} else {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const getPublicUrl = appPackageJson =>
|
||||||
|
envPublicUrl || require(appPackageJson).homepage;
|
||||||
|
|
||||||
|
// We use `PUBLIC_URL` environment variable or "homepage" field to infer
|
||||||
|
// "public path" at which the app is served.
|
||||||
|
// Webpack needs to know it to put the right <script> hrefs into HTML even in
|
||||||
|
// single-page apps that may serve index.html for nested URLs like /todos/42.
|
||||||
|
// We can't use a relative path in HTML because we don't want to load something
|
||||||
|
// like /todos/42/static/js/bundle.7289d.js. We have to know the root.
|
||||||
|
function getServedPath(appPackageJson) {
|
||||||
|
const publicUrl = getPublicUrl(appPackageJson);
|
||||||
|
const servedUrl =
|
||||||
|
envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : '/');
|
||||||
|
return ensureSlash(servedUrl, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// config after eject: we're in ./config/
|
||||||
|
module.exports = {
|
||||||
|
dotenv: resolveApp('.env'),
|
||||||
|
appBuild: resolveApp('build'),
|
||||||
|
appPublic: resolveApp('public'),
|
||||||
|
appHtml: resolveApp('public/index.html'),
|
||||||
|
appIndexJs: resolveApp('src/index.js'),
|
||||||
|
appPackageJson: resolveApp('package.json'),
|
||||||
|
appSrc: resolveApp('src'),
|
||||||
|
yarnLockFile: resolveApp('yarn.lock'),
|
||||||
|
testsSetup: resolveApp('src/setupTests.js'),
|
||||||
|
appNodeModules: resolveApp('node_modules'),
|
||||||
|
publicUrl: getPublicUrl(resolveApp('package.json')),
|
||||||
|
servedPath: getServedPath(resolveApp('package.json')),
|
||||||
|
};
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
if (typeof Promise === 'undefined') {
|
||||||
|
// Rejection tracking prevents a common issue where React gets into an
|
||||||
|
// inconsistent state due to an error, but it gets swallowed by a Promise,
|
||||||
|
// and the user has no idea what causes React's erratic future behavior.
|
||||||
|
require('promise/lib/rejection-tracking').enable();
|
||||||
|
window.Promise = require('promise/lib/es6-extensions.js');
|
||||||
|
}
|
||||||
|
|
||||||
|
// fetch() polyfill for making API calls.
|
||||||
|
require('whatwg-fetch');
|
||||||
|
|
||||||
|
// Object.assign() is commonly used with React.
|
||||||
|
// It will use the native implementation if it's present and isn't buggy.
|
||||||
|
Object.assign = require('object-assign');
|
||||||
|
|
||||||
|
// In tests, polyfill requestAnimationFrame since jsdom doesn't provide it yet.
|
||||||
|
// We don't polyfill it in the browser--this is user's responsibility.
|
||||||
|
if (process.env.NODE_ENV === 'test') {
|
||||||
|
require('raf').polyfill(global);
|
||||||
|
}
|
||||||
@@ -0,0 +1,264 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const autoprefixer = require('autoprefixer');
|
||||||
|
const path = require('path');
|
||||||
|
const webpack = require('webpack');
|
||||||
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||||
|
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
|
||||||
|
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
|
||||||
|
const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
|
||||||
|
const eslintFormatter = require('react-dev-utils/eslintFormatter');
|
||||||
|
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
|
||||||
|
const getClientEnvironment = require('./env');
|
||||||
|
const paths = require('./paths');
|
||||||
|
|
||||||
|
// Webpack uses `publicPath` to determine where the app is being served from.
|
||||||
|
// In development, we always serve from the root. This makes config easier.
|
||||||
|
const publicPath = '/';
|
||||||
|
// `publicUrl` is just like `publicPath`, but we will provide it to our app
|
||||||
|
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
|
||||||
|
// Omit trailing slash as %PUBLIC_PATH%/xyz looks better than %PUBLIC_PATH%xyz.
|
||||||
|
const publicUrl = '';
|
||||||
|
// Get environment variables to inject into our app.
|
||||||
|
const env = getClientEnvironment(publicUrl);
|
||||||
|
|
||||||
|
// This is the development configuration.
|
||||||
|
// It is focused on developer experience and fast rebuilds.
|
||||||
|
// The production configuration is different and lives in a separate file.
|
||||||
|
module.exports = {
|
||||||
|
mode: 'development',
|
||||||
|
// You may want 'eval' instead if you prefer to see the compiled output in DevTools.
|
||||||
|
// See the discussion in https://github.com/facebookincubator/create-react-app/issues/343.
|
||||||
|
devtool: 'cheap-module-source-map',
|
||||||
|
// These are the "entry points" to our application.
|
||||||
|
// This means they will be the "root" imports that are included in JS bundle.
|
||||||
|
// The first two entry points enable "hot" CSS and auto-refreshes for JS.
|
||||||
|
entry: [
|
||||||
|
// We ship a few polyfills by default:
|
||||||
|
require.resolve('./polyfills'),
|
||||||
|
// Include an alternative client for WebpackDevServer. A client's job is to
|
||||||
|
// connect to WebpackDevServer by a socket and get notified about changes.
|
||||||
|
// When you save a file, the client will either apply hot updates (in case
|
||||||
|
// of CSS changes), or refresh the page (in case of JS changes). When you
|
||||||
|
// make a syntax error, this client will display a syntax error overlay.
|
||||||
|
// Note: instead of the default WebpackDevServer client, we use a custom one
|
||||||
|
// to bring better experience for Create React App users. You can replace
|
||||||
|
// the line below with these two lines if you prefer the stock client:
|
||||||
|
// require.resolve('webpack-dev-server/client') + '?/',
|
||||||
|
// require.resolve('webpack/hot/dev-server'),
|
||||||
|
require.resolve('react-dev-utils/webpackHotDevClient'),
|
||||||
|
// Finally, this is your app's code:
|
||||||
|
paths.appIndexJs,
|
||||||
|
// We include the app code last so that if there is a runtime error during
|
||||||
|
// initialization, it doesn't blow up the WebpackDevServer client, and
|
||||||
|
// changing JS code would still trigger a refresh.
|
||||||
|
],
|
||||||
|
output: {
|
||||||
|
// Add /* filename */ comments to generated require()s in the output.
|
||||||
|
pathinfo: true,
|
||||||
|
// This does not produce a real file. It's just the virtual path that is
|
||||||
|
// served by WebpackDevServer in development. This is the JS bundle
|
||||||
|
// containing code from all our entry points, and the Webpack runtime.
|
||||||
|
filename: 'static/js/bundle.js',
|
||||||
|
// There are also additional JS chunk files if you use code splitting.
|
||||||
|
chunkFilename: 'static/js/[name].chunk.js',
|
||||||
|
// This is the URL that app is served from. We use "/" in development.
|
||||||
|
publicPath: publicPath,
|
||||||
|
// Point sourcemap entries to original disk location (format as URL on Windows)
|
||||||
|
devtoolModuleFilenameTemplate: info =>
|
||||||
|
path.resolve(info.absoluteResourcePath).replace(/\\/g, '/'),
|
||||||
|
},
|
||||||
|
resolve: {
|
||||||
|
// This allows you to set a fallback for where Webpack should look for modules.
|
||||||
|
// We placed these paths second because we want `node_modules` to "win"
|
||||||
|
// if there are any conflicts. This matches Node resolution mechanism.
|
||||||
|
// https://github.com/facebookincubator/create-react-app/issues/253
|
||||||
|
modules: ['node_modules', paths.appNodeModules].concat(
|
||||||
|
// It is guaranteed to exist because we tweak it in `env.js`
|
||||||
|
process.env.NODE_PATH.split(path.delimiter).filter(Boolean)
|
||||||
|
),
|
||||||
|
// These are the reasonable defaults supported by the Node ecosystem.
|
||||||
|
// We also include JSX as a common component filename extension to support
|
||||||
|
// some tools, although we do not recommend using it, see:
|
||||||
|
// https://github.com/facebookincubator/create-react-app/issues/290
|
||||||
|
// `web` extension prefixes have been added for better support
|
||||||
|
// for React Native Web.
|
||||||
|
extensions: ['.web.js', '.mjs', '.js', '.json', '.web.jsx', '.jsx'],
|
||||||
|
alias: {
|
||||||
|
|
||||||
|
// Support React Native Web
|
||||||
|
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
|
||||||
|
'react-native': 'react-native-web',
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
// Prevents users from importing files from outside of src/ (or node_modules/).
|
||||||
|
// This often causes confusion because we only process files within src/ with babel.
|
||||||
|
// To fix this, we prevent you from importing files out of src/ -- if you'd like to,
|
||||||
|
// please link the files into your node_modules/ and let module-resolution kick in.
|
||||||
|
// Make sure your source files are compiled, as they will not be processed in any way.
|
||||||
|
new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson]),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
module: {
|
||||||
|
strictExportPresence: true,
|
||||||
|
rules: [
|
||||||
|
// TODO: Disable require.ensure as it's not a standard language feature.
|
||||||
|
// We are waiting for https://github.com/facebookincubator/create-react-app/issues/2176.
|
||||||
|
// { parser: { requireEnsure: false } },
|
||||||
|
|
||||||
|
// First, run the linter.
|
||||||
|
// It's important to do this before Babel processes the JS.
|
||||||
|
{
|
||||||
|
test: /\.(js|jsx|mjs)$/,
|
||||||
|
enforce: 'pre',
|
||||||
|
use: [
|
||||||
|
{
|
||||||
|
options: {
|
||||||
|
formatter: eslintFormatter,
|
||||||
|
eslintPath: require.resolve('eslint'),
|
||||||
|
|
||||||
|
},
|
||||||
|
loader: require.resolve('eslint-loader'),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
include: paths.appSrc,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// "oneOf" will traverse all following loaders until one will
|
||||||
|
// match the requirements. When no loader matches it will fall
|
||||||
|
// back to the "file" loader at the end of the loader list.
|
||||||
|
oneOf: [
|
||||||
|
// "url" loader works like "file" loader except that it embeds assets
|
||||||
|
// smaller than specified limit in bytes as data URLs to avoid requests.
|
||||||
|
// A missing `test` is equivalent to a match.
|
||||||
|
{
|
||||||
|
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
|
||||||
|
loader: require.resolve('url-loader'),
|
||||||
|
options: {
|
||||||
|
limit: 10000,
|
||||||
|
name: 'static/media/[name].[hash:8].[ext]',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// Process JS with Babel.
|
||||||
|
{
|
||||||
|
test: /\.(js|jsx|mjs)$/,
|
||||||
|
include: paths.appSrc,
|
||||||
|
loader: require.resolve('babel-loader'),
|
||||||
|
options: {
|
||||||
|
|
||||||
|
// This is a feature of `babel-loader` for webpack (not Babel itself).
|
||||||
|
// It enables caching results in ./node_modules/.cache/babel-loader/
|
||||||
|
// directory for faster rebuilds.
|
||||||
|
cacheDirectory: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// "postcss" loader applies autoprefixer to our CSS.
|
||||||
|
// "css" loader resolves paths in CSS and adds assets as dependencies.
|
||||||
|
// "style" loader turns CSS into JS modules that inject <style> tags.
|
||||||
|
// In production, we use a plugin to extract that CSS to a file, but
|
||||||
|
// in development "style" loader enables hot editing of CSS.
|
||||||
|
{
|
||||||
|
test: /\.css$/,
|
||||||
|
use: [
|
||||||
|
require.resolve('style-loader'),
|
||||||
|
{
|
||||||
|
loader: require.resolve('css-loader'),
|
||||||
|
options: {
|
||||||
|
importLoaders: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
loader: require.resolve('postcss-loader'),
|
||||||
|
options: {
|
||||||
|
// Necessary for external CSS imports to work
|
||||||
|
// https://github.com/facebookincubator/create-react-app/issues/2677
|
||||||
|
ident: 'postcss',
|
||||||
|
plugins: () => [
|
||||||
|
require('postcss-flexbugs-fixes'),
|
||||||
|
autoprefixer({
|
||||||
|
browsers: [
|
||||||
|
'>1%',
|
||||||
|
'last 4 versions',
|
||||||
|
'Firefox ESR',
|
||||||
|
'not ie < 9', // React doesn't support IE8 anyway
|
||||||
|
],
|
||||||
|
flexbox: 'no-2009',
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
// "file" loader makes sure those assets get served by WebpackDevServer.
|
||||||
|
// When you `import` an asset, you get its (virtual) filename.
|
||||||
|
// In production, they would get copied to the `build` folder.
|
||||||
|
// This loader doesn't use a "test" so it will catch all modules
|
||||||
|
// that fall through the other loaders.
|
||||||
|
{
|
||||||
|
// Exclude `js` files to keep "css" loader working as it injects
|
||||||
|
// its runtime that would otherwise processed through "file" loader.
|
||||||
|
// Also exclude `html` and `json` extensions so they get processed
|
||||||
|
// by webpacks internal loaders.
|
||||||
|
exclude: [/\.(js|jsx|mjs)$/, /\.html$/, /\.json$/],
|
||||||
|
loader: require.resolve('file-loader'),
|
||||||
|
options: {
|
||||||
|
name: 'static/media/[name].[hash:8].[ext]',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
// ** STOP ** Are you adding a new loader?
|
||||||
|
// Make sure to add the new loader(s) before the "file" loader.
|
||||||
|
],
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
// Makes some environment variables available in index.html.
|
||||||
|
// The public URL is available as %PUBLIC_URL% in index.html, e.g.:
|
||||||
|
// <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
|
||||||
|
// In development, this will be an empty string.
|
||||||
|
// new InterpolateHtmlPlugin(env.raw),
|
||||||
|
// Generates an `index.html` file with the <script> injected.
|
||||||
|
new HtmlWebpackPlugin({
|
||||||
|
inject: true,
|
||||||
|
template: paths.appHtml,
|
||||||
|
}),
|
||||||
|
new InterpolateHtmlPlugin(HtmlWebpackPlugin, env.raw),
|
||||||
|
// Add module names to factory functions so they appear in browser profiler.
|
||||||
|
new webpack.NamedModulesPlugin(),
|
||||||
|
// Makes some environment variables available to the JS code, for example:
|
||||||
|
// if (process.env.NODE_ENV === 'development') { ... }. See `./env.js`.
|
||||||
|
new webpack.DefinePlugin(env.stringified),
|
||||||
|
// This is necessary to emit hot updates (currently CSS only):
|
||||||
|
new webpack.HotModuleReplacementPlugin(),
|
||||||
|
// Watcher doesn't work well if you mistype casing in a path so we use
|
||||||
|
// a plugin that prints an error when you attempt to do this.
|
||||||
|
// See https://github.com/facebookincubator/create-react-app/issues/240
|
||||||
|
new CaseSensitivePathsPlugin(),
|
||||||
|
// If you require a missing module and then `npm install` it, you still have
|
||||||
|
// to restart the development server for Webpack to discover it. This plugin
|
||||||
|
// makes the discovery automatic so you don't have to restart.
|
||||||
|
// See https://github.com/facebookincubator/create-react-app/issues/186
|
||||||
|
new WatchMissingNodeModulesPlugin(paths.appNodeModules),
|
||||||
|
// Moment.js is an extremely popular library that bundles large locale files
|
||||||
|
// by default due to how Webpack interprets its code. This is a practical
|
||||||
|
// solution that requires the user to opt into importing specific locales.
|
||||||
|
// https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
|
||||||
|
// You can remove this if you don't use Moment.js:
|
||||||
|
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
|
||||||
|
],
|
||||||
|
// Some libraries import Node modules but don't use them in the browser.
|
||||||
|
// Tell Webpack to provide empty mocks for them so importing them works.
|
||||||
|
node: {
|
||||||
|
dgram: 'empty',
|
||||||
|
fs: 'empty',
|
||||||
|
net: 'empty',
|
||||||
|
tls: 'empty',
|
||||||
|
child_process: 'empty',
|
||||||
|
},
|
||||||
|
// Turn off performance hints during development because we don't do any
|
||||||
|
// splitting or minification in interest of speed. These warnings become
|
||||||
|
// cumbersome.
|
||||||
|
performance: {
|
||||||
|
hints: false,
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -0,0 +1,346 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const autoprefixer = require('autoprefixer');
|
||||||
|
const path = require('path');
|
||||||
|
const webpack = require('webpack');
|
||||||
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||||
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
||||||
|
const ManifestPlugin = require('webpack-manifest-plugin');
|
||||||
|
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
|
||||||
|
const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin');
|
||||||
|
const eslintFormatter = require('react-dev-utils/eslintFormatter');
|
||||||
|
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
|
||||||
|
const paths = require('./paths');
|
||||||
|
const getClientEnvironment = require('./env');
|
||||||
|
|
||||||
|
// Webpack uses `publicPath` to determine where the app is being served from.
|
||||||
|
// It requires a trailing slash, or the file assets will get an incorrect path.
|
||||||
|
const publicPath = paths.servedPath;
|
||||||
|
// Some apps do not use client-side routing with pushState.
|
||||||
|
// For these, "homepage" can be set to "." to enable relative asset paths.
|
||||||
|
const shouldUseRelativeAssetPaths = publicPath === './';
|
||||||
|
// Source maps are resource heavy and can cause out of memory issue for large source files.
|
||||||
|
const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false';
|
||||||
|
// `publicUrl` is just like `publicPath`, but we will provide it to our app
|
||||||
|
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
|
||||||
|
// Omit trailing slash as %PUBLIC_URL%/xyz looks better than %PUBLIC_URL%xyz.
|
||||||
|
const publicUrl = publicPath.slice(0, -1);
|
||||||
|
// Get environment variables to inject into our app.
|
||||||
|
const env = getClientEnvironment(publicUrl);
|
||||||
|
|
||||||
|
// Assert this just to be safe.
|
||||||
|
// Development builds of React are slow and not intended for production.
|
||||||
|
if (env.stringified['process.env'].NODE_ENV !== '"production"') {
|
||||||
|
throw new Error('Production builds must have NODE_ENV=production.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Note: defined here because it will be used more than once.
|
||||||
|
const cssFilename = 'static/css/[name].css';
|
||||||
|
|
||||||
|
// ExtractTextPlugin expects the build output to be flat.
|
||||||
|
// (See https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/27)
|
||||||
|
// However, our output is structured with css, js and media folders.
|
||||||
|
// To have this structure working with relative paths, we have to use custom options.
|
||||||
|
const extractTextPluginOptions = shouldUseRelativeAssetPaths
|
||||||
|
? // Making sure that the publicPath goes back to to build folder.
|
||||||
|
{ publicPath: Array(cssFilename.split('/').length).join('../') }
|
||||||
|
: {};
|
||||||
|
|
||||||
|
// This is the production configuration.
|
||||||
|
// It compiles slowly and is focused on producing a fast and minimal bundle.
|
||||||
|
// The development configuration is different and lives in a separate file.
|
||||||
|
module.exports = {
|
||||||
|
mode: 'production',
|
||||||
|
// Don't attempt to continue if there are any errors.
|
||||||
|
bail: true,
|
||||||
|
// We generate sourcemaps in production. This is slow but gives good results.
|
||||||
|
// You can exclude the *.map files from the build during deployment.
|
||||||
|
devtool: shouldUseSourceMap ? 'source-map' : false,
|
||||||
|
// In production, we only want to load the polyfills and the app code.
|
||||||
|
entry: {
|
||||||
|
app: [require.resolve('./polyfills'), paths.appIndexJs],
|
||||||
|
content: [require.resolve('./polyfills'), './src/index.js'],
|
||||||
|
},
|
||||||
|
optimization: {
|
||||||
|
minimize: false, //Update this to true or false
|
||||||
|
},
|
||||||
|
output: {
|
||||||
|
// The build folder.
|
||||||
|
path: paths.appBuild,
|
||||||
|
// Generated JS file names (with nested folders).
|
||||||
|
// There will be one main bundle, and one file per asynchronous chunk.
|
||||||
|
// We don't currently advertise code splitting but Webpack supports it.
|
||||||
|
filename: 'static/js/[name].js',
|
||||||
|
chunkFilename: 'static/js/[name].[chunkhash:8].chunk.js',
|
||||||
|
// We inferred the "public path" (such as / or /my-project) from homepage.
|
||||||
|
publicPath: publicPath,
|
||||||
|
// Point sourcemap entries to original disk location (format as URL on Windows)
|
||||||
|
devtoolModuleFilenameTemplate: info =>
|
||||||
|
path.relative(paths.appSrc, info.absoluteResourcePath).replace(/\\/g, '/'),
|
||||||
|
},
|
||||||
|
resolve: {
|
||||||
|
// This allows you to set a fallback for where Webpack should look for modules.
|
||||||
|
// We placed these paths second because we want `node_modules` to "win"
|
||||||
|
// if there are any conflicts. This matches Node resolution mechanism.
|
||||||
|
// https://github.com/facebookincubator/create-react-app/issues/253
|
||||||
|
modules: ['node_modules', paths.appNodeModules].concat(
|
||||||
|
// It is guaranteed to exist because we tweak it in `env.js`
|
||||||
|
process.env.NODE_PATH.split(path.delimiter).filter(Boolean)
|
||||||
|
),
|
||||||
|
// These are the reasonable defaults supported by the Node ecosystem.
|
||||||
|
// We also include JSX as a common component filename extension to support
|
||||||
|
// some tools, although we do not recommend using it, see:
|
||||||
|
// https://github.com/facebookincubator/create-react-app/issues/290
|
||||||
|
// `web` extension prefixes have been added for better support
|
||||||
|
// for React Native Web.
|
||||||
|
extensions: ['.web.js', '.mjs', '.js', '.json', '.web.jsx', '.jsx'],
|
||||||
|
alias: {
|
||||||
|
// Support React Native Web
|
||||||
|
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
|
||||||
|
'react-native': 'react-native-web',
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
// Prevents users from importing files from outside of src/ (or node_modules/).
|
||||||
|
// This often causes confusion because we only process files within src/ with babel.
|
||||||
|
// To fix this, we prevent you from importing files out of src/ -- if you'd like to,
|
||||||
|
// please link the files into your node_modules/ and let module-resolution kick in.
|
||||||
|
// Make sure your source files are compiled, as they will not be processed in any way.
|
||||||
|
new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson]),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
module: {
|
||||||
|
strictExportPresence: true,
|
||||||
|
rules: [
|
||||||
|
// TODO: Disable require.ensure as it's not a standard language feature.
|
||||||
|
// We are waiting for https://github.com/facebookincubator/create-react-app/issues/2176.
|
||||||
|
// { parser: { requireEnsure: false } },
|
||||||
|
|
||||||
|
// First, run the linter.
|
||||||
|
// It's important to do this before Babel processes the JS.
|
||||||
|
{
|
||||||
|
test: /\.(js|jsx|mjs)$/,
|
||||||
|
enforce: 'pre',
|
||||||
|
use: [
|
||||||
|
{
|
||||||
|
options: {
|
||||||
|
formatter: eslintFormatter,
|
||||||
|
eslintPath: require.resolve('eslint'),
|
||||||
|
},
|
||||||
|
loader: require.resolve('eslint-loader'),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
include: paths.appSrc,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// "oneOf" will traverse all following loaders until one will
|
||||||
|
// match the requirements. When no loader matches it will fall
|
||||||
|
// back to the "file" loader at the end of the loader list.
|
||||||
|
oneOf: [
|
||||||
|
// "url" loader works just like "file" loader but it also embeds
|
||||||
|
// assets smaller than specified size as data URLs to avoid requests.
|
||||||
|
{
|
||||||
|
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
|
||||||
|
loader: require.resolve('url-loader'),
|
||||||
|
options: {
|
||||||
|
limit: 10000,
|
||||||
|
name: 'static/media/[name].[hash:8].[ext]',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// Process JS with Babel.
|
||||||
|
{
|
||||||
|
test: /\.(js|jsx|mjs)$/,
|
||||||
|
include: paths.appSrc,
|
||||||
|
loader: require.resolve('babel-loader'),
|
||||||
|
options: {
|
||||||
|
compact: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// The notation here is somewhat confusing.
|
||||||
|
// "postcss" loader applies autoprefixer to our CSS.
|
||||||
|
// "css" loader resolves paths in CSS and adds assets as dependencies.
|
||||||
|
// "style" loader normally turns CSS into JS modules injecting <style>,
|
||||||
|
// but unlike in development configuration, we do something different.
|
||||||
|
// `ExtractTextPlugin` first applies the "postcss" and "css" loaders
|
||||||
|
// (second argument), then grabs the result CSS and puts it into a
|
||||||
|
// separate file in our build process. This way we actually ship
|
||||||
|
// a single CSS file in production instead of JS code injecting <style>
|
||||||
|
// tags. If you use code splitting, however, any async bundles will still
|
||||||
|
// use the "style" loader inside the async code so CSS from them won't be
|
||||||
|
// in the main CSS file.
|
||||||
|
{
|
||||||
|
test: /\.css$/,
|
||||||
|
use: [{ loader: MiniCssExtractPlugin.loader }, 'css-loader'],
|
||||||
|
// loader: ExtractTextPlugin.extract(
|
||||||
|
// Object.assign(
|
||||||
|
// {
|
||||||
|
// fallback: {
|
||||||
|
// loader: require.resolve('style-loader'),
|
||||||
|
// options: {
|
||||||
|
// hmr: false,
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// use: [
|
||||||
|
// {
|
||||||
|
// loader: require.resolve('css-loader'),
|
||||||
|
// options: {
|
||||||
|
// importLoaders: 1,
|
||||||
|
// minimize: true,
|
||||||
|
// sourceMap: shouldUseSourceMap,
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// loader: require.resolve('postcss-loader'),
|
||||||
|
// options: {
|
||||||
|
// // Necessary for external CSS imports to work
|
||||||
|
// // https://github.com/facebookincubator/create-react-app/issues/2677
|
||||||
|
// ident: 'postcss',
|
||||||
|
// plugins: () => [
|
||||||
|
// require('postcss-flexbugs-fixes'),
|
||||||
|
// autoprefixer({
|
||||||
|
// browsers: [
|
||||||
|
// '>1%',
|
||||||
|
// 'last 4 versions',
|
||||||
|
// 'Firefox ESR',
|
||||||
|
// 'not ie < 9', // React doesn't support IE8 anyway
|
||||||
|
// ],
|
||||||
|
// flexbox: 'no-2009',
|
||||||
|
// }),
|
||||||
|
// ],
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// ],
|
||||||
|
// },
|
||||||
|
// extractTextPluginOptions
|
||||||
|
// )
|
||||||
|
// ),
|
||||||
|
// Note: this won't work without `new ExtractTextPlugin()` in `plugins`.
|
||||||
|
},
|
||||||
|
// "file" loader makes sure assets end up in the `build` folder.
|
||||||
|
// When you `import` an asset, you get its filename.
|
||||||
|
// This loader doesn't use a "test" so it will catch all modules
|
||||||
|
// that fall through the other loaders.
|
||||||
|
{
|
||||||
|
loader: require.resolve('file-loader'),
|
||||||
|
// Exclude `js` files to keep "css" loader working as it injects
|
||||||
|
// it's runtime that would otherwise processed through "file" loader.
|
||||||
|
// Also exclude `html` and `json` extensions so they get processed
|
||||||
|
// by webpacks internal loaders.
|
||||||
|
exclude: [/\.(js|jsx|mjs)$/, /\.html$/, /\.json$/],
|
||||||
|
options: {
|
||||||
|
name: 'static/media/[name].[hash:8].[ext]',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// ** STOP ** Are you adding a new loader?
|
||||||
|
// Make sure to add the new loader(s) before the "file" loader.
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
// Makes some environment variables available in index.html.
|
||||||
|
// The public URL is available as %PUBLIC_URL% in index.html, e.g.:
|
||||||
|
// <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
|
||||||
|
// In production, it will be an empty string unless you specify "homepage"
|
||||||
|
// in `package.json`, in which case it will be the pathname of that URL.
|
||||||
|
// new InterpolateHtmlPlugin(env.raw),
|
||||||
|
// Generates an `index.html` file with the <script> injected.
|
||||||
|
new HtmlWebpackPlugin({
|
||||||
|
inject: true,
|
||||||
|
template: paths.appHtml,
|
||||||
|
minify: {
|
||||||
|
removeComments: true,
|
||||||
|
collapseWhitespace: true,
|
||||||
|
removeRedundantAttributes: true,
|
||||||
|
useShortDoctype: true,
|
||||||
|
removeEmptyAttributes: true,
|
||||||
|
removeStyleLinkTypeAttributes: true,
|
||||||
|
keepClosingSlash: true,
|
||||||
|
minifyJS: true,
|
||||||
|
minifyCSS: true,
|
||||||
|
minifyURLs: true,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new InterpolateHtmlPlugin(HtmlWebpackPlugin, env.raw),
|
||||||
|
// Makes some environment variables available to the JS code, for example:
|
||||||
|
// if (process.env.NODE_ENV === 'production') { ... }. See `./env.js`.
|
||||||
|
// It is absolutely essential that NODE_ENV was set to production here.
|
||||||
|
// Otherwise React will be compiled in the very slow development mode.
|
||||||
|
new webpack.DefinePlugin(env.stringified),
|
||||||
|
// Minify the code.
|
||||||
|
// new webpack.optimize.UglifyJsPlugin({
|
||||||
|
// compress: {
|
||||||
|
// warnings: false,
|
||||||
|
// // Disabled because of an issue with Uglify breaking seemingly valid code:
|
||||||
|
// // https://github.com/facebookincubator/create-react-app/issues/2376
|
||||||
|
// // Pending further investigation:
|
||||||
|
// // https://github.com/mishoo/UglifyJS2/issues/2011
|
||||||
|
// comparisons: false,
|
||||||
|
// },
|
||||||
|
// mangle: {
|
||||||
|
// safari10: true,
|
||||||
|
// },
|
||||||
|
// output: {
|
||||||
|
// comments: false,
|
||||||
|
// // Turned on because emoji and regex is not minified properly using default
|
||||||
|
// // https://github.com/facebookincubator/create-react-app/issues/2488
|
||||||
|
// ascii_only: true,
|
||||||
|
// },
|
||||||
|
// sourceMap: shouldUseSourceMap,
|
||||||
|
// }),
|
||||||
|
// Note: this won't work without ExtractTextPlugin.extract(..) in `loaders`.
|
||||||
|
new MiniCssExtractPlugin({
|
||||||
|
filename: cssFilename,
|
||||||
|
}),
|
||||||
|
// Generate a manifest file which contains a mapping of all asset filenames
|
||||||
|
// to their corresponding output file so that tools can pick it up without
|
||||||
|
// having to parse `index.html`.
|
||||||
|
new ManifestPlugin({
|
||||||
|
fileName: 'asset-manifest.json',
|
||||||
|
}),
|
||||||
|
// Generate a service worker script that will precache, and keep up to date,
|
||||||
|
// the HTML & assets that are part of the Webpack build.
|
||||||
|
new SWPrecacheWebpackPlugin({
|
||||||
|
// By default, a cache-busting query parameter is appended to requests
|
||||||
|
// used to populate the caches, to ensure the responses are fresh.
|
||||||
|
// If a URL is already hashed by Webpack, then there is no concern
|
||||||
|
// about it being stale, and the cache-busting can be skipped.
|
||||||
|
dontCacheBustUrlsMatching: /\.\w{8}\./,
|
||||||
|
filename: 'service-worker.js',
|
||||||
|
logger(message) {
|
||||||
|
if (message.indexOf('Total precache size is') === 0) {
|
||||||
|
// This message occurs for every build and is a bit too noisy.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (message.indexOf('Skipping static resource') === 0) {
|
||||||
|
// This message obscures real errors so we ignore it.
|
||||||
|
// https://github.com/facebookincubator/create-react-app/issues/2612
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log(message);
|
||||||
|
},
|
||||||
|
minify: true,
|
||||||
|
// For unknown URLs, fallback to the index page
|
||||||
|
navigateFallback: publicUrl + '/index.html',
|
||||||
|
// Ignores URLs starting from /__ (useful for Firebase):
|
||||||
|
// https://github.com/facebookincubator/create-react-app/issues/2237#issuecomment-302693219
|
||||||
|
navigateFallbackWhitelist: [/^(?!\/__).*/],
|
||||||
|
// Don't precache sourcemaps (they're large) and build asset manifest:
|
||||||
|
staticFileGlobsIgnorePatterns: [/\.map$/, /asset-manifest\.json$/],
|
||||||
|
}),
|
||||||
|
// Moment.js is an extremely popular library that bundles large locale files
|
||||||
|
// by default due to how Webpack interprets its code. This is a practical
|
||||||
|
// solution that requires the user to opt into importing specific locales.
|
||||||
|
// https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
|
||||||
|
// You can remove this if you don't use Moment.js:
|
||||||
|
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
|
||||||
|
],
|
||||||
|
// Some libraries import Node modules but don't use them in the browser.
|
||||||
|
// Tell Webpack to provide empty mocks for them so importing them works.
|
||||||
|
node: {
|
||||||
|
dgram: 'empty',
|
||||||
|
fs: 'empty',
|
||||||
|
net: 'empty',
|
||||||
|
tls: 'empty',
|
||||||
|
child_process: 'empty',
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const errorOverlayMiddleware = require('react-dev-utils/errorOverlayMiddleware');
|
||||||
|
const noopServiceWorkerMiddleware = require('react-dev-utils/noopServiceWorkerMiddleware');
|
||||||
|
const ignoredFiles = require('react-dev-utils/ignoredFiles');
|
||||||
|
const config = require('./webpack.config.dev');
|
||||||
|
const paths = require('./paths');
|
||||||
|
|
||||||
|
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
|
||||||
|
const host = process.env.HOST || '0.0.0.0';
|
||||||
|
|
||||||
|
module.exports = function(proxy, allowedHost) {
|
||||||
|
return {
|
||||||
|
// WebpackDevServer 2.4.3 introduced a security fix that prevents remote
|
||||||
|
// websites from potentially accessing local content through DNS rebinding:
|
||||||
|
// https://github.com/webpack/webpack-dev-server/issues/887
|
||||||
|
// https://medium.com/webpack/webpack-dev-server-middleware-security-issues-1489d950874a
|
||||||
|
// However, it made several existing use cases such as development in cloud
|
||||||
|
// environment or subdomains in development significantly more complicated:
|
||||||
|
// https://github.com/facebookincubator/create-react-app/issues/2271
|
||||||
|
// https://github.com/facebookincubator/create-react-app/issues/2233
|
||||||
|
// While we're investigating better solutions, for now we will take a
|
||||||
|
// compromise. Since our WDS configuration only serves files in the `public`
|
||||||
|
// folder we won't consider accessing them a vulnerability. However, if you
|
||||||
|
// use the `proxy` feature, it gets more dangerous because it can expose
|
||||||
|
// remote code execution vulnerabilities in backends like Django and Rails.
|
||||||
|
// So we will disable the host check normally, but enable it if you have
|
||||||
|
// specified the `proxy` setting. Finally, we let you override it if you
|
||||||
|
// really know what you're doing with a special environment variable.
|
||||||
|
disableHostCheck:
|
||||||
|
!proxy || process.env.DANGEROUSLY_DISABLE_HOST_CHECK === 'true',
|
||||||
|
// Enable gzip compression of generated files.
|
||||||
|
compress: true,
|
||||||
|
// Silence WebpackDevServer's own logs since they're generally not useful.
|
||||||
|
// It will still show compile warnings and errors with this setting.
|
||||||
|
clientLogLevel: 'none',
|
||||||
|
// By default WebpackDevServer serves physical files from current directory
|
||||||
|
// in addition to all the virtual build products that it serves from memory.
|
||||||
|
// This is confusing because those files won’t automatically be available in
|
||||||
|
// production build folder unless we copy them. However, copying the whole
|
||||||
|
// project directory is dangerous because we may expose sensitive files.
|
||||||
|
// Instead, we establish a convention that only files in `public` directory
|
||||||
|
// get served. Our build script will copy `public` into the `build` folder.
|
||||||
|
// In `index.html`, you can get URL of `public` folder with %PUBLIC_URL%:
|
||||||
|
// <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
|
||||||
|
// In JavaScript code, you can access it with `process.env.PUBLIC_URL`.
|
||||||
|
// Note that we only recommend to use `public` folder as an escape hatch
|
||||||
|
// for files like `favicon.ico`, `manifest.json`, and libraries that are
|
||||||
|
// for some reason broken when imported through Webpack. If you just want to
|
||||||
|
// use an image, put it in `src` and `import` it from JavaScript instead.
|
||||||
|
contentBase: paths.appPublic,
|
||||||
|
// By default files from `contentBase` will not trigger a page reload.
|
||||||
|
watchContentBase: true,
|
||||||
|
// Enable hot reloading server. It will provide /sockjs-node/ endpoint
|
||||||
|
// for the WebpackDevServer client so it can learn when the files were
|
||||||
|
// updated. The WebpackDevServer client is included as an entry point
|
||||||
|
// in the Webpack development configuration. Note that only changes
|
||||||
|
// to CSS are currently hot reloaded. JS changes will refresh the browser.
|
||||||
|
hot: true,
|
||||||
|
// It is important to tell WebpackDevServer to use the same "root" path
|
||||||
|
// as we specified in the config. In development, we always serve from /.
|
||||||
|
publicPath: config.output.publicPath,
|
||||||
|
// WebpackDevServer is noisy by default so we emit custom message instead
|
||||||
|
// by listening to the compiler events with `compiler.plugin` calls above.
|
||||||
|
quiet: true,
|
||||||
|
// Reportedly, this avoids CPU overload on some systems.
|
||||||
|
// https://github.com/facebookincubator/create-react-app/issues/293
|
||||||
|
// src/node_modules is not ignored to support absolute imports
|
||||||
|
// https://github.com/facebookincubator/create-react-app/issues/1065
|
||||||
|
watchOptions: {
|
||||||
|
ignored: ignoredFiles(paths.appSrc),
|
||||||
|
},
|
||||||
|
// Enable HTTPS if the HTTPS environment variable is set to 'true'
|
||||||
|
https: protocol === 'https',
|
||||||
|
host: host,
|
||||||
|
overlay: false,
|
||||||
|
historyApiFallback: {
|
||||||
|
// Paths with dots should still use the history fallback.
|
||||||
|
// See https://github.com/facebookincubator/create-react-app/issues/387.
|
||||||
|
disableDotRule: true,
|
||||||
|
},
|
||||||
|
public: allowedHost,
|
||||||
|
proxy,
|
||||||
|
before(app) {
|
||||||
|
// This lets us open files from the runtime error overlay.
|
||||||
|
app.use(errorOverlayMiddleware());
|
||||||
|
// This service worker file is effectively a 'no-op' that will reset any
|
||||||
|
// previous service worker registered for the same host:port combination.
|
||||||
|
// We do this in development to avoid hitting the production cache if
|
||||||
|
// it used the same host and port.
|
||||||
|
// https://github.com/facebookincubator/create-react-app/issues/2272#issuecomment-302832432
|
||||||
|
app.use(noopServiceWorkerMiddleware());
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
{
|
||||||
|
"name": "watch-party-crx",
|
||||||
|
"version": "1.2.0",
|
||||||
|
"private": true,
|
||||||
|
"dependencies": {
|
||||||
|
"@giphy/js-fetch-api": "^1.5.8",
|
||||||
|
"@giphy/react-components": "^1.0.4",
|
||||||
|
"@material-ui/core": "^4.9.10",
|
||||||
|
"@material-ui/icons": "^4.9.1",
|
||||||
|
"autoprefixer": "7.1.6",
|
||||||
|
"babel-core": "6.26.3",
|
||||||
|
"babel-eslint": "10.x",
|
||||||
|
"babel-jest": "20.0.3",
|
||||||
|
"babel-preset-react-app": "^9.0.1",
|
||||||
|
"babel-runtime": "6.26.0",
|
||||||
|
"case-sensitive-paths-webpack-plugin": "2.1.1",
|
||||||
|
"chalk": "1.1.3",
|
||||||
|
"css-loader": "0.28.7",
|
||||||
|
"dotenv": "4.0.0",
|
||||||
|
"dotenv-expand": "4.2.0",
|
||||||
|
"eslint": "6.x",
|
||||||
|
"eslint-config-react-app": "^5.0.1",
|
||||||
|
"eslint-loader": "2.2.1",
|
||||||
|
"eslint-plugin-flowtype": "3.x",
|
||||||
|
"eslint-plugin-import": "2.x",
|
||||||
|
"eslint-plugin-jsx-a11y": "6.x",
|
||||||
|
"eslint-plugin-react": "7.x",
|
||||||
|
"file-loader": "4.2.0",
|
||||||
|
"firebase": "^7.14.0",
|
||||||
|
"fs-extra": "3.0.1",
|
||||||
|
"html-webpack-plugin": "^4.0.0-beta.8",
|
||||||
|
"jest": "20.0.4",
|
||||||
|
"object-assign": "4.1.1",
|
||||||
|
"postcss-flexbugs-fixes": "3.2.0",
|
||||||
|
"postcss-loader": "2.0.8",
|
||||||
|
"promise": "8.0.1",
|
||||||
|
"prop-types": "^15.7.2",
|
||||||
|
"raf": "3.4.0",
|
||||||
|
"react": "^16.4.1",
|
||||||
|
"react-chat-ui": "^0.3.2",
|
||||||
|
"react-dev-utils": "^9.0.0-next.68",
|
||||||
|
"react-dom": "^16.4.1",
|
||||||
|
"react-frame-component": "^4.0.0",
|
||||||
|
"resolve": "1.6.0",
|
||||||
|
"route-lite": "^0.3.0",
|
||||||
|
"style-loader": "0.19.0",
|
||||||
|
"sw-precache-webpack-plugin": "^0.11.5",
|
||||||
|
"url-loader": "0.6.2",
|
||||||
|
"webpack-dev-server": ">=3.1.11",
|
||||||
|
"webpack-manifest-plugin": "2.0.4",
|
||||||
|
"whatwg-fetch": "2.0.3"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"start": "node scripts/start.js",
|
||||||
|
"build": "node scripts/build.js",
|
||||||
|
"test": "node scripts/test.js --env=jsdom"
|
||||||
|
},
|
||||||
|
"jest": {
|
||||||
|
"collectCoverageFrom": [
|
||||||
|
"src/**/*.{js,jsx,mjs}"
|
||||||
|
],
|
||||||
|
"setupFiles": [
|
||||||
|
"<rootDir>/config/polyfills.js"
|
||||||
|
],
|
||||||
|
"testMatch": [
|
||||||
|
"<rootDir>/src/**/__tests__/**/*.{js,jsx,mjs}",
|
||||||
|
"<rootDir>/src/**/?(*.)(spec|test).{js,jsx,mjs}"
|
||||||
|
],
|
||||||
|
"testEnvironment": "node",
|
||||||
|
"testURL": "http://localhost",
|
||||||
|
"transform": {
|
||||||
|
"^.+\\.(js|jsx|mjs)$": "<rootDir>/node_modules/babel-jest",
|
||||||
|
"^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
|
||||||
|
"^(?!.*\\.(js|jsx|mjs|css|json)$)": "<rootDir>/config/jest/fileTransform.js"
|
||||||
|
},
|
||||||
|
"transformIgnorePatterns": [
|
||||||
|
"[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs)$"
|
||||||
|
],
|
||||||
|
"moduleNameMapper": {
|
||||||
|
"^react-native$": "react-native-web"
|
||||||
|
},
|
||||||
|
"moduleFileExtensions": [
|
||||||
|
"web.js",
|
||||||
|
"js",
|
||||||
|
"json",
|
||||||
|
"web.jsx",
|
||||||
|
"jsx",
|
||||||
|
"node",
|
||||||
|
"mjs"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"babel": {
|
||||||
|
"presets": [
|
||||||
|
"react-app",
|
||||||
|
"@babel/preset-env",
|
||||||
|
"@babel/preset-react"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"eslintConfig": {
|
||||||
|
"extends": "react-app"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@babel/core": "^7.1.6",
|
||||||
|
"@babel/preset-env": "^7.1.6",
|
||||||
|
"@babel/preset-react": "^7.0.0",
|
||||||
|
"@typescript-eslint/eslint-plugin": "^2.3.0",
|
||||||
|
"@typescript-eslint/parser": "^2.3.0",
|
||||||
|
"babel-loader": "^8.0.4",
|
||||||
|
"eslint-plugin-react-hooks": "^2.0.1",
|
||||||
|
"mini-css-extract-plugin": "^0.8.0",
|
||||||
|
"webpack": "^4.42.1",
|
||||||
|
"webpack-cli": "3.1.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
@@ -0,0 +1,131 @@
|
|||||||
|
/* global chrome */
|
||||||
|
/*global firebase*/
|
||||||
|
|
||||||
|
const firebaseConfig = {
|
||||||
|
apiKey: 'AIzaSyCJLuYpzXLDRmu2ttzFuSGmYcpFxqToWFU',
|
||||||
|
authDomain: 'watch-party-crx.firebaseapp.com',
|
||||||
|
databaseURL: 'https://watch-party-crx.firebaseio.com',
|
||||||
|
projectId: 'watch-party-crx',
|
||||||
|
storageBucket: 'watch-party-crx.appspot.com',
|
||||||
|
messagingSenderId: '712242707190',
|
||||||
|
appId: '1:712242707190:web:65fa7f772e30da364b0ad7',
|
||||||
|
measurementId: 'G-EZS4PEVG4T',
|
||||||
|
};
|
||||||
|
|
||||||
|
firebase.initializeApp(firebaseConfig);
|
||||||
|
firebase.auth().setPersistence(firebase.auth.Auth.Persistence.LOCAL);
|
||||||
|
|
||||||
|
const isAuthed = () => true && firebase.auth().currentUser;
|
||||||
|
const doAuth = () => firebase.auth().signInAnonymously();
|
||||||
|
|
||||||
|
const fetcher = async (request, sendResponse) => {
|
||||||
|
if (!isAuthed()) await doAuth();
|
||||||
|
const { url, method } = request;
|
||||||
|
delete request.type;
|
||||||
|
delete request.url;
|
||||||
|
delete request.method;
|
||||||
|
const idToken = await firebase.auth().currentUser.getIdToken();
|
||||||
|
let resStatus = {};
|
||||||
|
fetch(url, {
|
||||||
|
method,
|
||||||
|
headers: {
|
||||||
|
Authorization: `Token ${idToken}:${firebase.auth().currentUser.uid}`,
|
||||||
|
'Access-Control-Allow-Origin': '*',
|
||||||
|
},
|
||||||
|
...request,
|
||||||
|
})
|
||||||
|
.then((res) => {
|
||||||
|
resStatus = {
|
||||||
|
status: res.status,
|
||||||
|
statusText: res.statusText,
|
||||||
|
};
|
||||||
|
return res.json();
|
||||||
|
})
|
||||||
|
.then((res) => sendResponse({ ...res, ...resStatus }))
|
||||||
|
.catch((err) => sendResponse({ ...err, status: 503, statusText: "Couldn't talk to server" }));
|
||||||
|
};
|
||||||
|
|
||||||
|
const sendAuth = async (sendResponse) => {
|
||||||
|
if (!isAuthed()) await doAuth();
|
||||||
|
sendResponse(firebase.auth().currentUser);
|
||||||
|
};
|
||||||
|
|
||||||
|
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
||||||
|
const { type } = request;
|
||||||
|
switch (type) {
|
||||||
|
case 'API_CALL':
|
||||||
|
fetcher(request, sendResponse);
|
||||||
|
break;
|
||||||
|
case 'GET_AUTH':
|
||||||
|
sendAuth(sendResponse);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
console.warn('Unknown message type: <', type, '>');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
chrome.runtime.onConnect.addListener((port) => {
|
||||||
|
port.onDisconnect.addListener(() => {
|
||||||
|
port.roomListener && port.roomListener();
|
||||||
|
port.userListener && port.userListener();
|
||||||
|
port.messageListener && port.messageListener();
|
||||||
|
});
|
||||||
|
port.onMessage.addListener((request) => {
|
||||||
|
const { type, roomId } = request;
|
||||||
|
if (type === 'INIT') {
|
||||||
|
port.roomListener = firebase
|
||||||
|
.firestore()
|
||||||
|
.collection('rooms')
|
||||||
|
.doc(roomId)
|
||||||
|
.onSnapshot(
|
||||||
|
(snap) => {
|
||||||
|
if (snap) {
|
||||||
|
port.postMessage(snap.data());
|
||||||
|
}
|
||||||
|
},
|
||||||
|
(err) => {
|
||||||
|
port.postMessage({ isError: true, ...err });
|
||||||
|
}
|
||||||
|
);
|
||||||
|
port.userListener = firebase
|
||||||
|
.firestore()
|
||||||
|
.collection('rooms')
|
||||||
|
.doc(roomId)
|
||||||
|
.collection('users')
|
||||||
|
.onSnapshot(
|
||||||
|
(snap) => {
|
||||||
|
if (snap) {
|
||||||
|
const isAdmin = snap.docs
|
||||||
|
.filter((user) => user.id === firebase.auth().currentUser.uid)[0]
|
||||||
|
.data().admin;
|
||||||
|
port.postMessage({ admin: isAdmin });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
(err) => {
|
||||||
|
port.postMessage({ isError: true, ...err });
|
||||||
|
}
|
||||||
|
);
|
||||||
|
port.messageListener = firebase
|
||||||
|
.firestore()
|
||||||
|
.collection('rooms')
|
||||||
|
.doc(roomId)
|
||||||
|
.collection('messages')
|
||||||
|
.orderBy('time')
|
||||||
|
.onSnapshot(
|
||||||
|
(snap) => {
|
||||||
|
if (snap) {
|
||||||
|
let messages = snap.docs.map((v) => ({ ...v.data(), id: v.id }));
|
||||||
|
port.postMessage({
|
||||||
|
messages,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
(err) => {
|
||||||
|
port.postMessage({ isError: true, ...err });
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
After Width: | Height: | Size: 5.0 KiB |
|
After Width: | Height: | Size: 915 B |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
@@ -0,0 +1,7 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||||
|
<div id="root"></div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
After Width: | Height: | Size: 8.1 KiB |
|
After Width: | Height: | Size: 11 KiB |
@@ -0,0 +1,66 @@
|
|||||||
|
{
|
||||||
|
"name": "Watch Party",
|
||||||
|
"short_name": "WP",
|
||||||
|
"version": "1.2.0",
|
||||||
|
"description": "Watch streamed content together.",
|
||||||
|
"background": {
|
||||||
|
"page": "popup.html"
|
||||||
|
},
|
||||||
|
"permissions": [
|
||||||
|
"https://*.hulu.com/*",
|
||||||
|
"https://*.netflix.com/*",
|
||||||
|
"https://*.amazon.com/*",
|
||||||
|
"https://*.disneyplus.com/*",
|
||||||
|
"https://*.youtube.com/*",
|
||||||
|
"https://play.hbonow.com/*"
|
||||||
|
],
|
||||||
|
"content_security_policy": "script-src 'self' https://www.gstatic.com/ https://*.firebaseio.com https://www.googleapis.com; object-src 'self'",
|
||||||
|
"content_scripts": [
|
||||||
|
{
|
||||||
|
"matches": ["https://*.hulu.com/*"],
|
||||||
|
"run_at": "document_idle",
|
||||||
|
"js": ["/static/js/content.js"],
|
||||||
|
"css": ["/static/css/app.css"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"matches": ["https://*.netflix.com/*"],
|
||||||
|
"run_at": "document_idle",
|
||||||
|
"js": ["/static/js/content.js"],
|
||||||
|
"css": ["/static/css/app.css"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"matches": ["https://*.amazon.com/*"],
|
||||||
|
"run_at": "document_idle",
|
||||||
|
"js": ["/static/js/content.js"],
|
||||||
|
"css": ["/static/css/app.css"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"matches": ["https://*.disneyplus.com/*"],
|
||||||
|
"run_at": "document_idle",
|
||||||
|
"js": ["/static/js/content.js"],
|
||||||
|
"css": ["/static/css/app.css"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"matches": ["https://*.youtube.com/*"],
|
||||||
|
"run_at": "document_idle",
|
||||||
|
"js": ["/static/js/content.js"],
|
||||||
|
"css": ["/static/css/app.css"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"matches": ["https://play.hbonow.com/*"],
|
||||||
|
"run_at": "document_idle",
|
||||||
|
"js": ["/static/js/content.js"],
|
||||||
|
"css": ["/static/css/app.css"]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"web_accessible_resources": ["android-icon-192x192.png"],
|
||||||
|
"icons": {
|
||||||
|
"16": "favicon-16x16.png",
|
||||||
|
"32": "favicon-32x32.png",
|
||||||
|
"96": "favicon-96x96.png",
|
||||||
|
"128": "favicon-128x128.png",
|
||||||
|
"144": "android-icon-144x144.png",
|
||||||
|
"192": "android-icon-192x192.png"
|
||||||
|
},
|
||||||
|
"manifest_version": 2
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta
|
||||||
|
http-equiv="Content-Security-Policy"
|
||||||
|
content="default-src *; style-src 'self' https://* 'unsafe-inline'; script-src 'self' http://* 'unsafe-inline' 'unsafe-eval'"
|
||||||
|
/>
|
||||||
|
<style>
|
||||||
|
html {
|
||||||
|
height: fit-content;
|
||||||
|
width: fit-content;
|
||||||
|
}
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
min-width: 200px;
|
||||||
|
background-color: rgba(46, 46, 46, 1);
|
||||||
|
height: fit-content;
|
||||||
|
}
|
||||||
|
a:hover {
|
||||||
|
filter: drop-shadow(0 0 10px black);
|
||||||
|
}
|
||||||
|
a {
|
||||||
|
border-radius: 13px;
|
||||||
|
font-family: sans-serif;
|
||||||
|
font-weight: 500;
|
||||||
|
display: block;
|
||||||
|
user-select: none;
|
||||||
|
color: black;
|
||||||
|
text-decoration: none;
|
||||||
|
padding: 5px 10px;
|
||||||
|
text-align: center;
|
||||||
|
margin: 10px 10px;
|
||||||
|
}
|
||||||
|
a:nth-child(1) {
|
||||||
|
background-color: rgb(23, 245, 160);
|
||||||
|
}
|
||||||
|
a:nth-child(2) {
|
||||||
|
background-color: rgb(235, 77, 77);
|
||||||
|
}
|
||||||
|
a:nth-child(3) {
|
||||||
|
background-color: cornflowerblue;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<script src="https://www.gstatic.com/firebasejs/7.14.1/firebase-app.js"></script>
|
||||||
|
<script src="https://www.gstatic.com/firebasejs/7.14.1/firebase-auth.js"></script>
|
||||||
|
<script src="https://www.gstatic.com/firebasejs/7.14.1/firebase-firestore.js"></script>
|
||||||
|
<script src="background.js"></script>
|
||||||
|
<a target="_blank" href="https://www.hulu.com/">Hulu</a>
|
||||||
|
<a target="_blank" href="https://www.netflix.com/browse">Netflix</a>
|
||||||
|
<a target="_blank" href="https://www.amazon.com/gp/video/storefront">Prime Video</a>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
# https://www.robotstxt.org/robotstxt.html
|
||||||
|
User-agent: *
|
||||||
|
Disallow:
|
||||||
@@ -0,0 +1,150 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
// Do this as the first thing so that any code reading it knows the right env.
|
||||||
|
process.env.BABEL_ENV = 'production';
|
||||||
|
process.env.NODE_ENV = 'production';
|
||||||
|
|
||||||
|
// Makes the script crash on unhandled rejections instead of silently
|
||||||
|
// ignoring them. In the future, promise rejections that are not handled will
|
||||||
|
// terminate the Node.js process with a non-zero exit code.
|
||||||
|
process.on('unhandledRejection', err => {
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Ensure environment variables are read.
|
||||||
|
require('../config/env');
|
||||||
|
|
||||||
|
const path = require('path');
|
||||||
|
const chalk = require('chalk');
|
||||||
|
const fs = require('fs-extra');
|
||||||
|
const webpack = require('webpack');
|
||||||
|
const config = require('../config/webpack.config.prod');
|
||||||
|
const paths = require('../config/paths');
|
||||||
|
const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
|
||||||
|
const formatWebpackMessages = require('react-dev-utils/formatWebpackMessages');
|
||||||
|
const printHostingInstructions = require('react-dev-utils/printHostingInstructions');
|
||||||
|
const FileSizeReporter = require('react-dev-utils/FileSizeReporter');
|
||||||
|
const printBuildError = require('react-dev-utils/printBuildError');
|
||||||
|
|
||||||
|
const measureFileSizesBeforeBuild =
|
||||||
|
FileSizeReporter.measureFileSizesBeforeBuild;
|
||||||
|
const printFileSizesAfterBuild = FileSizeReporter.printFileSizesAfterBuild;
|
||||||
|
const useYarn = fs.existsSync(paths.yarnLockFile);
|
||||||
|
|
||||||
|
// These sizes are pretty large. We'll warn for bundles exceeding them.
|
||||||
|
const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
|
||||||
|
const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;
|
||||||
|
|
||||||
|
// Warn and crash if required files are missing
|
||||||
|
if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) {
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// First, read the current file sizes in build directory.
|
||||||
|
// This lets us display how much they changed later.
|
||||||
|
measureFileSizesBeforeBuild(paths.appBuild)
|
||||||
|
.then(previousFileSizes => {
|
||||||
|
// Remove all content but keep the directory so that
|
||||||
|
// if you're in it, you don't end up in Trash
|
||||||
|
fs.emptyDirSync(paths.appBuild);
|
||||||
|
// Merge with the public folder
|
||||||
|
copyPublicFolder();
|
||||||
|
// Start the webpack build
|
||||||
|
return build(previousFileSizes);
|
||||||
|
})
|
||||||
|
.then(
|
||||||
|
({ stats, previousFileSizes, warnings }) => {
|
||||||
|
if (warnings.length) {
|
||||||
|
console.log(chalk.yellow('Compiled with warnings.\n'));
|
||||||
|
console.log(warnings.join('\n\n'));
|
||||||
|
console.log(
|
||||||
|
'\nSearch for the ' +
|
||||||
|
chalk.underline(chalk.yellow('keywords')) +
|
||||||
|
' to learn more about each warning.'
|
||||||
|
);
|
||||||
|
console.log(
|
||||||
|
'To ignore, add ' +
|
||||||
|
chalk.cyan('// eslint-disable-next-line') +
|
||||||
|
' to the line before.\n'
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
console.log(chalk.green('Compiled successfully.\n'));
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('File sizes after gzip:\n');
|
||||||
|
printFileSizesAfterBuild(
|
||||||
|
stats,
|
||||||
|
previousFileSizes,
|
||||||
|
paths.appBuild,
|
||||||
|
WARN_AFTER_BUNDLE_GZIP_SIZE,
|
||||||
|
WARN_AFTER_CHUNK_GZIP_SIZE
|
||||||
|
);
|
||||||
|
console.log();
|
||||||
|
|
||||||
|
const appPackage = require(paths.appPackageJson);
|
||||||
|
const publicUrl = paths.publicUrl;
|
||||||
|
const publicPath = config.output.publicPath;
|
||||||
|
const buildFolder = path.relative(process.cwd(), paths.appBuild);
|
||||||
|
printHostingInstructions(
|
||||||
|
appPackage,
|
||||||
|
publicUrl,
|
||||||
|
publicPath,
|
||||||
|
buildFolder,
|
||||||
|
useYarn
|
||||||
|
);
|
||||||
|
},
|
||||||
|
err => {
|
||||||
|
console.log(chalk.red('Failed to compile.\n'));
|
||||||
|
printBuildError(err);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// Create the production build and print the deployment instructions.
|
||||||
|
function build(previousFileSizes) {
|
||||||
|
console.log('Creating an optimized production build...');
|
||||||
|
|
||||||
|
let compiler = webpack(config);
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
compiler.run((err, stats) => {
|
||||||
|
if (err) {
|
||||||
|
return reject(err);
|
||||||
|
}
|
||||||
|
const messages = formatWebpackMessages(stats.toJson({}, true));
|
||||||
|
if (messages.errors.length) {
|
||||||
|
// Only keep the first error. Others are often indicative
|
||||||
|
// of the same problem, but confuse the reader with noise.
|
||||||
|
if (messages.errors.length > 1) {
|
||||||
|
messages.errors.length = 1;
|
||||||
|
}
|
||||||
|
return reject(new Error(messages.errors.join('\n\n')));
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
process.env.CI &&
|
||||||
|
(typeof process.env.CI !== 'string' ||
|
||||||
|
process.env.CI.toLowerCase() !== 'false') &&
|
||||||
|
messages.warnings.length
|
||||||
|
) {
|
||||||
|
console.log(
|
||||||
|
chalk.yellow(
|
||||||
|
'\nTreating warnings as errors because process.env.CI = true.\n' +
|
||||||
|
'Most CI servers set it automatically.\n'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return reject(new Error(messages.warnings.join('\n\n')));
|
||||||
|
}
|
||||||
|
return resolve({
|
||||||
|
stats,
|
||||||
|
previousFileSizes,
|
||||||
|
warnings: messages.warnings,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function copyPublicFolder() {
|
||||||
|
fs.copySync(paths.appPublic, paths.appBuild, {
|
||||||
|
dereference: true,
|
||||||
|
filter: file => file !== paths.appHtml,
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
// Do this as the first thing so that any code reading it knows the right env.
|
||||||
|
process.env.BABEL_ENV = 'development';
|
||||||
|
process.env.NODE_ENV = 'development';
|
||||||
|
|
||||||
|
// Makes the script crash on unhandled rejections instead of silently
|
||||||
|
// ignoring them. In the future, promise rejections that are not handled will
|
||||||
|
// terminate the Node.js process with a non-zero exit code.
|
||||||
|
process.on('unhandledRejection', (err) => {
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Ensure environment variables are read.
|
||||||
|
require('../config/env');
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
|
const chalk = require('chalk');
|
||||||
|
const webpack = require('webpack');
|
||||||
|
const WebpackDevServer = require('webpack-dev-server');
|
||||||
|
const clearConsole = require('react-dev-utils/clearConsole');
|
||||||
|
const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
|
||||||
|
const {
|
||||||
|
choosePort,
|
||||||
|
createCompiler,
|
||||||
|
prepareProxy,
|
||||||
|
prepareUrls,
|
||||||
|
} = require('react-dev-utils/WebpackDevServerUtils');
|
||||||
|
const openBrowser = require('react-dev-utils/openBrowser');
|
||||||
|
const paths = require('../config/paths');
|
||||||
|
const config = require('../config/webpack.config.dev');
|
||||||
|
const createDevServerConfig = require('../config/webpackDevServer.config');
|
||||||
|
|
||||||
|
const useYarn = fs.existsSync(paths.yarnLockFile);
|
||||||
|
const isInteractive = process.stdout.isTTY;
|
||||||
|
|
||||||
|
// Warn and crash if required files are missing
|
||||||
|
if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) {
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tools like Cloud9 rely on this.
|
||||||
|
const DEFAULT_PORT = parseInt(process.env.PORT, 10) || 3000;
|
||||||
|
const HOST = process.env.HOST || '0.0.0.0';
|
||||||
|
|
||||||
|
if (process.env.HOST) {
|
||||||
|
console.log(
|
||||||
|
chalk.cyan(
|
||||||
|
`Attempting to bind to HOST environment variable: ${chalk.yellow(
|
||||||
|
chalk.bold(process.env.HOST)
|
||||||
|
)}`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
console.log(`If this was unintentional, check that you haven't mistakenly set it in your shell.`);
|
||||||
|
console.log(`Learn more here: ${chalk.yellow('http://bit.ly/2mwWSwH')}`);
|
||||||
|
console.log();
|
||||||
|
}
|
||||||
|
|
||||||
|
// We attempt to use the default port but if it is busy, we offer the user to
|
||||||
|
// run on a different port. `choosePort()` Promise resolves to the next free port.
|
||||||
|
choosePort(HOST, DEFAULT_PORT)
|
||||||
|
.then((port) => {
|
||||||
|
if (port == null) {
|
||||||
|
// We have not found a port.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
|
||||||
|
const appName = require(paths.appPackageJson).name;
|
||||||
|
const urls = prepareUrls(protocol, HOST, port);
|
||||||
|
// Create a webpack compiler that is configured with custom messages.
|
||||||
|
const compiler = createCompiler({ webpack, config, appName, urls, useYarn });
|
||||||
|
// Load proxy config
|
||||||
|
const proxySetting = require(paths.appPackageJson).proxy;
|
||||||
|
const proxyConfig = prepareProxy(proxySetting, paths.appPublic);
|
||||||
|
// Serve webpack assets generated by the compiler over a web sever.
|
||||||
|
const serverConfig = createDevServerConfig(proxyConfig, urls.lanUrlForConfig);
|
||||||
|
const devServer = new WebpackDevServer(compiler, serverConfig);
|
||||||
|
// Launch WebpackDevServer.
|
||||||
|
devServer.listen(port, HOST, (err) => {
|
||||||
|
if (err) {
|
||||||
|
return console.log(err);
|
||||||
|
}
|
||||||
|
if (isInteractive) {
|
||||||
|
clearConsole();
|
||||||
|
}
|
||||||
|
console.log(chalk.cyan('Starting the development server...\n'));
|
||||||
|
openBrowser(urls.localUrlForBrowser);
|
||||||
|
});
|
||||||
|
|
||||||
|
['SIGINT', 'SIGTERM'].forEach(function (sig) {
|
||||||
|
process.on(sig, function () {
|
||||||
|
devServer.close();
|
||||||
|
process.exit();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
if (err && err.message) {
|
||||||
|
console.log(err.message);
|
||||||
|
}
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
// Do this as the first thing so that any code reading it knows the right env.
|
||||||
|
process.env.BABEL_ENV = 'test';
|
||||||
|
process.env.NODE_ENV = 'test';
|
||||||
|
process.env.PUBLIC_URL = '';
|
||||||
|
|
||||||
|
// Makes the script crash on unhandled rejections instead of silently
|
||||||
|
// ignoring them. In the future, promise rejections that are not handled will
|
||||||
|
// terminate the Node.js process with a non-zero exit code.
|
||||||
|
process.on('unhandledRejection', err => {
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Ensure environment variables are read.
|
||||||
|
require('../config/env');
|
||||||
|
|
||||||
|
const jest = require('jest');
|
||||||
|
let argv = process.argv.slice(2);
|
||||||
|
|
||||||
|
// Watch unless on CI or in coverage mode
|
||||||
|
if (!process.env.CI && argv.indexOf('--coverage') < 0) {
|
||||||
|
argv.push('--watch');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
jest.run(argv);
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
/*global chrome*/
|
||||||
|
|
||||||
|
const API_HOST = window.location.href.startsWith('http://localhost')
|
||||||
|
? 'http://localhost:5001/watch-party-crx/us-central1/widgets'
|
||||||
|
: // : 'http://localhost:5001/watch-party-crx/us-central1/widgets';
|
||||||
|
'https://us-central1-watch-party-crx.cloudfunctions.net/widgets';
|
||||||
|
|
||||||
|
export const PLAYER_STATUS = {
|
||||||
|
PLAYING: 'PLAYING',
|
||||||
|
PAUSED: 'PAUSED',
|
||||||
|
NOT_PLAYING: 'NOT_PLAYING',
|
||||||
|
};
|
||||||
|
|
||||||
|
export const PLAYER_SOURCE = {
|
||||||
|
NETFLIX: 'https://www.netflix.',
|
||||||
|
AMAZON: 'https://www.amazon.',
|
||||||
|
HULU: 'https://www.hulu.',
|
||||||
|
DISNEY: 'https://www.disneyplus.',
|
||||||
|
YOUTUBE: 'https://www.youtube.',
|
||||||
|
HBONOW: 'https://play.hbonow.',
|
||||||
|
LOCAL: 'http://localhost',
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getPlayerSource = () => {
|
||||||
|
const HREF = window.location.href;
|
||||||
|
if (HREF.startsWith(PLAYER_SOURCE.NETFLIX)) return PLAYER_SOURCE.NETFLIX;
|
||||||
|
if (HREF.startsWith(PLAYER_SOURCE.HULU)) return PLAYER_SOURCE.HULU;
|
||||||
|
if (HREF.startsWith(PLAYER_SOURCE.AMAZON)) return PLAYER_SOURCE.AMAZON;
|
||||||
|
if (HREF.startsWith(PLAYER_SOURCE.DISNEY)) return PLAYER_SOURCE.DISNEY;
|
||||||
|
if (HREF.startsWith(PLAYER_SOURCE.YOUTUBE)) return PLAYER_SOURCE.YOUTUBE;
|
||||||
|
if (HREF.startsWith(PLAYER_SOURCE.HBONOW)) return PLAYER_SOURCE.HBONOW;
|
||||||
|
if (HREF.startsWith(PLAYER_SOURCE.LOCAL)) return PLAYER_SOURCE.LOCAL;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getUserUid = async () =>
|
||||||
|
new Promise((resolve, reject) => {
|
||||||
|
chrome.runtime.sendMessage(
|
||||||
|
{
|
||||||
|
type: 'GET_AUTH',
|
||||||
|
},
|
||||||
|
(response) => {
|
||||||
|
const { uid } = response;
|
||||||
|
window.localStorage.setItem('watchPartyUserUid', uid);
|
||||||
|
resolve(uid);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
export const fetcher = async ({ endpoint, method, ...args }) => {
|
||||||
|
const url = `${API_HOST}/${endpoint}`;
|
||||||
|
return new Promise((resolve, reject) =>
|
||||||
|
chrome.runtime.sendMessage(
|
||||||
|
{
|
||||||
|
type: 'API_CALL',
|
||||||
|
url,
|
||||||
|
method,
|
||||||
|
...args,
|
||||||
|
},
|
||||||
|
(response) => {
|
||||||
|
if (response.status > 299) reject(response);
|
||||||
|
else resolve({ json: () => response });
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const CreateRoomApi = async (data) => {
|
||||||
|
return fetcher({
|
||||||
|
endpoint: 'create',
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const JoinRoomApi = async (data) => {
|
||||||
|
return fetcher({
|
||||||
|
endpoint: 'join',
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const SendMessageApi = async (data) => {
|
||||||
|
return fetcher({
|
||||||
|
endpoint: 'message',
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const LeaveRoomApi = async (data) => {
|
||||||
|
return fetcher({
|
||||||
|
endpoint: `leave/${data.roomId}/users/${data.uid}`,
|
||||||
|
method: 'DELETE',
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const DeleteRoomApi = async (data) => {
|
||||||
|
return fetcher({
|
||||||
|
endpoint: `delete/${data.roomId}`,
|
||||||
|
method: 'DELETE',
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const UpdatePlayerApi = async (data) => {
|
||||||
|
return fetcher({
|
||||||
|
endpoint: 'updatePlayer',
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
import React, { useState, useEffect } from 'react';
|
||||||
|
import Router from 'route-lite';
|
||||||
|
import { Fab, createMuiTheme, ThemeProvider, Snackbar } from '@material-ui/core';
|
||||||
|
import Create from './Create';
|
||||||
|
import Loading from './Loading';
|
||||||
|
import firebase from 'firebase/app';
|
||||||
|
import 'firebase/firestore';
|
||||||
|
import Inactive from './Inactive';
|
||||||
|
import { getUserUid } from './Api';
|
||||||
|
|
||||||
|
const darkTheme = createMuiTheme({
|
||||||
|
palette: {
|
||||||
|
type: 'dark',
|
||||||
|
primary: {
|
||||||
|
main: '#a6d4fa',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const Routes = (props) => (
|
||||||
|
<Router>
|
||||||
|
<Create {...props} />
|
||||||
|
</Router>
|
||||||
|
);
|
||||||
|
|
||||||
|
const App = () => {
|
||||||
|
const closedNotification = { open: false, message: '' };
|
||||||
|
|
||||||
|
const [status, setStatus] = useState({ active: false, message: '' });
|
||||||
|
const [visible, setVisible] = useState(false);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [notification, setNotification] = useState(closedNotification);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setLoading(true);
|
||||||
|
getUserUid();
|
||||||
|
firebase
|
||||||
|
.firestore()
|
||||||
|
.collection('server')
|
||||||
|
.doc('status')
|
||||||
|
.onSnapshot((statusSnap) => {
|
||||||
|
setStatus(statusSnap.data());
|
||||||
|
setLoading(false);
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// HANDLE VISIBILITY STYLING
|
||||||
|
const PartyRoutesWrapper = document.getElementById('party-routes-wrapper');
|
||||||
|
if (visible) {
|
||||||
|
document.body.classList.add('visible');
|
||||||
|
PartyRoutesWrapper && PartyRoutesWrapper.classList.add('visible');
|
||||||
|
} else {
|
||||||
|
document.body.classList.remove('visible');
|
||||||
|
PartyRoutesWrapper && PartyRoutesWrapper.classList.remove('visible');
|
||||||
|
}
|
||||||
|
|
||||||
|
// HANDLE FULLSCREEN EVENT
|
||||||
|
document.onfullscreenchange = () => {
|
||||||
|
if (document.fullscreenElement) setVisible(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ThemeProvider theme={darkTheme}>
|
||||||
|
<Snackbar
|
||||||
|
className="party-notification-container"
|
||||||
|
anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }}
|
||||||
|
open={notification.open}
|
||||||
|
onClose={() => setNotification(closedNotification)}
|
||||||
|
message={notification.message}
|
||||||
|
resumeHideDuration={500}
|
||||||
|
autoHideDuration={2000}
|
||||||
|
/>
|
||||||
|
<div className="party-content-wrapper">
|
||||||
|
<div id="party-routes-wrapper">
|
||||||
|
{loading && <Loading />}
|
||||||
|
{status.active ? (
|
||||||
|
<Routes
|
||||||
|
updateLoading={setLoading}
|
||||||
|
notify={(message) => setNotification({ open: true, message })}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<Inactive status={status} />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<Fab onClick={() => setVisible(!visible)} className="watch-party-fab">
|
||||||
|
<span />
|
||||||
|
</Fab>
|
||||||
|
</div>
|
||||||
|
</ThemeProvider>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default App;
|
||||||
@@ -0,0 +1,280 @@
|
|||||||
|
/*global chrome */
|
||||||
|
import React, { Component } from 'react';
|
||||||
|
import {
|
||||||
|
Typography,
|
||||||
|
TextField,
|
||||||
|
InputAdornment,
|
||||||
|
IconButton,
|
||||||
|
ButtonGroup,
|
||||||
|
Button,
|
||||||
|
} from '@material-ui/core';
|
||||||
|
import Thread from './Thread';
|
||||||
|
import Send from '@material-ui/icons/Send';
|
||||||
|
import Exit from '@material-ui/icons/ExitToApp';
|
||||||
|
import Share from '@material-ui/icons/Share';
|
||||||
|
import Delete from '@material-ui/icons/Delete';
|
||||||
|
import Gif from '@material-ui/icons/Gif';
|
||||||
|
import { Carousel } from '@giphy/react-components';
|
||||||
|
import { GiphyFetch } from '@giphy/js-fetch-api';
|
||||||
|
import {
|
||||||
|
SendMessageApi,
|
||||||
|
LeaveRoomApi,
|
||||||
|
DeleteRoomApi,
|
||||||
|
UpdatePlayerApi,
|
||||||
|
getPlayerSource,
|
||||||
|
PLAYER_SOURCE,
|
||||||
|
} from './Api';
|
||||||
|
import { goTo } from 'route-lite';
|
||||||
|
import Create from './Create';
|
||||||
|
import VideoListener from './VideoListener';
|
||||||
|
|
||||||
|
const giphyFetch = new GiphyFetch('ojJbIMUN6XRMn4mHiFFav3rMCpXUg8sq');
|
||||||
|
const alertMessage = {
|
||||||
|
name: '<alert>',
|
||||||
|
text: 'Functionality may be buggy, support on this site is in beta.',
|
||||||
|
time: '',
|
||||||
|
uid: '<system>',
|
||||||
|
};
|
||||||
|
export default class Chat extends Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
name: '',
|
||||||
|
messages: [],
|
||||||
|
newMessage: '',
|
||||||
|
admin: null,
|
||||||
|
gif: false,
|
||||||
|
};
|
||||||
|
this.sendMessage = this.sendMessage.bind(this);
|
||||||
|
this.sendMessageInvoker = this.sendMessageInvoker.bind(this);
|
||||||
|
this.endParty = this.endParty.bind(this);
|
||||||
|
this.leaveParty = this.leaveParty.bind(this);
|
||||||
|
this.shareParty = this.shareParty.bind(this);
|
||||||
|
this.syncPlayer = this.syncPlayer.bind(this);
|
||||||
|
this.videoEventListener = this.videoEventListener.bind(this);
|
||||||
|
this.mVideoListener = new VideoListener(this.videoEventListener);
|
||||||
|
this.port = null;
|
||||||
|
this.getCarousel = this.getCarousel.bind(this);
|
||||||
|
this.gifClick = this.gifClick.bind(this);
|
||||||
|
}
|
||||||
|
componentDidMount() {
|
||||||
|
// EVENT CAPTURE FOR ENTER TO SEND
|
||||||
|
window.onkeypress = (ev) => {
|
||||||
|
if (ev.code === 'Enter') {
|
||||||
|
if (ev.target === document.getElementById('chat-message-box-input')) {
|
||||||
|
if (ev.shiftKey === false && this.state.gif === true) ev.preventDefault();
|
||||||
|
if (ev.shiftKey === false && this.state.gif === false) {
|
||||||
|
ev.preventDefault();
|
||||||
|
this.sendMessageInvoker();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// VIDEO LISTENER START
|
||||||
|
this.mVideoListener.start();
|
||||||
|
|
||||||
|
// CHROME FIREBASE FIRESTORE LISTENER
|
||||||
|
this.port = chrome.runtime.connect({ name: window.localStorage.getItem('watchPartyRoomId') });
|
||||||
|
// Initialize listener
|
||||||
|
this.port.postMessage({
|
||||||
|
type: 'INIT',
|
||||||
|
roomId: window.localStorage.getItem('watchPartyRoomId'),
|
||||||
|
});
|
||||||
|
// Listener
|
||||||
|
this.port.onMessage.addListener((response) => {
|
||||||
|
if (response.isError === true) {
|
||||||
|
this.props.notify('Uh oh. Got lost from the party.');
|
||||||
|
goTo(Create, this.props);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.setState(response);
|
||||||
|
if (response.player) this.mVideoListener.doUpdate(response.player);
|
||||||
|
const pcc = document.getElementsByClassName('thread-container')[0];
|
||||||
|
if (pcc) pcc.scrollTop = pcc.scrollHeight;
|
||||||
|
});
|
||||||
|
|
||||||
|
// DONE WITH MOUNTING TASKS
|
||||||
|
this.props.updateLoading(false);
|
||||||
|
}
|
||||||
|
componentWillUnmount() {
|
||||||
|
this.mVideoListener.end();
|
||||||
|
}
|
||||||
|
videoEventListener(video) {
|
||||||
|
this.syncPlayer(video);
|
||||||
|
}
|
||||||
|
syncPlayer(video) {
|
||||||
|
const { status, showName, time, source, element, showChanged } = video;
|
||||||
|
if (element) {
|
||||||
|
UpdatePlayerApi({
|
||||||
|
roomId: window.localStorage.getItem('watchPartyRoomId'),
|
||||||
|
showChanged,
|
||||||
|
userName: window.localStorage.getItem('watchPartyUserName'),
|
||||||
|
player: {
|
||||||
|
status,
|
||||||
|
showName,
|
||||||
|
time,
|
||||||
|
source,
|
||||||
|
updatedBy: window.localStorage.getItem('watchPartyUserUid'),
|
||||||
|
},
|
||||||
|
}).catch((err) => {
|
||||||
|
this.props.updateLoading(false);
|
||||||
|
this.props.notify(err.message || err.statusText);
|
||||||
|
console.error('Sync Party API error', err);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.mVideoListener.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
endParty() {
|
||||||
|
this.props.notify('Ending party...');
|
||||||
|
this.props.updateLoading(true);
|
||||||
|
const data = {
|
||||||
|
roomId: window.localStorage.getItem('watchPartyRoomId'),
|
||||||
|
};
|
||||||
|
DeleteRoomApi(data)
|
||||||
|
.then((res) => {
|
||||||
|
this.props.notify('Ended party');
|
||||||
|
window.localStorage.removeItem('watchPartyRoomId');
|
||||||
|
goTo(Create, this.props);
|
||||||
|
this.props.updateLoading(false);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
this.props.updateLoading(false);
|
||||||
|
this.props.notify(err.message || err.statusText);
|
||||||
|
console.error('End Party API error', err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
leaveParty() {
|
||||||
|
this.props.notify('Leaving party...');
|
||||||
|
this.props.updateLoading(true);
|
||||||
|
const data = {
|
||||||
|
roomId: window.localStorage.getItem('watchPartyRoomId'),
|
||||||
|
uid: window.localStorage.getItem('watchPartyUserUid'),
|
||||||
|
};
|
||||||
|
LeaveRoomApi(data)
|
||||||
|
.then((res) => {
|
||||||
|
this.props.notify('Left party');
|
||||||
|
window.localStorage.removeItem('watchPartyRoomId');
|
||||||
|
goTo(Create, this.props);
|
||||||
|
this.props.updateLoading(false);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
this.props.updateLoading(false);
|
||||||
|
this.props.notify(err.message || err.statusText);
|
||||||
|
console.error('End Party API error', err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
shareParty() {
|
||||||
|
const el = document.createElement('textarea');
|
||||||
|
el.value = window.localStorage.getItem('watchPartyRoomId');
|
||||||
|
document.body.appendChild(el);
|
||||||
|
el.select();
|
||||||
|
document.execCommand('copy');
|
||||||
|
document.body.removeChild(el);
|
||||||
|
this.props.notify('Copied room code');
|
||||||
|
}
|
||||||
|
sendMessage(message) {
|
||||||
|
const data = {
|
||||||
|
roomId: window.localStorage.getItem('watchPartyRoomId'),
|
||||||
|
name: window.localStorage.getItem('watchPartyUserName'),
|
||||||
|
uid: window.localStorage.getItem('watchPartyUserUid'),
|
||||||
|
text: message,
|
||||||
|
time: new Date(),
|
||||||
|
type: '',
|
||||||
|
};
|
||||||
|
if (this.state.gif === true) data.type = 'giphy';
|
||||||
|
SendMessageApi(data).catch((err) => {
|
||||||
|
this.props.notify(err.message || err.statusText);
|
||||||
|
console.error('Send Message API error', err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
sendMessageInvoker(overrideMessage) {
|
||||||
|
if (overrideMessage) this.sendMessage(overrideMessage);
|
||||||
|
else {
|
||||||
|
const trim = this.state.newMessage.replace(/^\s+|\s+$/g, '');
|
||||||
|
if (trim !== '') this.sendMessage(trim);
|
||||||
|
}
|
||||||
|
this.setState({ newMessage: '' });
|
||||||
|
}
|
||||||
|
gifClick(iGif, ev) {
|
||||||
|
ev.preventDefault();
|
||||||
|
this.sendMessageInvoker(iGif.images.original.url);
|
||||||
|
}
|
||||||
|
getCarousel() {
|
||||||
|
const trendingFetch = (offset) => giphyFetch.trending({ offset, limit: 5 });
|
||||||
|
const searchFetch = (offset) => giphyFetch.search(this.state.newMessage, { offset, limit: 5 });
|
||||||
|
return (
|
||||||
|
<Carousel
|
||||||
|
fetchGifs={this.state.newMessage === '' ? trendingFetch : searchFetch}
|
||||||
|
gifHeight={200}
|
||||||
|
gutter={6}
|
||||||
|
onGifClick={this.gifClick}
|
||||||
|
hideAttribution
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
render() {
|
||||||
|
const { admin, name, messages, newMessage, gif } = this.state;
|
||||||
|
if (getPlayerSource() === PLAYER_SOURCE.HBONOW && messages[0] !== alertMessage)
|
||||||
|
messages.unshift(alertMessage);
|
||||||
|
return (
|
||||||
|
<div className="party-chat-container">
|
||||||
|
<div className="party-chat-header">
|
||||||
|
<div className="party-chat-header-text">
|
||||||
|
<Typography className="brand-title" variant="overline" display="block">
|
||||||
|
WATCH PARTY
|
||||||
|
</Typography>
|
||||||
|
<Typography className="room-title" variant="h4" gutterBottom>
|
||||||
|
{name}
|
||||||
|
</Typography>
|
||||||
|
</div>
|
||||||
|
<ButtonGroup className="party-controls" size="small" color="secondary">
|
||||||
|
<Button onClick={this.shareParty} startIcon={<Share />}>
|
||||||
|
<span className="party-control-button-text">Share</span>
|
||||||
|
</Button>
|
||||||
|
<Button onClick={this.leaveParty} startIcon={<Exit />}>
|
||||||
|
<span className="party-control-button-text">Leave</span>
|
||||||
|
</Button>
|
||||||
|
{admin && (
|
||||||
|
<Button onClick={this.endParty} startIcon={<Delete />}>
|
||||||
|
{/* <span className="party-control-button-text">End Party</span> */}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</ButtonGroup>
|
||||||
|
</div>
|
||||||
|
<div className="thread-container">
|
||||||
|
<Thread messages={messages} />
|
||||||
|
</div>
|
||||||
|
<TextField
|
||||||
|
multiline
|
||||||
|
rowsMax="3"
|
||||||
|
size="small"
|
||||||
|
placeholder="New message... (Enter to send)"
|
||||||
|
variant="outlined"
|
||||||
|
className="chat-message-box addFocus"
|
||||||
|
value={newMessage}
|
||||||
|
onChange={(e) => this.setState({ newMessage: e.target.value, gif: false })}
|
||||||
|
InputProps={{
|
||||||
|
id: 'chat-message-box-input',
|
||||||
|
endAdornment: (
|
||||||
|
<InputAdornment position="end">
|
||||||
|
<IconButton onClick={() => this.sendMessageInvoker(newMessage)} edge="end">
|
||||||
|
<Send />
|
||||||
|
</IconButton>
|
||||||
|
</InputAdornment>
|
||||||
|
),
|
||||||
|
startAdornment: (
|
||||||
|
<InputAdornment position="start">
|
||||||
|
<IconButton onClick={() => this.setState({ gif: !gif })} edge="start">
|
||||||
|
<Gif />
|
||||||
|
</IconButton>
|
||||||
|
</InputAdornment>
|
||||||
|
),
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
{gif ? this.getCarousel() : null}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,180 @@
|
|||||||
|
import React, { useState } from 'react';
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
InputAdornment,
|
||||||
|
TextField,
|
||||||
|
Typography,
|
||||||
|
IconButton,
|
||||||
|
Paper,
|
||||||
|
} from '@material-ui/core';
|
||||||
|
import Save from '@material-ui/icons/Save';
|
||||||
|
import { JoinRoomApi, CreateRoomApi, PLAYER_STATUS, getPlayerSource } from './Api';
|
||||||
|
import { goTo } from 'route-lite';
|
||||||
|
import Chat from './Chat';
|
||||||
|
|
||||||
|
const saveName = (data) => {
|
||||||
|
const { name, notify } = data;
|
||||||
|
window.localStorage.setItem('watchPartyUserName', name);
|
||||||
|
notify('Saved name');
|
||||||
|
};
|
||||||
|
const getName = () => window.localStorage.getItem('watchPartyUserName');
|
||||||
|
|
||||||
|
const saveRoomId = (data) => {
|
||||||
|
const { rid, notify } = data;
|
||||||
|
window.localStorage.setItem('watchPartyRoomId', rid);
|
||||||
|
notify('Saved room');
|
||||||
|
};
|
||||||
|
const getRoomId = () => window.localStorage.getItem('watchPartyRoomId');
|
||||||
|
|
||||||
|
const joinRoom = async (data) => {
|
||||||
|
data.props.updateLoading(true);
|
||||||
|
data.props.notify('Joining party...');
|
||||||
|
const apidata = {
|
||||||
|
roomId: data.joinName.trim(),
|
||||||
|
userName: data.name.trim(),
|
||||||
|
source: getPlayerSource(),
|
||||||
|
};
|
||||||
|
const confirmedRoomId = await JoinRoomApi(apidata)
|
||||||
|
.then((res) => res.json())
|
||||||
|
.then((res) => res.roomId)
|
||||||
|
.catch((err) => {
|
||||||
|
data.props.updateLoading(false);
|
||||||
|
data.props.notify(err.message || err.statusText);
|
||||||
|
console.error('Join Room API error', err);
|
||||||
|
});
|
||||||
|
if (confirmedRoomId && confirmedRoomId === apidata.roomId) {
|
||||||
|
saveName({
|
||||||
|
name: apidata.userName,
|
||||||
|
notify: data.props.notify,
|
||||||
|
});
|
||||||
|
saveRoomId({
|
||||||
|
rid: confirmedRoomId,
|
||||||
|
notify: data.props.notify,
|
||||||
|
});
|
||||||
|
data.props.notify('Joined party');
|
||||||
|
goTo(Chat, data.props);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const createRoom = async (data) => {
|
||||||
|
data.props.updateLoading(true);
|
||||||
|
data.props.notify('Starting party...');
|
||||||
|
|
||||||
|
const apidata = {
|
||||||
|
roomName: data.createName,
|
||||||
|
userName: data.name,
|
||||||
|
player: {
|
||||||
|
source: getPlayerSource(),
|
||||||
|
status: PLAYER_STATUS.PAUSED,
|
||||||
|
time: 0,
|
||||||
|
url: '',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
CreateRoomApi(apidata)
|
||||||
|
.then((res) => res.json())
|
||||||
|
.then((res) => {
|
||||||
|
if (res.status <= 299) {
|
||||||
|
saveName({
|
||||||
|
name: data.name,
|
||||||
|
notify: data.props.notify,
|
||||||
|
});
|
||||||
|
saveRoomId({
|
||||||
|
rid: res.roomId,
|
||||||
|
notify: data.props.notify,
|
||||||
|
});
|
||||||
|
data.props.notify('Started party');
|
||||||
|
goTo(Chat, data.props);
|
||||||
|
} else {
|
||||||
|
data.props.updateLoading(false);
|
||||||
|
data.props.notify(res.message || res.statusText);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
data.props.updateLoading(false);
|
||||||
|
data.props.notify(err.message || err.statusText);
|
||||||
|
console.error('Create Room API error', err);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const Create = (props) => {
|
||||||
|
const [name, setName] = useState(getName() || '');
|
||||||
|
const [createName, setCreateName] = useState('');
|
||||||
|
const [joinName, setJoinName] = useState(getRoomId() || '');
|
||||||
|
const { notify } = props;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="party-create-container">
|
||||||
|
<Typography className="brand-title" variant="h6" display="block" gutterBottom>
|
||||||
|
WATCH PARTY
|
||||||
|
</Typography>
|
||||||
|
<div className="party-create-inputs">
|
||||||
|
<TextField
|
||||||
|
fullWidth
|
||||||
|
value={name}
|
||||||
|
onChange={(e) => (e.target.value.length <= 24 ? setName(e.target.value) : null)}
|
||||||
|
className="name-field"
|
||||||
|
label="Name"
|
||||||
|
variant="filled"
|
||||||
|
helperText={name.length > 0 ? `${name.length}/24` : null}
|
||||||
|
InputProps={{
|
||||||
|
endAdornment: (
|
||||||
|
<InputAdornment position="end">
|
||||||
|
<IconButton onClick={() => saveName({ name, notify })}>
|
||||||
|
<Save />
|
||||||
|
</IconButton>
|
||||||
|
</InputAdornment>
|
||||||
|
),
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Paper className="join-card" elevation={3}>
|
||||||
|
<Typography variant="button" display="block" gutterBottom>
|
||||||
|
CREATE PARTY
|
||||||
|
</Typography>
|
||||||
|
<TextField
|
||||||
|
fullWidth
|
||||||
|
value={createName}
|
||||||
|
className="card-field addFocus"
|
||||||
|
onChange={(e) => (e.target.value.length <= 24 ? setCreateName(e.target.value) : null)}
|
||||||
|
helperText={createName.length > 0 ? `${createName.length}/24` : null}
|
||||||
|
label="Party Name"
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
onClick={() => createRoom({ name, createName, props })}
|
||||||
|
disabled={createName === ''}
|
||||||
|
color="primary"
|
||||||
|
fullWidth
|
||||||
|
variant="contained"
|
||||||
|
>
|
||||||
|
CREATE
|
||||||
|
</Button>
|
||||||
|
</Paper>
|
||||||
|
<Paper className="join-card" elevation={3}>
|
||||||
|
<Typography variant="button" display="block" gutterBottom>
|
||||||
|
JOIN PARTY
|
||||||
|
</Typography>
|
||||||
|
<TextField
|
||||||
|
color="secondary"
|
||||||
|
fullWidth
|
||||||
|
value={joinName}
|
||||||
|
className="card-field addFocus"
|
||||||
|
onChange={(e) => setJoinName(e.target.value)}
|
||||||
|
label="Party Code"
|
||||||
|
helperText="Ask your party leader for this code"
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
onClick={() => joinRoom({ joinName, name, props })}
|
||||||
|
disabled={joinName === ''}
|
||||||
|
variant="contained"
|
||||||
|
color="secondary"
|
||||||
|
fullWidth
|
||||||
|
>
|
||||||
|
JOIN
|
||||||
|
</Button>
|
||||||
|
</Paper>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Create;
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Typography } from '@material-ui/core';
|
||||||
|
import { Warning } from '@material-ui/icons';
|
||||||
|
|
||||||
|
const Inactive = (props) => (
|
||||||
|
<div id="party-loading" className="inactive">
|
||||||
|
<Warning />
|
||||||
|
<Typography variant="overline">PARTY IS PAUSED FOR A LITTLE CLEANUP</Typography>
|
||||||
|
<Typography variant="caption">{props.status.message}</Typography>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
export default Inactive;
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { CircularProgress } from '@material-ui/core';
|
||||||
|
|
||||||
|
const Loading = () => (
|
||||||
|
<div id="party-loading">
|
||||||
|
<CircularProgress />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
export default Loading;
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
.thread-item {
|
||||||
|
width: 100%;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
margin-top: 25px !important;
|
||||||
|
font-size: 12px !important;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
.thread-item.no-space {
|
||||||
|
margin-top: 0 !important;
|
||||||
|
}
|
||||||
|
.system-message {
|
||||||
|
display: block;
|
||||||
|
text-align: center;
|
||||||
|
width: 100%;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 12px;
|
||||||
|
margin-top: 7.5px !important;
|
||||||
|
color: rgba(147, 147, 147, 0.8) !important;
|
||||||
|
}
|
||||||
|
.system-message.alert {
|
||||||
|
background-color: black;
|
||||||
|
border-radius: 1rem;
|
||||||
|
color: white !important;
|
||||||
|
padding: 5px 10px;
|
||||||
|
position: sticky;
|
||||||
|
top: 2px;
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
.my-message {
|
||||||
|
display: block;
|
||||||
|
width: fit-content;
|
||||||
|
text-align: right;
|
||||||
|
margin-left: auto !important;
|
||||||
|
margin-right: 5px !important;
|
||||||
|
margin-top: 5px !important;
|
||||||
|
padding: 2.5px 10px !important;
|
||||||
|
border-radius: 13px;
|
||||||
|
max-width: 60%;
|
||||||
|
word-wrap: break-word;
|
||||||
|
background-color: rgb(49, 49, 49);
|
||||||
|
}
|
||||||
|
img.my-message {
|
||||||
|
margin-right: 0 !important;
|
||||||
|
padding-right: 0 !important;
|
||||||
|
border-radius: 1rem;
|
||||||
|
max-width: 60%;
|
||||||
|
background: none;
|
||||||
|
border-radius: 2rem;
|
||||||
|
}
|
||||||
|
.party-message {
|
||||||
|
font-size: 1rem !important;
|
||||||
|
display: block;
|
||||||
|
width: fit-content;
|
||||||
|
max-width: 60%;
|
||||||
|
word-wrap: break-word;
|
||||||
|
margin-top: 5px !important;
|
||||||
|
padding: 2.5px 10px !important;
|
||||||
|
border-radius: 13px;
|
||||||
|
background-color: rgb(88, 88, 88);
|
||||||
|
}
|
||||||
|
img.party-message {
|
||||||
|
border-radius: 1rem;
|
||||||
|
max-width: 60%;
|
||||||
|
background: none;
|
||||||
|
border-radius: 2rem;
|
||||||
|
margin-left: 0 !important;
|
||||||
|
padding-left: 0 !important;
|
||||||
|
}
|
||||||
|
.thread-item .name {
|
||||||
|
color: rgb(149, 149, 149);
|
||||||
|
font-size: 10px !important;
|
||||||
|
}
|
||||||
|
.time {
|
||||||
|
top: 0;
|
||||||
|
color: #3a3a3a;
|
||||||
|
position: absolute;
|
||||||
|
opacity: 0;
|
||||||
|
transition: all ease-in-out 0.3s;
|
||||||
|
}
|
||||||
|
.party-message ~ .time {
|
||||||
|
right: 0;
|
||||||
|
}
|
||||||
|
.party-message:hover ~ .time {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
.my-message ~ .time {
|
||||||
|
left: 0;
|
||||||
|
}
|
||||||
|
.my-message:hover ~ .time {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
body.hulu .my-message,
|
||||||
|
body.hulu .party-message {
|
||||||
|
font-size: 1.4rem !important;
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Typography } from '@material-ui/core';
|
||||||
|
import './Thread.css';
|
||||||
|
import firebase from 'firebase/app';
|
||||||
|
import 'firebase/firestore';
|
||||||
|
|
||||||
|
const Thread = (props) =>
|
||||||
|
props.messages.map((m, midx) => {
|
||||||
|
const userUid = window.localStorage.getItem('watchPartyUserUid');
|
||||||
|
if (m.uid === '<system>') {
|
||||||
|
if (m.name === '<alert>') {
|
||||||
|
return (
|
||||||
|
<Typography
|
||||||
|
variant="body2"
|
||||||
|
className="thread-item system-message alert"
|
||||||
|
key={m.id}
|
||||||
|
disabled
|
||||||
|
>
|
||||||
|
{m.text}
|
||||||
|
</Typography>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<Typography variant="body2" className="thread-item system-message" key={m.id} disabled>
|
||||||
|
{m.text}
|
||||||
|
</Typography>
|
||||||
|
);
|
||||||
|
} else if (m.uid === userUid) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={`thread-item ${
|
||||||
|
midx > 0 ? (props.messages[midx - 1].uid !== m.uid ? '' : 'no-space') : ''
|
||||||
|
}`}
|
||||||
|
key={m.id}
|
||||||
|
>
|
||||||
|
{m.type === 'giphy' ? (
|
||||||
|
<img className="my-message" alt="giphy gif" src={m.text} />
|
||||||
|
) : (
|
||||||
|
<Typography variant="body1" className="my-message">
|
||||||
|
{m.text}
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
|
<span className="time">{new Date(m.time.seconds * 1000).toLocaleTimeString()}</span>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={`thread-item ${
|
||||||
|
midx > 0 ? (props.messages[midx - 1].uid !== m.uid ? '' : 'no-space') : ''
|
||||||
|
}`}
|
||||||
|
key={m.id}
|
||||||
|
>
|
||||||
|
<Typography variant="caption" className="name">
|
||||||
|
{midx > 0 ? (props.messages[midx - 1].uid !== m.uid ? m.name : '') : m.name}
|
||||||
|
</Typography>
|
||||||
|
{m.type === 'giphy' ? (
|
||||||
|
<img className="party-message" alt="giphy gif" src={m.text} />
|
||||||
|
) : (
|
||||||
|
<Typography variant="body1" className="party-message">
|
||||||
|
{m.text}
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
|
<span className="time">{new Date(m.time.seconds * 1000).toLocaleTimeString()}</span>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
export default Thread;
|
||||||
@@ -0,0 +1,304 @@
|
|||||||
|
import { PLAYER_STATUS, getPlayerSource, PLAYER_SOURCE } from './Api';
|
||||||
|
|
||||||
|
const templateListener = (video) => console.log('MISSING VIDEO LISTENER');
|
||||||
|
|
||||||
|
export default class VideoListener {
|
||||||
|
constructor(listener = templateListener) {
|
||||||
|
this.video = {
|
||||||
|
status: PLAYER_STATUS.NOT_PLAYING,
|
||||||
|
time: 0,
|
||||||
|
showName: '',
|
||||||
|
source: '',
|
||||||
|
element: null,
|
||||||
|
};
|
||||||
|
this.isUpdating = false;
|
||||||
|
this.listener = listener;
|
||||||
|
this.updateStatus = this.updateStatus.bind(this);
|
||||||
|
this.firstTimeSync = this.firstTimeSync.bind(this);
|
||||||
|
this.doUpdate = this.doUpdate.bind(this);
|
||||||
|
this.start = this.start.bind(this);
|
||||||
|
this.onpause = this.onpause.bind(this);
|
||||||
|
this.onplay = this.onplay.bind(this);
|
||||||
|
this.shouldPushSync = this.shouldPushSync.bind(this);
|
||||||
|
}
|
||||||
|
shouldPushSync() {
|
||||||
|
return (
|
||||||
|
this.isUpdating === false &&
|
||||||
|
this.server !== null &&
|
||||||
|
this.server !== undefined &&
|
||||||
|
this.video.element !== null &&
|
||||||
|
this.video.element !== undefined &&
|
||||||
|
this.video.status !== PLAYER_STATUS.NOT_PLAYING &&
|
||||||
|
this.video.showName !== '' &&
|
||||||
|
this.video.showName !== null &&
|
||||||
|
(this.video.status !== this.server.status ||
|
||||||
|
Math.abs(this.video.element.currentTime - this.server.time) > 1.5)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
updateStatus(newStatus) {
|
||||||
|
this.video = Object.assign({}, this.video, newStatus);
|
||||||
|
if (this.shouldPushSync()) {
|
||||||
|
this.listener({
|
||||||
|
...this.video,
|
||||||
|
showChanged: this.video.showName !== this.server.showName,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async doUpdate(serverPlayer) {
|
||||||
|
this.server = serverPlayer;
|
||||||
|
if (
|
||||||
|
this.isUpdating === false &&
|
||||||
|
serverPlayer.showName === this.video.showName &&
|
||||||
|
serverPlayer.updatedBy !== window.localStorage.getItem('watchPartyUserUid')
|
||||||
|
) {
|
||||||
|
this.isUpdating = true;
|
||||||
|
if (this.video.element) {
|
||||||
|
// REMOVE LISTENER BEFORE SYNCING
|
||||||
|
this.video.element.removeEventListener('playing', this.onplay);
|
||||||
|
this.video.element.removeEventListener('pause', this.onpause);
|
||||||
|
await this.timeout(250);
|
||||||
|
// SEEK
|
||||||
|
if (Math.abs(serverPlayer.time - this.video.element.currentTime) > 1.5) {
|
||||||
|
switch (serverPlayer.source) {
|
||||||
|
case PLAYER_SOURCE.NETFLIX:
|
||||||
|
window.postMessage({ type: 'SEEK', time: serverPlayer.time * 1000 }, '*');
|
||||||
|
break;
|
||||||
|
case PLAYER_SOURCE.AMAZON:
|
||||||
|
if (this.video.status === PLAYER_STATUS.PAUSED)
|
||||||
|
await this.video.element
|
||||||
|
.play()
|
||||||
|
.catch((err) => console.error('WatchParty erred when syncing time.'));
|
||||||
|
this.video.element.currentTime = serverPlayer.time;
|
||||||
|
await this.timeout(500);
|
||||||
|
break;
|
||||||
|
case PLAYER_SOURCE.DISNEY:
|
||||||
|
this.video.element.currentTime = serverPlayer.time;
|
||||||
|
await this.timeout(500);
|
||||||
|
break;
|
||||||
|
case PLAYER_SOURCE.YOUTUBE:
|
||||||
|
this.video.element.currentTime = serverPlayer.time;
|
||||||
|
break;
|
||||||
|
case PLAYER_SOURCE.HULU:
|
||||||
|
window.postMessage({ type: 'SEEK', time: serverPlayer.time }, '*');
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// TOGGLE PLAYER STATUS
|
||||||
|
switch (serverPlayer.status) {
|
||||||
|
case PLAYER_STATUS.PAUSED:
|
||||||
|
if (
|
||||||
|
PLAYER_SOURCE.HULU === this.video.source ||
|
||||||
|
PLAYER_SOURCE.NETFLIX === this.video.source
|
||||||
|
)
|
||||||
|
window.postMessage({ type: 'PAUSE', time: serverPlayer.time }, '*');
|
||||||
|
else await this.video.element.pause();
|
||||||
|
break;
|
||||||
|
case PLAYER_STATUS.PLAYING:
|
||||||
|
if (
|
||||||
|
PLAYER_SOURCE.HULU === this.video.source ||
|
||||||
|
PLAYER_SOURCE.NETFLIX === this.video.source
|
||||||
|
)
|
||||||
|
window.postMessage({ type: 'PLAY', time: serverPlayer.time }, '*');
|
||||||
|
else
|
||||||
|
await this.video.element
|
||||||
|
.play()
|
||||||
|
.catch((err) => console.error('WatchParty erred when syncing play.'));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
await this.timeout(500);
|
||||||
|
// RE-ADD LISTENERS FOR FUTURE SYNC
|
||||||
|
this.video.element.addEventListener('playing', this.onplay);
|
||||||
|
this.video.element.addEventListener('pause', this.onpause);
|
||||||
|
}
|
||||||
|
this.isUpdating = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
timeout(n) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
setTimeout(resolve, n);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
async getShowName() {
|
||||||
|
switch (this.video.source) {
|
||||||
|
case PLAYER_SOURCE.NETFLIX:
|
||||||
|
const titleContainerParent = document.querySelector(
|
||||||
|
'.PlayerControls--control-element.text-control.video-title'
|
||||||
|
);
|
||||||
|
if (titleContainerParent) {
|
||||||
|
const titleContainer = titleContainerParent.firstChild;
|
||||||
|
const nshow = titleContainer.querySelector('h4')
|
||||||
|
? titleContainer.querySelector('h4').innerHTML
|
||||||
|
: titleContainer.innerHTML;
|
||||||
|
let nepisode = '';
|
||||||
|
titleContainer.querySelectorAll('span').forEach((e) => {
|
||||||
|
if (e.innerHTML) nepisode += e.innerHTML + ' ';
|
||||||
|
});
|
||||||
|
return nshow === '' && nepisode === '' ? null : nshow + '\n' + nepisode;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case PLAYER_SOURCE.AMAZON:
|
||||||
|
const ashow = document.querySelector('.f3w9jrr.ff48h02').firstChild.innerHTML;
|
||||||
|
const aepisode = document.querySelector('.f3w9jrr.ff48h02').lastChild.innerHTML;
|
||||||
|
return ashow === '' && aepisode === '' ? null : ashow + '\n' + aepisode;
|
||||||
|
case PLAYER_SOURCE.HULU:
|
||||||
|
const hshow = document.querySelector('.metadata-area__second-line').innerHTML;
|
||||||
|
const hepisode = document.querySelector('.metadata-area__third-line').innerHTML;
|
||||||
|
return hshow === '' && hepisode === '' ? null : hshow + '\n' + hepisode;
|
||||||
|
case PLAYER_SOURCE.DISNEY:
|
||||||
|
this.video.element.parentElement.click();
|
||||||
|
await this.timeout(200);
|
||||||
|
const dshow = document.querySelector('.title-field')
|
||||||
|
? document.querySelector('.title-field').innerHTML
|
||||||
|
: '';
|
||||||
|
const depisode = document.querySelector('.subtitle-field')
|
||||||
|
? document.querySelector('.subtitle-field').innerHTML
|
||||||
|
: '';
|
||||||
|
return dshow === '' && depisode === '' ? null : dshow + '\n' + depisode;
|
||||||
|
case PLAYER_SOURCE.YOUTUBE:
|
||||||
|
const yshow = document.querySelector('h1.title').innerText;
|
||||||
|
const yepisode = document.querySelector('yt-formatted-string.super-title').innerText;
|
||||||
|
return yshow === '' && yepisode === '' ? null : yshow + '\n' + yepisode;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async onplay(ev) {
|
||||||
|
this.updateStatus({
|
||||||
|
status: PLAYER_STATUS.PLAYING,
|
||||||
|
time: this.video.element.currentTime,
|
||||||
|
showName: await this.getShowName(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
async onpause(ev) {
|
||||||
|
this.updateStatus({
|
||||||
|
status: PLAYER_STATUS.PAUSED,
|
||||||
|
time: this.video.element.currentTime,
|
||||||
|
showName: await this.getShowName(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
async firstTimeSync(videoElement) {
|
||||||
|
this.updateStatus({
|
||||||
|
element: videoElement,
|
||||||
|
});
|
||||||
|
this.updateStatus({
|
||||||
|
showName: await this.getShowName(),
|
||||||
|
});
|
||||||
|
// if (videoElement.currentTime > 0 && !videoElement.paused) {
|
||||||
|
// this.updateStatus({
|
||||||
|
// time: videoElement.currentTime,
|
||||||
|
// status: PLAYER_STATUS.PLAYING,
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
videoElement.addEventListener('playing', this.onplay);
|
||||||
|
videoElement.addEventListener('pause', this.onpause);
|
||||||
|
}
|
||||||
|
async start() {
|
||||||
|
this.updateStatus({ source: getPlayerSource(), showName: await this.getShowName() });
|
||||||
|
switch (this.video.source) {
|
||||||
|
case PLAYER_SOURCE.NETFLIX:
|
||||||
|
const seekInject = `window.seekScriptLoaded=!0;var getVideoPlayer=function(){var e=window.netflix.appContext.state.playerApp.getAPI().videoPlayer,t=e.getAllPlayerSessionIds()[0];return e.getVideoPlayerBySessionId(t)},seekInteraction=function(e){if(e.source==window){if(e.data.type&&"SEEK"==e.data.type){getVideoPlayer().pause();getVideoPlayer().seek(e.data.time);}if(e.data.type&&e.data.type==="PAUSE"){getVideoPlayer().pause();}if(e.data.type&&e.data.type==="PLAY"){getVideoPlayer().play();}e.data.type&&"teardown"==e.data.type&&(window.removeEventListener("message",seekInteraction,!1),window.seekScriptLoaded=!1)}};window.addEventListener("message",seekInteraction,!1);`;
|
||||||
|
const seekInjectScript = document.createElement('script');
|
||||||
|
seekInjectScript.text = seekInject;
|
||||||
|
document.head.appendChild(seekInjectScript);
|
||||||
|
if (document.getElementsByClassName('AkiraPlayer')[0]) {
|
||||||
|
const videoElement = document
|
||||||
|
.getElementsByClassName('AkiraPlayer')[0]
|
||||||
|
.getElementsByTagName('video')[0];
|
||||||
|
if (videoElement) {
|
||||||
|
this.firstTimeSync(videoElement);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
document.addEventListener('DOMNodeInserted', (e) => {
|
||||||
|
if (e.target) {
|
||||||
|
if (e.target.classList) {
|
||||||
|
if (
|
||||||
|
e.target.classList.contains('nfp') &&
|
||||||
|
e.target.classList.contains('AkiraPlayer')
|
||||||
|
) {
|
||||||
|
e.target.addEventListener('DOMNodeInserted', (ev) => {
|
||||||
|
if (ev.target.children[0].id) {
|
||||||
|
this.firstTimeSync(ev.target.children[0].firstChild);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case PLAYER_SOURCE.HULU:
|
||||||
|
const huluSeekInject = `window.seekScriptLoaded=!0;var getVideoPlayer=function(){var e=document.getElementsByClassName('content-video-player')[0].__HuluDashPlayer__;return e;},seekInteraction=function(e){if(e.source==window){if(e.data.type&&"SEEK"==e.data.type){getVideoPlayer().seek(e.data.time,e.data.time);}if(e.data.type&&e.data.type==="PAUSE"){getVideoPlayer().pause();}if(e.data.type&&e.data.type==="PLAY"){getVideoPlayer().play();}e.data.type&&"teardown"==e.data.type&&(window.removeEventListener("message",seekInteraction,!1),window.seekScriptLoaded=!1)}};window.addEventListener("message",seekInteraction,!1);`;
|
||||||
|
const huluSeekInjectScript = document.createElement('script');
|
||||||
|
huluSeekInjectScript.text = huluSeekInject;
|
||||||
|
document.head.appendChild(huluSeekInjectScript);
|
||||||
|
const videoElement = document.getElementsByClassName('content-video-player')[0];
|
||||||
|
if (videoElement) {
|
||||||
|
this.firstTimeSync(videoElement);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case PLAYER_SOURCE.AMAZON:
|
||||||
|
if (document.getElementsByClassName('webPlayerSDKContainer')[0]) {
|
||||||
|
const videoElement = document
|
||||||
|
.getElementsByClassName('webPlayerSDKContainer')[0]
|
||||||
|
.getElementsByTagName('video')[0];
|
||||||
|
if (videoElement) {
|
||||||
|
this.firstTimeSync(videoElement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case PLAYER_SOURCE.DISNEY:
|
||||||
|
const disneyVideoElement = document.querySelector('video.btm-media-client-element');
|
||||||
|
if (disneyVideoElement) {
|
||||||
|
this.firstTimeSync(disneyVideoElement);
|
||||||
|
} else {
|
||||||
|
setInterval(
|
||||||
|
this.video.element
|
||||||
|
? null
|
||||||
|
: () => {
|
||||||
|
var dve = document.querySelector('video.btm-media-client-element');
|
||||||
|
if (dve !== null && (this.video.element !== dve || this.video.element === null)) {
|
||||||
|
this.firstTimeSync(dve);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
1000
|
||||||
|
);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case PLAYER_SOURCE.YOUTUBE:
|
||||||
|
const youtubeVideoElement = document.querySelector('video.video-stream.html5-main-video');
|
||||||
|
if (youtubeVideoElement) this.firstTimeSync(youtubeVideoElement);
|
||||||
|
else {
|
||||||
|
setInterval(
|
||||||
|
this.video.element
|
||||||
|
? null
|
||||||
|
: () => {
|
||||||
|
var yve = document.querySelector('video.video-stream.html5-main-video');
|
||||||
|
if (yve !== null && (this.video.element !== yve || this.video.element === null)) {
|
||||||
|
this.firstTimeSync(yve);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
1000
|
||||||
|
);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case PLAYER_SOURCE.LOCAL:
|
||||||
|
const localVideoElement = document.getElementsByTagName('video')[0];
|
||||||
|
if (localVideoElement) {
|
||||||
|
this.firstTimeSync(localVideoElement);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end() {
|
||||||
|
if (this.video.element) {
|
||||||
|
this.video.element.removeEventListener('playing', this.onplay);
|
||||||
|
this.video.element.removeEventListener('pause', this.onpause);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,302 @@
|
|||||||
|
:root {
|
||||||
|
--party-width: 350px;
|
||||||
|
--neg-party-width: -350px;
|
||||||
|
--body-width: calc(100% - var(--party-width));
|
||||||
|
}
|
||||||
|
body {
|
||||||
|
margin: 0 !important;
|
||||||
|
background-color: black;
|
||||||
|
transition: max-width ease-in-out 0.35s;
|
||||||
|
}
|
||||||
|
body.visible {
|
||||||
|
width: var(--body-width);
|
||||||
|
}
|
||||||
|
body.visible .watch-party-fab {
|
||||||
|
right: var(--party-width) !important;
|
||||||
|
transform: translateX(50%);
|
||||||
|
top: 1.5rem;
|
||||||
|
}
|
||||||
|
body.visible .party-notification-container {
|
||||||
|
display: block !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
body.netflix.visible .AkiraPlayer, /* NETFLIX */
|
||||||
|
body.hulu.visible .Player__container,/* HULU */
|
||||||
|
body.amazon-prime.visible #dv-web-player.dv-player-fullscreen, /* AMAZON PRIME */
|
||||||
|
body.disney.visible #hudson-wrapper, /* DISNEY */
|
||||||
|
body.youtube.visible #content.ytd-app, /* YOUTUBE */
|
||||||
|
body.youtube.visible #masthead-container, /* YOUTUBE HEADER */
|
||||||
|
body.hbo.visible video.default {
|
||||||
|
max-width: var(--body-width) !important;
|
||||||
|
}
|
||||||
|
/* HULU MINIMIZED VIDEO */
|
||||||
|
body.hulu.visible #__player__ .Player__container.Player__container--modal {
|
||||||
|
right: calc(var(--party-width) + 2rem) !important;
|
||||||
|
z-index: 99999 !important;
|
||||||
|
}
|
||||||
|
/* HULU, DISNEY & AMAZON PRIME FIX */
|
||||||
|
body.disney #party-routes-wrapper,
|
||||||
|
body.hulu #party-routes-wrapper,
|
||||||
|
body.amazon-prime #party-routes-wrapper {
|
||||||
|
width: var(--party-width) !important;
|
||||||
|
height: 100% !important;
|
||||||
|
}
|
||||||
|
/* DISNEY FULL SCREEN VIDEO FIX */
|
||||||
|
body.disney #hudson-wrapper {
|
||||||
|
left: 0;
|
||||||
|
}
|
||||||
|
/* YOUTUBE VIDEO SIZING FIX */
|
||||||
|
body.youtube.visible video {
|
||||||
|
max-width: 100%;
|
||||||
|
height: auto !important;
|
||||||
|
}
|
||||||
|
body.youtube.visible .ytp-chrome-bottom {
|
||||||
|
max-width: 100% !important;
|
||||||
|
width: calc(100% - 24px) !important;
|
||||||
|
}
|
||||||
|
body.youtube.visible .ytp-chapter-hover-container {
|
||||||
|
max-width: 100% !important;
|
||||||
|
}
|
||||||
|
body.youtube.visible .ytp-tooltip.ytp-bottom.ytp-preview {
|
||||||
|
bottom: 100px !important;
|
||||||
|
top: unset !important;
|
||||||
|
}
|
||||||
|
body.youtube.visible td-two-column-browse-results-renderer.grid:not(.grid-disabled) {
|
||||||
|
max-width: calc(100% - 48px);
|
||||||
|
}
|
||||||
|
/* AMAZON STYLING FIX */
|
||||||
|
body.amazon-prime input,
|
||||||
|
body.amazon-prime textarea {
|
||||||
|
background-color: inherit !important;
|
||||||
|
border: initial !important;
|
||||||
|
box-shadow: none !important;
|
||||||
|
}
|
||||||
|
body.amazon-prime input.MuiInputBase-input {
|
||||||
|
height: 1.1876em !important;
|
||||||
|
padding: 6px 0 7px !important;
|
||||||
|
}
|
||||||
|
body.amazon-prime input.MuiFilledInput-inputAdornedEnd {
|
||||||
|
padding-right: 0 !important;
|
||||||
|
}
|
||||||
|
body.amazon-prime input.MuiFilledInput-input {
|
||||||
|
padding: 27px 12px 10px !important;
|
||||||
|
}
|
||||||
|
body.amazon-prime input:focus,
|
||||||
|
body.amazon-prime textarea:focus {
|
||||||
|
border: none !important;
|
||||||
|
box-shadow: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes backgroundpulse {
|
||||||
|
0% {
|
||||||
|
background-color: black;
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
|
50% {
|
||||||
|
background-color: red;
|
||||||
|
color: black;
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
background-color: black;
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#party-loading {
|
||||||
|
position: absolute;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
z-index: 9999;
|
||||||
|
background-color: rgba(0, 0, 0, 0.8);
|
||||||
|
display: flex;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
#party-loading.inactive {
|
||||||
|
flex-direction: column;
|
||||||
|
text-align: center;
|
||||||
|
animation-duration: 4s;
|
||||||
|
animation-timing-function: linear;
|
||||||
|
animation-iteration-count: infinite;
|
||||||
|
animation-name: backgroundpulse;
|
||||||
|
}
|
||||||
|
#party-routes-wrapper {
|
||||||
|
margin: 0;
|
||||||
|
position: fixed;
|
||||||
|
background-color: rgb(27, 27, 27);
|
||||||
|
bottom: 0;
|
||||||
|
width: calc(var(--party-width) - 2rem);
|
||||||
|
right: var(--neg-party-width);
|
||||||
|
transition: all ease-in-out 0.3s;
|
||||||
|
height: calc(100% - 2rem);
|
||||||
|
padding: 1rem;
|
||||||
|
color: white;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
z-index: 9999;
|
||||||
|
}
|
||||||
|
#party-routes-wrapper.visible {
|
||||||
|
right: 0;
|
||||||
|
}
|
||||||
|
.party-notification-container {
|
||||||
|
z-index: 99999 !important;
|
||||||
|
display: none !important;
|
||||||
|
bottom: 0.8rem !important;
|
||||||
|
right: 1rem !important;
|
||||||
|
width: calc(var(--party-width) - 2rem) !important;
|
||||||
|
}
|
||||||
|
.party-notification-container .MuiPaper-root {
|
||||||
|
border-radius: 26px !important;
|
||||||
|
color: white;
|
||||||
|
background-color: black;
|
||||||
|
}
|
||||||
|
@keyframes showbutton {
|
||||||
|
0% {
|
||||||
|
right: 1rem;
|
||||||
|
}
|
||||||
|
50% {
|
||||||
|
transform: scale(5) translateX(-100%) translateY(-100%);
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
right: -1rem;
|
||||||
|
transform: scale(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.watch-party-fab {
|
||||||
|
z-index: 9999;
|
||||||
|
position: fixed !important;
|
||||||
|
bottom: 1rem !important;
|
||||||
|
right: -2rem !important;
|
||||||
|
border: 1px solid white;
|
||||||
|
background-color: black !important;
|
||||||
|
/* background-image: url('/android-icon-192x192.png'); */
|
||||||
|
background-image: url('chrome-extension://__MSG_@@extension_id__/android-icon-192x192.png');
|
||||||
|
background-position: center;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
background-size: 2rem;
|
||||||
|
animation-name: showbutton;
|
||||||
|
animation-iteration-count: 1;
|
||||||
|
animation-duration: 2s;
|
||||||
|
transition: all ease-in-out 0.3s !important;
|
||||||
|
}
|
||||||
|
.watch-party-fab:hover {
|
||||||
|
right: 1rem !important;
|
||||||
|
}
|
||||||
|
.watch-party-fab .fab-logo {
|
||||||
|
max-width: 75%;
|
||||||
|
max-height: 75%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.party-create-container {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
.party-create-container .brand-title {
|
||||||
|
padding-top: 1.4rem !important;
|
||||||
|
padding-left: 3.5rem !important;
|
||||||
|
}
|
||||||
|
.party-create-container .name-field {
|
||||||
|
margin-bottom: 2rem !important;
|
||||||
|
}
|
||||||
|
.party-create-container .join-card {
|
||||||
|
padding: 1rem !important;
|
||||||
|
margin-bottom: 2rem;
|
||||||
|
}
|
||||||
|
.party-create-container .join-card .card-field {
|
||||||
|
margin-bottom: 1rem !important;
|
||||||
|
}
|
||||||
|
.party-create-container .party-create-inputs {
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.party-chat-container {
|
||||||
|
display: flex;
|
||||||
|
max-height: 100%;
|
||||||
|
flex-direction: column;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.thread-container {
|
||||||
|
max-height: 100%;
|
||||||
|
flex: 1;
|
||||||
|
overflow-y: auto;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
margin-top: 1rem;
|
||||||
|
}
|
||||||
|
.room-title {
|
||||||
|
text-overflow: ellipsis !important;
|
||||||
|
word-break: break-word !important;
|
||||||
|
overflow: hidden !important;
|
||||||
|
padding-right: 1rem !important;
|
||||||
|
}
|
||||||
|
.thread-container::-webkit-scrollbar {
|
||||||
|
width: 5px;
|
||||||
|
}
|
||||||
|
.thread-container::-webkit-scrollbar-track {
|
||||||
|
background-color: rgb(90, 90, 90);
|
||||||
|
border-radius: 1rem;
|
||||||
|
}
|
||||||
|
.thread-container::-webkit-scrollbar-thumb {
|
||||||
|
background-color: rgb(118, 182, 255);
|
||||||
|
border-radius: 13px;
|
||||||
|
}
|
||||||
|
textarea::-webkit-scrollbar {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
.chat-message-box > div {
|
||||||
|
border-radius: 26px;
|
||||||
|
}
|
||||||
|
.party-chat-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
padding-left: 2.25rem;
|
||||||
|
}
|
||||||
|
.party-chat-header-text {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
.party-controls {
|
||||||
|
margin-top: 2rem;
|
||||||
|
}
|
||||||
|
.party-controls .MuiButton-startIcon {
|
||||||
|
margin-right: 0px !important;
|
||||||
|
}
|
||||||
|
.party-control-button-text {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
.party-controls button:hover .party-control-button-text {
|
||||||
|
display: initial;
|
||||||
|
}
|
||||||
|
.party-controls button:hover .MuiButton-startIcon {
|
||||||
|
margin-right: 8px !important;
|
||||||
|
}
|
||||||
|
.giphy-carousel {
|
||||||
|
margin-top: 1rem;
|
||||||
|
min-height: fit-content;
|
||||||
|
}
|
||||||
|
.giphy-carousel img {
|
||||||
|
border-radius: 1rem;
|
||||||
|
transform: scale(0.85);
|
||||||
|
transition: all ease-in-out 0.2s;
|
||||||
|
}
|
||||||
|
.giphy-carousel img:hover {
|
||||||
|
transform: scale(0.95);
|
||||||
|
}
|
||||||
|
|
||||||
|
.giphy-carousel::-webkit-scrollbar {
|
||||||
|
width: 5px;
|
||||||
|
height: 5px;
|
||||||
|
}
|
||||||
|
.giphy-carousel::-webkit-scrollbar-track {
|
||||||
|
background-color: rgb(90, 90, 90);
|
||||||
|
border-radius: 1rem;
|
||||||
|
}
|
||||||
|
.giphy-carousel::-webkit-scrollbar-thumb {
|
||||||
|
background-color: rgb(118, 182, 255);
|
||||||
|
border-radius: 13px;
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import ReactDOM from 'react-dom';
|
||||||
|
import firebase from 'firebase/app';
|
||||||
|
import App from './App';
|
||||||
|
import './index.css';
|
||||||
|
import { PLAYER_SOURCE, getPlayerSource } from './Api';
|
||||||
|
|
||||||
|
const firebaseConfig = {
|
||||||
|
apiKey: 'AIzaSyCJLuYpzXLDRmu2ttzFuSGmYcpFxqToWFU',
|
||||||
|
authDomain: 'watch-party-crx.firebaseapp.com',
|
||||||
|
databaseURL: 'https://watch-party-crx.firebaseio.com',
|
||||||
|
projectId: 'watch-party-crx',
|
||||||
|
storageBucket: 'watch-party-crx.appspot.com',
|
||||||
|
messagingSenderId: '712242707190',
|
||||||
|
appId: '1:712242707190:web:65fa7f772e30da364b0ad7',
|
||||||
|
measurementId: 'G-EZS4PEVG4T',
|
||||||
|
};
|
||||||
|
|
||||||
|
firebase.initializeApp(firebaseConfig);
|
||||||
|
|
||||||
|
const PartyWrapper = document.createElement('div');
|
||||||
|
PartyWrapper.id = 'party_wrapper';
|
||||||
|
document.body.appendChild(PartyWrapper);
|
||||||
|
|
||||||
|
switch (getPlayerSource()) {
|
||||||
|
case PLAYER_SOURCE.NETFLIX:
|
||||||
|
document.body.classList.add('netflix');
|
||||||
|
break;
|
||||||
|
case PLAYER_SOURCE.HULU:
|
||||||
|
document.addEventListener(
|
||||||
|
'keydown',
|
||||||
|
(ev) => {
|
||||||
|
if (ev.target.tagName !== 'INPUT' || ev.target.tagName !== 'TEXTAREA') {
|
||||||
|
ev.stopImmediatePropagation();
|
||||||
|
ev.stopPropagation();
|
||||||
|
} else {
|
||||||
|
ev.target.focus();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ capture: true }
|
||||||
|
);
|
||||||
|
document.body.classList.add('hulu');
|
||||||
|
const ds = document.createElement('script');
|
||||||
|
ds.text = `window.doquery=function(){window.huluPlayer=window.queryObjects(window.HuluMediaPlayer);}`;
|
||||||
|
document.head.appendChild(ds);
|
||||||
|
break;
|
||||||
|
case PLAYER_SOURCE.AMAZON:
|
||||||
|
document.body.classList.add('amazon-prime');
|
||||||
|
break;
|
||||||
|
case PLAYER_SOURCE.DISNEY:
|
||||||
|
document.body.classList.add('disney');
|
||||||
|
break;
|
||||||
|
case PLAYER_SOURCE.YOUTUBE:
|
||||||
|
document.body.classList.add('youtube');
|
||||||
|
break;
|
||||||
|
case PLAYER_SOURCE.HBONOW:
|
||||||
|
document.body.classList.add('hbo');
|
||||||
|
break;
|
||||||
|
case PLAYER_SOURCE.LOCAL:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReactDOM.render(
|
||||||
|
<React.StrictMode>
|
||||||
|
<App />
|
||||||
|
</React.StrictMode>,
|
||||||
|
PartyWrapper
|
||||||
|
);
|
||||||