Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinatown committed Aug 11, 2017
0 parents commit 79ec8b8
Show file tree
Hide file tree
Showing 5 changed files with 228 additions and 0 deletions.
106 changes: 106 additions & 0 deletions DialServer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
const dial = require("peer-dial");
const http = require('http');
const express = require('express');
const { spawn } = require('child_process');
const ipc = require('node-ipc');
ipc.config.id = 'screenCastDIAL';
ipc.config.retry = 1000;
const app = express();
const server = http.createServer(app);
const PORT = 8569;
// var PORT = 8080;
const MANUFACTURER = "Kevin Townsend";
const MODEL_NAME = "DIAL Server";
var child = null;

var apps = {
"YouTube": {
name: "YouTube",
state: "stopped",
allowStop: true,
pid: null,
launch: function (launchData, config) {
var url = "http://www.youtube.com/tv?"+launchData;
child = spawn('npm', ['start', url, config.position, config.width, config.height], {
cwd: 'modules/MMM-Screencast'
})
child.stdout.on('data', function(data) {
console.log('screencast stdout: ' + data);
});
child.stderr.on('data', function(data) {
console.log('screencast stderr: ' + data);
});
child.on('close', function(code) {
console.log('closing code: ' + code);
});
}
}
};

var dialServer = new dial.Server({
corsAllowOrigins: true,
expressApp: app,
port: PORT,
prefix: "/dial",
manufacturer: MANUFACTURER,
modelName: MODEL_NAME,
launchFunction: null,
electronConfig: {},
delegate: {
getApp: function(appName){
var app = apps[appName];
return app;
},

launchApp: function(appName,lauchData,callback){
var app = apps[appName];
var pid = null;
if (app) {
app.pid = "run";
app.state = "starting";
app.launch(lauchData, dialServer.electronConfig);
app.state = "running";
}
callback(app.pid);
},

stopApp: function(appName,pid,callback){
console.log("Got request to stop", appName," with pid: ", pid);

var app = apps[appName];
if (app && app.pid == pid) {
app.pid = null;
app.state = "stopped";
ipc.connectTo('screenCastWindow',() => {
ipc.of.screenCastWindow.on('connect',() => {
ipc.of.screenCastWindow.emit('quit');
});
ipc.of.screenCastWindow.on('quit', () => {
ipc.disconnect('screenCastWindow');
});
});
child = null;
callback(true);
}
else {
callback(false);
}
}
}
});

var App = function() {
this.config = {};
this.server = http.createServer(app);

this.start = function(config) {
dialServer.electronConfig = config;
this.server.listen(PORT,function(){
dialServer.start();
console.log("DIAL Server is running on PORT "+PORT);
});
};

};

module.exports = new App();
25 changes: 25 additions & 0 deletions MMM-Screencast.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* global Module */

/* Magic Mirror
* Module: MMM-Screencast
*
* By Kevin Townsend
* MIT Licensed.
*/

Module.register("MMM-Screencast", {

requiresVersion: "2.1.0", // Required version of MagicMirror

start: function() {
Log.info("Starting module: " + this.name);
this.sendSocketNotification('SET_CONFIG', this.config);
// this.getYoutube();
},

getDom: function() {
// load fake div
const div = document.createElement("div");
return div;
}
});
51 changes: 51 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const electron = require('electron');
const Positioner = require('electron-positioner');
const ipc = require('node-ipc');
ipc.config.id = 'screenCastWindow';
ipc.config.retry= 1500;

const url = process.argv[2];
const position = process.argv[3]
const width = parseInt(process.argv[4], 10)
const height = parseInt(process.argv[5], 10)

ipc.serve(() => {
ipc.server.on('quit', (data, socket) => {
ipc.server.emit(socket, 'quit');
app.quit();
process.exit();
});
});

ipc.server.start();
const app = electron.app;

app.once('ready', function () {
const windowOptions = {
maxHeight: height,
maxWidth: width,
resize: false,
width: width,
height: height,
darkTheme: true,
alwayOnTop: true,
show: false,
frame: false,
zoomFactor: 1.0,
};

const screenCastWindow = new electron.BrowserWindow(windowOptions);

const positioner = new Positioner(screenCastWindow)
positioner.move(position)

screenCastWindow.loadURL(url)

// Show window when page is ready
screenCastWindow.once('ready-to-show', function () {
screenCastWindow.show();
screenCastWindow.focus();
});

});

19 changes: 19 additions & 0 deletions node_helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = NodeHelper.create({
dialServer: require("./DialServer.js"),
config: {},

start: function() {
},

socketNotificationReceived: function(notification, payload) {
console.log(notification, payload);
switch (notification) {
case 'SET_CONFIG':
this.config = payload;
this.dialServer.start(payload);
break;
default:
break;
}
}
});
27 changes: 27 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "MagicMirror-Screencast",
"version": "1.1.0",
"description": "A module to cast to videos to a Magic Mirror",
"license": "MIT",
"devDependencies": {
"grunt": "latest",
"grunt-eslint": "latest",
"grunt-jsonlint": "latest",
"grunt-markdownlint": "^1.0.13",
"grunt-stylelint": "latest",
"grunt-yamllint": "latest",
"stylelint-config-standard": "latest",
"time-grunt": "latest"
},
"main": "app.js",
"scripts": {
"start": "electron app.js"
},
"dependencies": {
"child_process": "^1.0.2",
"electron": "^1.6.11",
"electron-positioner": "^3.0.0",
"node-ipc": "^9.1.0",
"peer-dial": "0.0.7"
}
}

0 comments on commit 79ec8b8

Please sign in to comment.