├── .babelrc ├── src ├── assets │ └── css │ │ ├── App.css │ │ └── _example │ │ └── _example.css ├── index.js └── components │ └── App.js ├── docs └── images │ └── electron-react-webpack-boilerplate.png ├── .editorconfig ├── postcss.config.js ├── .gitignore ├── LICENSE ├── README.md ├── webpack.build.config.js ├── webpack.dev.config.js ├── package.json ├── main.js └── code-of-conduct.md /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "@babel/preset-react" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /src/assets/css/App.css: -------------------------------------------------------------------------------- 1 | /* Main CSS file */ 2 | 3 | @import '_example/_example.css'; 4 | -------------------------------------------------------------------------------- /src/assets/css/_example/_example.css: -------------------------------------------------------------------------------- 1 | /* Example stylesheet */ 2 | 3 | h1 { 4 | font-family: helvetica; 5 | font-size: 21px; 6 | font-weight: 200; 7 | } 8 | -------------------------------------------------------------------------------- /docs/images/electron-react-webpack-boilerplate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/olzzon/CasparCG-React-Electron-boilerplate/HEAD/docs/images/electron-react-webpack-boilerplate.png -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | 3 | root = true 4 | 5 | [*] 6 | charset = utf-8 7 | end_of_line = crlf 8 | indent_size = 2 9 | indent_style = space 10 | insert_final_newline = true 11 | trim_trailing_whitespace = true 12 | 13 | [*.md] 14 | trim_trailing_whitespace = false 15 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { render } from 'react-dom'; 3 | import App from './components/App'; 4 | 5 | // Since we are using HtmlWebpackPlugin WITHOUT a template, we should create our own root node in the body element before rendering into it 6 | let root = document.createElement('div'); 7 | 8 | root.id = 'root'; 9 | document.body.appendChild(root); 10 | 11 | // Now we can render our application into it 12 | render(, document.getElementById('root')) 13 | -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | 'postcss-cssnext': { 4 | browsers: [ 5 | 'Firefox >= 58', 6 | 'Chrome >= 62', 7 | 'ie >= 10', 8 | 'last 4 versions', 9 | 'Safari >= 9' 10 | ] 11 | }, 12 | 'postcss-import': {}, 13 | 'postcss-pxtorem': { 14 | rootValue: 16, 15 | unitPrecision: 5, 16 | propList: ['*'], 17 | selectorBlackList: ['html', 'body'], 18 | replace: true, 19 | mediaQuery: false, 20 | minPixelValue: 0 21 | }, 22 | 'postcss-nested': {} 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Build folder and files # 2 | ########################## 3 | builds/ 4 | 5 | # Development folders and files # 6 | ################################# 7 | .tmp/ 8 | dist/ 9 | node_modules/ 10 | *.compiled.* 11 | 12 | # Folder config file # 13 | ###################### 14 | Desktop.ini 15 | 16 | # Folder notes # 17 | ################ 18 | _ignore/ 19 | 20 | # Log files & folders # 21 | ####################### 22 | logs/ 23 | *.log 24 | npm-debug.log* 25 | .npm 26 | 27 | # Packages # 28 | ############ 29 | # it's better to unpack these files and commit the raw source 30 | # git has its own built in compression methods 31 | *.7z 32 | *.dmg 33 | *.gz 34 | *.iso 35 | *.jar 36 | *.rar 37 | *.tar 38 | *.zip 39 | 40 | # Photoshop & Illustrator files # 41 | ################################# 42 | *.ai 43 | *.eps 44 | *.psd 45 | 46 | # Windows & Mac file caches # 47 | ############################# 48 | .DS_Store 49 | Thumbs.db 50 | ehthumbs.db 51 | 52 | # Windows shortcuts # 53 | ##################### 54 | *.lnk 55 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Alex Devero (alexdevero.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | ## Caspar CG boilerplate 3 | If you wan´t to try out controlling CasparCG from Electron-React, this can get you started. 4 | 5 | ### A minimal CasparCG Electron NodeJS client. 6 | Using SuperflyTV CasparCG-Connection and Alex Devero boilerplate 7 | ``` 8 | https://github.com/SuperFlyTV/casparcg-connection 9 | ``` 10 | 11 | 12 | ### React-Electron boilerplate from: 13 | Minimal Electron, React and Webpack boilerplate 14 | 15 | ``` 16 | https://github.com/alexdevero/electron-react-webpack-boilerplate.git 17 | ``` 18 | 19 | ### Install: 20 | ``` 21 | git clone https://github.com/olzzon/CasparCG-React-Electron-boilerplate.git nameofyourproject 22 | cd nameofyourproject 23 | yarn 24 | ``` 25 | 26 | ### Run the app 27 | ``` 28 | yarn start 29 | ``` 30 | 31 | ### Edit your app 32 | /src/components/app.js 33 | 34 | ### Build the app (automatic) 35 | ``` 36 | yarn package 37 | ``` 38 | 39 | ### Build the app (manual) 40 | ``` 41 | yarn build 42 | ``` 43 | 44 | ### Test the app (`yarn run build`) 45 | ``` 46 | yarn prod 47 | ``` 48 | 49 | ### Code of Conduct for electron-react-webpack-boilerplate: 50 | 51 | [Contributor Code of Conduct](code-of-conduct.md). By participating in this project you agree to abide by its terms. 52 | 53 | ### License for electron-react-webpack-boilerplate: 54 | 55 | MIT © [Alex Devero](https://alexdevero.com). 56 | -------------------------------------------------------------------------------- /webpack.build.config.js: -------------------------------------------------------------------------------- 1 | const webpack = require('webpack') 2 | const path = require('path') 3 | const HtmlWebpackPlugin = require('html-webpack-plugin') 4 | const BabiliPlugin = require('babili-webpack-plugin') 5 | const MiniCssExtractPlugin = require('mini-css-extract-plugin') 6 | 7 | // Any directories you will be adding code/files into, need to be added to this array so webpack will pick them up 8 | const defaultInclude = path.resolve(__dirname, 'src') 9 | 10 | module.exports = { 11 | module: { 12 | rules: [ 13 | { 14 | test: /\.css$/, 15 | use: [ 16 | MiniCssExtractPlugin.loader, 17 | 'css-loader', 18 | 'postcss-loader' 19 | ], 20 | include: defaultInclude 21 | }, 22 | { 23 | test: /\.jsx?$/, 24 | use: [{ loader: 'babel-loader' }], 25 | include: defaultInclude 26 | }, 27 | { 28 | test: /\.(jpe?g|png|gif)$/, 29 | use: [{ loader: 'file-loader?name=img/[name]__[hash:base64:5].[ext]' }], 30 | include: defaultInclude 31 | }, 32 | { 33 | test: /\.(eot|svg|ttf|woff|woff2)$/, 34 | use: [{ loader: 'file-loader?name=font/[name]__[hash:base64:5].[ext]' }], 35 | include: defaultInclude 36 | } 37 | ] 38 | }, 39 | target: 'electron-renderer', 40 | plugins: [ 41 | new HtmlWebpackPlugin(), 42 | new MiniCssExtractPlugin({ 43 | // Options similar to the same options in webpackOptions.output 44 | // both options are optional 45 | filename: 'bundle.css', 46 | chunkFilename: '[id].css' 47 | }), 48 | new webpack.DefinePlugin({ 49 | 'process.env.NODE_ENV': JSON.stringify('production') 50 | }), 51 | new BabiliPlugin() 52 | ], 53 | stats: { 54 | colors: true, 55 | children: false, 56 | chunks: false, 57 | modules: false 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /webpack.dev.config.js: -------------------------------------------------------------------------------- 1 | const webpack = require('webpack') 2 | const path = require('path') 3 | const HtmlWebpackPlugin = require('html-webpack-plugin') 4 | const { spawn } = require('child_process') 5 | 6 | // Any directories you will be adding code/files into, need to be added to this array so webpack will pick them up 7 | const defaultInclude = path.resolve(__dirname, 'src') 8 | 9 | module.exports = { 10 | module: { 11 | rules: [ 12 | { 13 | test: /\.css$/, 14 | use: [{ loader: 'style-loader' }, { loader: 'css-loader' }, { loader: 'postcss-loader' }], 15 | include: defaultInclude 16 | }, 17 | { 18 | test: /\.jsx?$/, 19 | use: [{ loader: 'babel-loader' }], 20 | include: defaultInclude 21 | }, 22 | { 23 | test: /\.(jpe?g|png|gif)$/, 24 | use: [{ loader: 'file-loader?name=img/[name]__[hash:base64:5].[ext]' }], 25 | include: defaultInclude 26 | }, 27 | { 28 | test: /\.(eot|svg|ttf|woff|woff2)$/, 29 | use: [{ loader: 'file-loader?name=font/[name]__[hash:base64:5].[ext]' }], 30 | include: defaultInclude 31 | } 32 | ] 33 | }, 34 | target: 'electron-renderer', 35 | plugins: [ 36 | new HtmlWebpackPlugin(), 37 | new webpack.DefinePlugin({ 38 | 'process.env.NODE_ENV': JSON.stringify('development') 39 | }) 40 | ], 41 | devtool: 'cheap-source-map', 42 | devServer: { 43 | contentBase: path.resolve(__dirname, 'dist'), 44 | stats: { 45 | colors: true, 46 | chunks: false, 47 | children: false 48 | }, 49 | before() { 50 | spawn( 51 | 'electron', 52 | ['.'], 53 | { shell: true, env: process.env, stdio: 'inherit' } 54 | ) 55 | .on('close', code => process.exit(0)) 56 | .on('error', spawnError => console.error(spawnError)) 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CasparCGClient", 3 | "version": "0.1.0", 4 | "description": "Electron/React based CasparCG Client", 5 | "license": "MIT", 6 | "private": false, 7 | "repository": { 8 | "type": "git", 9 | "url": "https://github.com/olzzon/CasparCG-React-Electron-boilerplate.git" 10 | }, 11 | "author": { 12 | "name": "Kasper Olsson Hans", 13 | "email": "xxx", 14 | "url": "https://github.com/olzzon" 15 | }, 16 | "keywords": [ 17 | "app", 18 | "boilerplate", 19 | "electron", 20 | "open", 21 | "open-source", 22 | "postcss", 23 | "react", 24 | "reactjs", 25 | "source", 26 | "webpack" 27 | ], 28 | "engines": { 29 | "node": ">=9.0.0", 30 | "npm": ">=5.0.0", 31 | "yarn": ">=1.0.0" 32 | }, 33 | "main": "main.js", 34 | "scripts": { 35 | "prod": "webpack --mode production --config webpack.build.config.js && electron --noDevServer .", 36 | "start": "webpack-dev-server --hot --host 0.0.0.0 --config=./webpack.dev.config.js --mode development", 37 | "build": "webpack --config webpack.build.config.js --mode production", 38 | "package": "npm run build", 39 | "postpackage": "electron-packager ./ --out=./builds" 40 | }, 41 | "dependencies": { 42 | "casparcg-connection": "^4.5.0", 43 | "electron": "^2.0.8", 44 | "react": "^16.4.2", 45 | "react-dom": "^16.4.2" 46 | }, 47 | "devDependencies": { 48 | "@babel/core": "^7.0.0", 49 | "@babel/preset-react": "^7.0.0", 50 | "babel-loader": "^8.0.0", 51 | "babili-webpack-plugin": "^0.1.2", 52 | "css-loader": "^1.0.0", 53 | "electron-packager": "^12.1.1", 54 | "file-loader": "^2.0.0", 55 | "html-webpack-plugin": "^3.2.0", 56 | "mini-css-extract-plugin": "^0.4.2", 57 | "postcss-cssnext": "^3.1.0", 58 | "postcss-import": "^12.0.0", 59 | "postcss-loader": "^3.0.0", 60 | "postcss-nested": "^3.0.0", 61 | "postcss-pxtorem": "^4.0.1", 62 | "style-loader": "^0.23.0", 63 | "webpack": "^4.17.1", 64 | "webpack-cli": "^3.1.0", 65 | "webpack-dev-server": "^3.1.6" 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/components/App.js: -------------------------------------------------------------------------------- 1 | import '../assets/css/App.css'; 2 | import React, { Component } from 'react'; 3 | import {CasparCG} from 'casparcg-connection'; 4 | 5 | 6 | class App extends Component { 7 | constructor(props) { 8 | // Required step: always call the parent class' constructor 9 | super(props); 10 | 11 | this.ccgConnection = new CasparCG( 12 | { 13 | host: "localhost", 14 | port: 5250, 15 | autoConnect: false, 16 | }); 17 | 18 | // Set the state directly. Use props if necessary. 19 | this.state = { 20 | ccgConnectionStatus: false 21 | }; 22 | this.setConnectionStatus = this.setConnectionStatus.bind(this); 23 | } 24 | 25 | componentDidMount() { 26 | //Connect to CG server: 27 | this.ccgConnection.connect(); 28 | 29 | //Send a STOP command to get a promise for Server connection status. 30 | this.ccgConnection.stop(1, 10) 31 | .then ((connected) => { 32 | console.log("Send a STOP command to show connection: ", this.ccgConnection.connectionStatus); 33 | }); 34 | 35 | // Initialize timer connection status: 36 | var temp = setInterval(this.setConnectionStatus, 1000); 37 | console.log("Timer initiated: " + temp); 38 | } 39 | 40 | // Timer controlled connection status 41 | setConnectionStatus() { 42 | this.setState({ccgConnectionStatus: this.ccgConnection.connectionStatus.connected}); 43 | console.log("Checking connection: " + this.ccgConnection.connectionStatus.connected); 44 | } 45 | 46 | playMedia(channel, layer, mediaSource) { 47 | this.ccgConnection.play(channel, layer, mediaSource); 48 | } 49 | 50 | stopMedia(channel, layer) { 51 | this.ccgConnection.stop(channel, layer); 52 | } 53 | 54 | render() { 55 | return ( 56 |
57 |

CasparCG

58 |

Client based on SuperflyTV CasparCG-connecton

59 | Connection status: 60 | {this.state.ccgConnectionStatus ? "Connected" : "not Connected"} 61 |
62 | 65 | 68 | 69 |
70 | ) 71 | } 72 | } 73 | 74 | export default App 75 | -------------------------------------------------------------------------------- /main.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | // Import parts of electron to use 4 | const { app, BrowserWindow } = require('electron') 5 | const path = require('path') 6 | const url = require('url') 7 | 8 | // Keep a global reference of the window object, if you don't, the window will 9 | // be closed automatically when the JavaScript object is garbage collected. 10 | let mainWindow 11 | 12 | // Keep a reference for dev mode 13 | let dev = false 14 | 15 | if (process.defaultApp || /[\\/]electron-prebuilt[\\/]/.test(process.execPath) || /[\\/]electron[\\/]/.test(process.execPath)) { 16 | dev = true 17 | } 18 | 19 | // Temporary fix broken high-dpi scale factor on Windows (125% scaling) 20 | // info: https://github.com/electron/electron/issues/9691 21 | if (process.platform === 'win32') { 22 | app.commandLine.appendSwitch('high-dpi-support', 'true') 23 | app.commandLine.appendSwitch('force-device-scale-factor', '1') 24 | } 25 | 26 | function createWindow() { 27 | // Create the browser window. 28 | mainWindow = new BrowserWindow({ 29 | width: 1024, 30 | height: 768, 31 | show: false 32 | }) 33 | 34 | // and load the index.html of the app. 35 | let indexPath 36 | 37 | if (dev && process.argv.indexOf('--noDevServer') === -1) { 38 | indexPath = url.format({ 39 | protocol: 'http:', 40 | host: 'localhost:8080', 41 | pathname: 'index.html', 42 | slashes: true 43 | }) 44 | } else { 45 | indexPath = url.format({ 46 | protocol: 'file:', 47 | pathname: path.join(__dirname, 'dist', 'index.html'), 48 | slashes: true 49 | }) 50 | } 51 | 52 | mainWindow.loadURL(indexPath) 53 | 54 | // Don't show until we are ready and loaded 55 | mainWindow.once('ready-to-show', () => { 56 | mainWindow.show() 57 | 58 | // Open the DevTools automatically if developing 59 | if (dev) { 60 | mainWindow.webContents.openDevTools() 61 | } 62 | }) 63 | 64 | // Emitted when the window is closed. 65 | mainWindow.on('closed', function() { 66 | // Dereference the window object, usually you would store windows 67 | // in an array if your app supports multi windows, this is the time 68 | // when you should delete the corresponding element. 69 | mainWindow = null 70 | }) 71 | } 72 | 73 | // This method will be called when Electron has finished 74 | // initialization and is ready to create browser windows. 75 | // Some APIs can only be used after this event occurs. 76 | app.on('ready', createWindow) 77 | 78 | // Quit when all windows are closed. 79 | app.on('window-all-closed', () => { 80 | // On macOS it is common for applications and their menu bar 81 | // to stay active until the user quits explicitly with Cmd + Q 82 | if (process.platform !== 'darwin') { 83 | app.quit() 84 | } 85 | }) 86 | 87 | app.on('activate', () => { 88 | // On macOS it's common to re-create a window in the app when the 89 | // dock icon is clicked and there are no other windows open. 90 | if (mainWindow === null) { 91 | createWindow() 92 | } 93 | }) 94 | -------------------------------------------------------------------------------- /code-of-conduct.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at deveroalex@gmail.com. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]. 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | --------------------------------------------------------------------------------