Skip to content

Commit e450b8f

Browse files
authored
Merge pull request #346 from EnCiv/civ-serv
Uses Civil Server
2 parents d5539bc + 8f521fe commit e450b8f

25 files changed

+32945
-39850
lines changed

.storybook/main.js

+32-37
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,34 @@
11
const webpack = require('webpack')
22

33
module.exports = {
4-
stories: ['../stories/**/*.stories.mdx', '../stories/**/*.stories.@(js|jsx|ts|tsx)'],
5-
addons: ['@storybook/addon-links', '@storybook/addon-essentials'],
6-
framework: '@storybook/react',
7-
core: {
8-
builder: 'webpack5',
9-
},
10-
webpackFinal: async config => {
11-
// config may or may not have these properties so we have to make sure they are there and then modify them to ensure we don't delete anything
12-
if (!config.resolve) config.resolve = {}
13-
if (!config.resolve.fallback) config.resolve.fallback = {}
14-
Object.assign(config.resolve.fallback, {
15-
fs: false,
16-
buffer: require.resolve('buffer'),
17-
path: require.resolve('path-browserify'),
18-
stream: require.resolve('stream-browserify'),
19-
os: require.resolve('os-browserify/browser'),
20-
zlib: require.resolve('browserify-zlib'),
21-
constants: require.resolve('constants-browserify'),
22-
util: require.resolve('util'),
23-
})
24-
if (!config.plugins) config.plugins = []
25-
config.plugins.push(new webpack.ProvidePlugin({ Buffer: ['buffer', 'Buffer'] }))
26-
config.plugins.push(new webpack.ProvidePlugin({ process: 'process/browser' })) // fix "process is not defined" error: // (do "npm install process" before running the build)
27-
for (const plugin of config.plugins) {
28-
if (plugin.definitions) {
29-
if (plugin.definitions['process.env']) {
30-
console.info(
31-
'.storybook/main.js: deleting process.env from',
32-
{ plugin },
33-
'see comments in that file'
34-
)
35-
delete plugin.definitions['process.env']
36-
/*
4+
stories: ['../stories/**/*.stories.mdx', '../stories/**/*.stories.@(js|jsx|ts|tsx)'],
5+
addons: ['@storybook/addon-links', '@storybook/addon-essentials'],
6+
framework: '@storybook/react',
7+
core: {
8+
builder: 'webpack5',
9+
},
10+
webpackFinal: async config => {
11+
// config may or may not have these properties so we have to make sure they are there and then modify them to ensure we don't delete anything
12+
if (!config.resolve) config.resolve = {}
13+
if (!config.resolve.fallback) config.resolve.fallback = {}
14+
Object.assign(config.resolve.fallback, {
15+
fs: false,
16+
buffer: require.resolve('buffer'),
17+
path: require.resolve('path-browserify'),
18+
stream: require.resolve('stream-browserify'),
19+
os: require.resolve('os-browserify/browser'),
20+
zlib: require.resolve('browserify-zlib'),
21+
constants: require.resolve('constants-browserify'),
22+
util: require.resolve('util'),
23+
})
24+
if (!config.plugins) config.plugins = []
25+
config.plugins.push(new webpack.ProvidePlugin({ Buffer: ['buffer', 'Buffer'] }))
26+
for (const plugin of config.plugins) {
27+
if (plugin.definitions) {
28+
if (plugin.definitions['process.env']) {
29+
console.info('.storybook/main.js: deleting process.env from', { plugin }, 'see comments in that file')
30+
delete plugin.definitions['process.env']
31+
/*
3732
webpack will try to string replace process.env with what is assigned in the definition.
3833
// But if there is code in the browser side that does something like "if(process.env)" it will get replaced and cause syntax error and break the existing code
3934
@@ -48,9 +43,9 @@ module.exports = {
4843
to become
4944
if (!{"NODE_ENV":"development","NODE_PATH":["/usr/lib64/node_modules"],"STORYBOOK":"true","PUBLIC_URL":"."}) {"NODE_ENV":"development","NODE_PATH":["/usr/lib64/node_modules"],"STORYBOOK":"true","PUBLIC_URL":"."} = {};
5045
*/
51-
}
52-
}
5346
}
54-
return config
55-
},
47+
}
48+
}
49+
return config
50+
},
5651
}

app/components/ask-webrtc.jsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import injectSheet from 'react-jss'
66
import cx from 'classnames'
77

88
import DebugOverlay from './debug-overlay'
9+
import DynamicFontSizeHelmet from './dynamic-font-size-helmet'
910

1011
const TransitionTime = 500
1112
const TopMargin = '0vh'
@@ -235,7 +236,7 @@ class RASPAskWebRTC extends React.Component {
235236
constructor(props) {
236237
super(props)
237238
if (typeof window !== 'undefined') {
238-
if (window.env === 'development') this.rotateButton = true
239+
if (window?.process?.env?.NODE_ENV === 'development') this.rotateButton = true
239240
} else {
240241
if (process.env.NODE_ENV === 'development') this.rotateButton = true
241242
}
@@ -775,6 +776,7 @@ class RASPAskWebRTC extends React.Component {
775776
style={{ position: 'relative', left: this.state.left, width: '100vw' }}
776777
ref={this.fixupLeft}
777778
>
779+
<DynamicFontSizeHelmet />
778780
<DebugOverlay ref={this.debugOverlayRef} />
779781
<div className={classes['outerBox']}>
780782
{Object.keys(participants).map(videoBox)}
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Helmet } from 'react-helmet'
2+
3+
const DynamicFontSizeHelmet =
4+
typeof window === 'undefined'
5+
? () => (
6+
<Helmet
7+
script={[
8+
{
9+
type: 'text/javascript',
10+
innerHTML: `function setFontSize(){document.getElementsByTagName("html")[0].style.fontSize=Math.round(Math.min(window.innerWidth,window.innerHeight))/100*(15/(1080/100))+'px'}; addEventListener('resize',setFontSize); setFontSize();`,
11+
},
12+
]}
13+
/>
14+
)
15+
: () => null
16+
17+
export default DynamicFontSizeHelmet

app/components/lib/create-participant.js

+10
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ function allThere(array, length) {
1818
return array.length === length && array.every(i => typeof i !== 'undefined')
1919
}
2020

21+
// webpack might include process.browser but if it doesn't the pipe opertion below needs process.nextTick
22+
if (typeof window !== 'undefined') {
23+
if (typeof process === 'undefined') window.process = {}
24+
if (!process.nextTick)
25+
window.process.nextTick = (...args) => {
26+
const func = args.shift()
27+
setTimeout(() => func.apply(null, args))
28+
}
29+
}
30+
2131
export default function createParticipant(props, human, userId, name, progressFunc, listeningRound, listeningSeat) {
2232
var transferred = 0
2333
var totalSize = 0

app/web-components/candidate-conversation.jsx

+6-3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import { auto_quality, placeholder_image } from '../components/lib/cloudinary-ur
4040
import createParticipant from '../components/lib/create-participant'
4141
import BeginButton from '../components/begin-button'
4242
import DonateButton from '../components/donate-button'
43+
import DynamicFontSizeHelmet from '../components/dynamic-font-size-helmet'
4344

4445
function promiseSleep(time) {
4546
return new Promise((ok, ko) => setTimeout(ok, time))
@@ -562,7 +563,7 @@ class RASPUndebate extends React.Component {
562563
super(props)
563564
if (typeof window !== 'undefined') {
564565
this.startTime = Date.now()
565-
if (window.env === 'development') this.rotateButton = true
566+
if (window?.process?.env?.NODE_ENV === 'development') this.rotateButton = true
566567
} else {
567568
if (process.env.NODE_ENV === 'development') this.rotateButton = true
568569
}
@@ -1293,7 +1294,7 @@ class RASPUndebate extends React.Component {
12931294
preFetchObjectURL(part, speaking, round) {
12941295
if (!this.props.participants[part]) return // part may not exist in this debate
12951296

1296-
if (true /*window.env!=='production' || this.participants[part].youtube */) {
1297+
if (true /*window.process.env.NODE_ENV!=='production' || this.participants[part].youtube */) {
12971298
// in development, don'e prefetch the videos because they won't be cached by the browser and you'll end up consuming a lot of extra cloudinary bandwith, on youtube we can't prefetch
12981299
logger.trace("CandidateConversation.preFetchObjectURl - in development we don't prefetch", part, speaking, round)
12991300
this.setExternalObjectURL(part, speaking, round)
@@ -1404,7 +1405,8 @@ class RASPUndebate extends React.Component {
14041405
this.participants[part].youtubePlayer.playVideo()
14051406
} else {
14061407
let element = this.participants[part].element.current
1407-
if (element.src === objectURL) {
1408+
if (element.src === objectURL && element.loop) {
1409+
// element.loop because if there is only the moderator, and the next position is playing the same video we need to start playing it again. This is only for when the listening segment is the same for this position and the laste
14081410
return // don't change it.
14091411
}
14101412
//element.src=null;
@@ -2668,6 +2670,7 @@ class RASPUndebate extends React.Component {
26682670

26692671
return (
26702672
<div className={cx(classes['wrapper'], scrollableIframe && classes['scrollableIframe'])}>
2673+
<DynamicFontSizeHelmet />
26712674
{this.props.participants.human && <ReactCameraRecorder ref={this.getCamera} />}
26722675
<section
26732676
id="syn-ask-webrtc"

app/web-components/cc-wrapper/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import CanNotRecordHere from './can-not-record-here'
88
import ViewerRecorder from './viewer-recorder'
99
import Precheck from './precheck'
1010
import useMicCameraConstraints from './mic-camera-constraints'
11+
import DynamicFontSizeHelmet from '../../components/dynamic-font-size-helmet'
1112

1213
const pages = {
1314
CandidatePreamble: WrappedCandidatePreamble,
@@ -22,7 +23,7 @@ const PTS = Object.keys(pages).reduce((PTS, k) => ((PTS[k] = k), PTS), {}) //
2223

2324
// through an error if someone tries to get a property that isn't defined
2425
const throwIfUndefined = {
25-
get: function(obj, prop) {
26+
get: function (obj, prop) {
2627
if (prop in obj) return obj[prop]
2728
throw Error('undefined action TYPE: ' + prop)
2829
},
@@ -84,6 +85,7 @@ function CcWrapper(props) {
8485
})
8586
return (
8687
<div className={cx(classes['wrapper'], ccState.pageToShow !== PTS.ViewerRecorder && classes['scrollable'])}>
88+
<DynamicFontSizeHelmet />
8789
<Page
8890
{...props}
8991
dispatch={dispatch}

app/web-components/cc-wrapper/viewer-camera-logic.jsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ export default class ViewerRecorderLogic extends React.Component {
411411
preFetchObjectURL(part, speaking, round) {
412412
if (!this.props.participants[part]) return // part may not exist in this debate
413413

414-
if (true /*window.env!=='production' || this.props.ccState.participants[part].youtube */) {
414+
if (true /*window.process.env.NODE_ENV!=='production' || this.props.ccState.participants[part].youtube */) {
415415
// in development, don'e prefetch the videos because they won't be cached by the browser and you'll end up consuming a lot of extra cloudinary bandwith, on youtube we can't prefetch
416416
logger.trace("undebate.preFetchObjectURl - in development we don't prefetch", part, speaking, round)
417417
this.setExternalObjectURL(part, speaking, round)
@@ -509,7 +509,8 @@ export default class ViewerRecorderLogic extends React.Component {
509509
this.props.ccState.participants[part].youtubePlayer.playVideo()
510510
} else {
511511
let element = this.props.ccState.participants[part].element.current
512-
if (element.src === objectURL) {
512+
if (element.src === objectURL && element.loop) {
513+
// element.loop because if there is only the moderator, and the next position is playing the same video we need to start playing it again. This is only for when the listening segment is the same for this position and the laste
513514
return // don't change it.
514515
}
515516
//element.src=null;

app/web-components/undebate.jsx

+6-3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import { auto_quality, placeholder_image } from '../components/lib/cloudinary-ur
4242
import createParticipant from '../components/lib/create-participant'
4343
import Modal from '../components/Modal'
4444
import Icon from '../components/lib/icon'
45+
import DynamicFontSizeHelmet from '../components/dynamic-font-size-helmet'
4546

4647
function promiseSleep(time) {
4748
return new Promise((ok, ko) => setTimeout(ok, time))
@@ -639,7 +640,7 @@ class Undebate extends React.Component {
639640
super(props)
640641
if (typeof window !== 'undefined') {
641642
this.startTime = Date.now()
642-
if (window.env === 'development') this.rotateButton = true
643+
if (window?.process?.env?.NODE_ENV === 'development') this.rotateButton = true
643644
} else {
644645
if (process.env.NODE_ENV === 'development') this.rotateButton = true
645646
}
@@ -1490,7 +1491,7 @@ class Undebate extends React.Component {
14901491
preFetchObjectURL(part, speaking, round) {
14911492
if (!this.props.participants[part]) return // part may not exist in this debate
14921493

1493-
if (true /*window.env!=='production' || this.participants[part].youtube */) {
1494+
if (true /*window.process.env.NODE_ENV!=='production' || this.participants[part].youtube */) {
14941495
// in development, don'e prefetch the videos because they won't be cached by the browser and you'll end up consuming a lot of extra cloudinary bandwith, on youtube we can't prefetch
14951496
logger.trace("undebate.preFetchObjectURl - in development we don't prefetch", part, speaking, round)
14961497
this.setExternalObjectURL(part, speaking, round)
@@ -1587,7 +1588,8 @@ class Undebate extends React.Component {
15871588
this.participants[part].youtubePlayer.playVideo()
15881589
} else {
15891590
let element = this.participants[part].element.current
1590-
if (element.src === objectURL) {
1591+
if (element.src === objectURL && element.loop) {
1592+
// element.loop because if there is only the moderator, and the next position is playing the same video we need to start playing it again. This is only for when the listening segment is the same for this position and the laste
15911593
return // don't change it.
15921594
}
15931595
//element.src=null;
@@ -3169,6 +3171,7 @@ class Undebate extends React.Component {
31693171
style={{ fontSize: fontSize }}
31703172
className={cx(classes['wrapper'], scrollableIframe && classes['scrollableIframe'])}
31713173
>
3174+
<DynamicFontSizeHelmet />
31723175
{isPortraitPhoneRecording ? (
31733176
<Modal
31743177
render={() => (

build.sh

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/bash
2+
3+
#*************************************************************************'
4+
# These directoies need to exist in dist, even if you don't have them in your project
5+
# *************************************************************************'
6+
7+
mkdir -p dist/events
8+
mkdir -p dist/routes
9+
mkdir -p dist/socket-apis
10+
mkdir -p dist/data-components
11+
mkdir -p dist/web-components
12+
#
13+
# assets is where static files go
14+
#
15+
mkdir -p ./assets/js/
16+
# you can start with the favicon images from civil-server - but you should to replace them with your own some day
17+
mkdir -p ./assets/images
18+
cp -rp node_modules/civil-server/assets/images ./assets/images
19+
20+
#
21+
# Update/create web-components/index.js to require all react components in that director, and in the listed child/peer directories. Web components are used by the getIota route - which uses reactServerRender
22+
#
23+
react-directory-indexer app/web-components/ node_modules/civil-server/dist/web-components/ || {
24+
echo Could not build web-components
25+
exit 1
26+
}
27+
#
28+
# Update/create data-components/index.js to require all data-components in that director, and in the listed child/peer directories. Data components are used by the getIota route.
29+
#
30+
react-directory-indexer --data app/data-components/ node_modules/civil-server/dist/data-components/ || {
31+
echo Could not build data-components
32+
exit 1
33+
}
34+
35+
npm run svgr || {
36+
echo Could not svgr
37+
exit 1
38+
}
39+
40+
npm run transpile || {
41+
echo Could not transpile;
42+
exit 1
43+
}
44+
45+
# don't run webpack if this is a dependency of another project - the memory usage will blow out heroku build
46+
if test \"$NPM_PROJECT\" = \"\" || test \"$NPM_PROJECT\" == \"undebate\" ; then {
47+
npm run packbuild || {
48+
echo Could not webpack;
49+
exit 1
50+
}
51+
}; fi
52+
53+

cypress.json

-3
This file was deleted.

cypress/README.md

-19
This file was deleted.

cypress/fixtures/example.json

-5
This file was deleted.

cypress/fixtures/profile.json

-5
This file was deleted.

0 commit comments

Comments
 (0)