Cleanup. Fixed bug in casparcg client. Replaced browserify and babelify with asbundle. Updated all packages.

This commit is contained in:
Jonatan Nilsson 2020-04-05 05:12:55 +00:00
parent 71ac85ab7f
commit 653ac2dba0
13 changed files with 2684 additions and 4491 deletions

View file

@ -13,6 +13,7 @@ WORKDIR $HOME
RUN apk add --no-cache make gcc g++ python && \
npm install && \
apk del make gcc g++ python && \
npm run build
###########################

View file

@ -1,8 +1,7 @@
import Settings from '../settings/model'
import { address } from 'ip'
import { CasparCG, AMCP } from 'casparcg-connection'
const timeoutDuration = 60000
const timeoutDuration = 5000
let io
let logger
@ -10,7 +9,6 @@ let logger
let connection
let casparIsPlaying
let casparIsConnected
let checkTimeout
let currentHost
export async function initialise(log, socket) {
@ -36,27 +34,23 @@ export async function connect() {
queueMode: 2,
autoReconnectInterval: timeoutDuration,
onError: err => {
logger.error('CasparCG: Error', err.message)
logger.error(err, 'CasparCG: Error')
},
onConnectionStatus: data => {
casparIsConnected = data.connected
if (!data.connected) {
casparIsPlaying = false
logger.warn('CasparCG: connection closed, retrying in 60 seconds', connection.connected)
if (!casparIsConnected) {
logger.warn(`CasparCG: connection down, retrying in ${timeoutDuration / 1000} seconds`)
io.emit('casparcg.status', currentStatus())
if (checkTimeout) clearInterval(checkTimeout)
checkTimeout = null
}
},
onConnected: async connected => {
logger.info('CasparCG: connected', connected)
io.emit('casparcg.status', currentStatus())
checkClientPlaying(false, true)
// Run our check on hourly interval
if (checkTimeout) clearInterval(checkTimeout)
checkTimeout = setInterval(() => checkClientPlaying(), timeoutDuration * 60)
if (!casparIsPlaying) {
startPlaying().then()
} else {
logger.warn('CasparCG: Stopped from starting play again.')
}
},
})
}
@ -69,52 +63,40 @@ export function currentStatus(e) {
}
}
export async function checkClientPlaying(starting = false, first = false) {
let ip
if (currentHost === 'localhost' || currentHost === '127.0.0.1') {
ip = 'localhost'
} else {
ip = address()
}
export async function startPlaying() {
let ip = 'localhost'
// Check if we lost connection while attempting to start playing
if (!connection.connected) {
logger.error('CasparCG: Attempted to play but connection was lost')
}
let success = false
try {
// Check if we're already playing
let output = await connection.info(1, 100)
if (output.response.data.status !== 'playing') {
casparIsPlaying = false
if (starting) {
// We are not playing, check to see if we've already attempted
// to issue a play command and delay trying for a minute
await new Promise(res => {
logger.warn('CasparCG: Play did not start playing, retrying in 60 seconds')
setTimeout(res, timeoutDuration)
})
}
// Send a play command and retry checking again
logger.info(`CasparCG: Sending play command for ${ip}:3000`)
await connection.do(new AMCP.CustomCommand(`PLAY 1-100 [HTML] "http://${ip}:3000/client.html" CUT 1 LINEAR RIGHT`))
return checkClientPlaying(true)
// Send a play command
let command = `PLAY 1-100 [HTML] "http://${ip}:3000/client.html" CUT 1 LINEAR RIGHT`
logger.info(`CasparCG Command: ${command}`)
await connection.do(new AMCP.CustomCommand(command))
success = true
} catch (e) {
// Weird error where it throws an error despite a successful play command on reconnect
if (e && e.responseProtocol && e.responseProtocol.code >= 200 && e.responseProtocol.code < 300) {
success = true
} else {
logger.error(e, 'CasparCG: Error starting play on client')
}
}
if (success) {
casparIsPlaying = true
// We are playing, notify all clients
io.emit('casparcg.status', currentStatus())
if (starting || first) {
logger.info('CasparCG: client is up and playing')
}
} catch (e) {
logger.info('CasparCG: client is up and playing')
} else {
// Unknown error occured
casparIsPlaying = true
logger.error(e, 'CasparCG: Error starting play on client')
casparIsPlaying = false
io.emit('casparcg.status', currentStatus(e))
}
}

8
app/client.js Normal file

File diff suppressed because one or more lines are too long

View file

@ -1,5 +1,4 @@
var io = require('socket.io-client')
var io = require('./client')
var socket = io()
module.exports = socket

View file

@ -1,7 +1,7 @@
* {
-webkit-box-sizing: border-box;
box-sizing:border-box; /* This sets all elements to be the actual set dimensions, disregarding padding and borders */
/* -webkit-backface-visibility: hidden; /* Hide the backface of elements - useful for 3d effects */
/* -webkit-backface-visibility: hidden; */ /* Hide the backface of elements - useful for 3d effects */
-webkit-transition: translate3d(0,0,0); /* Turns on hardware acceleration - not known to be of benefit in CCG, but won't hurt */
}
html, body {
@ -25,7 +25,7 @@ body {
body {
font-family: Arial;
font-weight: normal;
text-shadow: 0px 0px 0px #000000;
/* text-shadow: 0px 0px 0px #000000; */
font-size: 22pt;
}
html {

View file

@ -294,6 +294,14 @@ $header-color = #777777;
}
}
textarea#graphic-html {
min-height: 150px;
}
textarea#graphic-css {
min-height: 400px;
}
input[type=submit] {
margin-top: 0.6em;
border: none;

View file

@ -5,7 +5,7 @@
"host": "0.0.0.0"
},
"bunyan": {
"name": "keywe",
"name": "caspar",
"streams": [{
"stream": "process.stdout",
"level": "debug"

View file

@ -1,3 +0,0 @@
{
"ignore": ["app/*", "public/*"]
}

7004
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -4,29 +4,19 @@
"description": "CasparCG superimposed graphics project",
"main": "index.js",
"scripts": {
"build:styl": "stylus -m app/styl/main.styl --out public",
"watch:styl": "stylus -w -m app/styl/main.styl --out public",
"build-client:styl": "stylus -m app/styl/client.styl --out public",
"watch-client:styl": "stylus -w -m app/styl/client.styl --out public",
"build-status:styl": "stylus -m app/styl/status.styl --out public",
"watch-status:styl": "stylus -w -m app/styl/status.styl --out public",
"watch:js": "watchify -t babelify app/main/index.js -o public/main.js --debug",
"build:js": "browserify app/main/index.js -o public/main.js --debug -t [ babelify ]",
"watch-client:js": "watchify -t babelify app/client/index.js -o public/client.js --debug",
"build-client:js": "browserify app/client/index.js -o public/client.js --debug -t [ babelify ]",
"watch-status:js": "watchify -t babelify app/status/index.js -o public/status.js --debug",
"build-status:js": "browserify app/status/index.js -o public/status.js --debug -t [ babelify ]",
"watch:server": "nodemon index.js",
"build:styl": "stylus -m app/styl/main.styl --out public && stylus -m app/styl/client.styl --out public && stylus -m app/styl/status.styl --out public",
"watch:styl": "stylus -w -m app/styl/main.styl app/styl/client.styl app/styl/status.styl --out public",
"build:js": "asbundle app/main/index.js ../../../public/main.js && asbundle app/client/index.js public/client.js && asbundle app/status/index.js ../../public/status.js",
"watch:js": "nodemon --watch app --exec \"npm run build:js\"",
"watch:server": "nodemon --watch api index.js | bunyan -o short",
"start": "node index.js",
"start:win": "node index.js | bunyan",
"dev-run": "run-p watch:js watch-client:js watch-status:js watch:server watch:styl watch-client:styl watch-status:styl",
"dev": "run-p watch:styl watch:js watch:server",
"prod-run": "npm run build:js && npm run build-client:js && npm run build-status:js && npm run build:styl && npm run build-client:styl && npm run build-status:styl && npm start",
"build": "npm run build:js && npm run build-client:js && npm run build-status:js && npm run build:styl && npm run build-client:styl && npm run build-status:styl",
"test": "env NODE_ENV=test mocha --require babel-register --recursive --reporter dot",
"docker": "docker run -it --rm --name my-running-script -v \"$PWD\":/usr/src/app -w /usr/src/app node:alpine",
"docker:test": "npm run docker -- npm install && npm run test",
"docker:dev": "npm run docker -- npm install && npm run dev-run",
"docker:run": "npm run docker -- npm install && npm run prod-run"
"build": "npm run build:js && npm run build:styl",
"docker": "docker run -it --rm --name my-running-script -p 3000:3000 -v \"%cd%\":/usr/src/app -w /usr/src/app node",
"docker:install": "npm run docker -- npm install",
"docker:dev": "npm run docker -- npm run dev"
},
"repository": {
"type": "git",
@ -48,28 +38,24 @@
"babel-register": "^6.26.0",
"bookshelf": "^0.11.1",
"bunyan": "^1.8.12",
"casparcg-connection": "4.1.0",
"casparcg-connection": "4.9.0",
"ip": "^1.1.5",
"knex": "^0.12.9",
"koa": "^2.4.1",
"koa-better-serve": "^2.0.7",
"koa-socket": "^4.4.0",
"nconf": "^0.9.1",
"socket.io": "^2.0.4",
"sqlite3": "^3.1.13"
"socket.io": "^2.3.0",
"sqlite3": "^4.1.1",
"tslib": "^1.11.1"
},
"devDependencies": {
"babelify": "^8.0.0",
"browserify": "^16.2.2",
"asbundle": "^2.6.0",
"dragula": "^3.7.2",
"eslint": "^4.16.0",
"eslint-plugin-mocha": "^4.11.0",
"mithril": "^1.1.5",
"mocha": "^4.0.1",
"nodemon": "^1.12.1",
"npm-run-all": "^4.1.2",
"socket.io-client": "^2.0.4",
"stylus": "^0.54.5",
"watchify": "^3.9.0"
"nodemon": "^2.0.2",
"run-p": "0.0.0",
"stylus": "^0.54.7"
}
}

View file

@ -2,7 +2,8 @@
-webkit-box-sizing: border-box;
box-sizing: border-box;
/* This sets all elements to be the actual set dimensions, disregarding padding and borders */
/* -webkit-backface-visibility: hidden; /* Hide the backface of elements - useful for 3d effects */
/* -webkit-backface-visibility: hidden; */
/* Hide the backface of elements - useful for 3d effects */
-webkit-transition: translate3d(0, 0, 0); /* Turns on hardware acceleration - not known to be of benefit in CCG, but won't hurt */
}
html,
@ -33,7 +34,7 @@ body {
body {
font-family: Arial;
font-weight: normal;
text-shadow: 0px 0px 0px #000;
/* text-shadow: 0px 0px 0px #000000; */
font-size: 22pt;
}
html {

View file

@ -1 +1 @@
{"version":3,"sources":["../app/styl/client.styl"],"names":[],"mappings":"AAAA;EACE,oBAAoB,WAApB;EACA,YAAW,WAAX;AAA4C;AAC7C;EACC,oBAAqC,qBAArC;AAA4C;;AAE9C;AAAM;EACJ,OAAM,OAAN;AAAyD;EACzD,QAAO,OAAP;AAAyD;EACzD,QAAO,EAAP;AAAyD;EACzD,SAAQ,EAAR;AAAyD;EACzD,YAAW,YAAX;AAAyD;EACzD,UAAS,OAAT;AAAyD;EACzD,wBAAuB,uBAAvB;AAAyD;;AAE3D;EACE,aAAoB,eAApB;EACA,WAAW,KAAX;EACA,OAAO,KAAP;AACA;;;;AAKF;EACE,aAAa,MAAb;EACA,aAAa,OAAb;EACA,aAAa,iBAAb;EACA,WAAW,KAAX;;AAEF;EACE,UAAU,KAAV;;AAEF;EAEE,UAAU,SAAV;;AAGF;EACE,SAAS,EAAT;EACA,YAAY,WAAZ;;AAGF;EACE,SAAS,EAAT;EACA,YAAY,WAAZ","file":"client.css"}
{"version":3,"sources":["../app/styl/client.styl"],"names":[],"mappings":"AAAA;EACE,oBAAoB,WAApB;EACA,YAAW,WAAX;AAA4C;AAC7C;AAAiD;EAChD,oBAAoB,qBAApB;AAA4C;;AAE9C;AAAM;EACJ,OAAM,OAAN;AAAyD;EACzD,QAAO,OAAP;AAAyD;EACzD,QAAO,EAAP;AAAyD;EACzD,SAAQ,EAAR;AAAyD;EACzD,YAAW,YAAX;AAAyD;EACzD,UAAS,OAAT;AAAyD;EACzD,wBAAuB,uBAAvB;AAAyD;;AAE3D;EACE,aAAoB,eAApB;EACA,WAAW,KAAX;EACA,OAAO,KAAP;AACA;;;;AAKF;EACE,aAAa,MAAb;EACA,aAAa,OAAb;AACA;EACA,WAAW,KAAX;;AAEF;EACE,UAAU,KAAV;;AAEF;EAEE,UAAU,SAAV;;AAGF;EACE,SAAS,EAAT;EACA,YAAY,WAAZ;;AAGF;EACE,SAAS,EAAT;EACA,YAAY,WAAZ","file":"client.css"}

View file

@ -1,9 +0,0 @@
git pull
START openbrowser.bat
CALL npm install
CALL npm run build
CALL npm run start:win
echo.
echo EXITED
echo.
PAUSE