Skip to content

Commit

Permalink
mdns changes, monitor initial values,, removed electron remote
Browse files Browse the repository at this point in the history
  • Loading branch information
jrviz committed Aug 3, 2021
1 parent ebdd461 commit 02958ca
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 38 deletions.
18 changes: 13 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
<script>

const ipc = require('electron').ipcRenderer;
const remote = require('electron').remote;
//const remote = require('electron').remote;
const { shell } = require('electron')

const config = require('./config');

const marked = require("marked");
const helpFile = './help.md';

const fs = require('fs')
const { readFile } = require('fs')
const package_json = require('./package.json');

var propresenter_status = 'disconnected';
Expand Down Expand Up @@ -227,7 +227,7 @@

$("body").tooltip({ selector: '[data-toggle=tooltip]' });

fs.readFile(helpFile, 'utf8' , (err, data) => {
readFile(helpFile, 'utf8' , (err, data) => {
if (err) {
console.error(err);
return;
Expand Down Expand Up @@ -360,6 +360,9 @@
config.set('companionIP', $('#txtCompanionIP').val());
}

function mdnsRescan() {
ipc.send('mdns_rescan');
}

function openAuthor() {
shell.openExternal('http://techministry.blog');
Expand Down Expand Up @@ -580,12 +583,17 @@ <h2>Created by <a href="#" onclick="openAuthor();">techministry.blog</a></h2><h3
<section>
<div class='horizontal-line'></div>
<div class='row'>
<div class='form-group col-md-2'>
<div class='form-group col-md-1'>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#helpModal">
Help
</button>
</div>
<div class='form-group col-md-3'><b>Show at start-up: </b></div>
<div class='form-group col-md-2'>
<div class="text-right">
<button type="button" id="btnSave" class="btn btn-info" data-toggle="tooltip" data-placement="top" title="Re-scan mdns" onclick='mdnsRescan();'>mdns</button>
</div>
</div>
<div class='form-group col-md-2'><b>At start-up:</b></div>
<div class='form-group col-md-2'>
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input" id="switchSettings" onClick="switch_enable('settings');">
Expand Down
39 changes: 31 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ const WebSocket = require('ws');

//mdns variables
const mdns = require('mdns-js');
var mdns_browser_propresenter = null; //mdns browser variable
var mdns_browser_midirelay = null; //mdns browser variable
var mdns_window_timer = undefined;
var mdns_browser_propresenter = undefined; //mdns browser variable
var mdns_browser_midirelay = undefined; //mdns browser variable
var mdns_propresenter_hosts = []; //global array of found hosts through mdns
var mdns_midirelay_hosts = []; //global array of found hosts through mdns

//ProPresenter variables
var propresenter_socket = null;
var propresenter_socket = undefined;
var propresenter_status = 'disconnected';
var propresenter_cs = '';
var propresenter_csn = '';
Expand Down Expand Up @@ -155,7 +156,7 @@ const createsettingsWindow = async () => {
height: 825,
webPreferences: {
nodeIntegration: true,
enableRemoteModule: true
//enableRemoteModule: true
}
});

Expand Down Expand Up @@ -198,7 +199,7 @@ const createmonitorWindow = async () => {
height: 800,
webPreferences: {
nodeIntegration: true,
enableRemoteModule: true
//enableRemoteModule: true
}
});

Expand Down Expand Up @@ -230,6 +231,7 @@ const openMonitor = async () => {
}
else {
monitorWindow = await createmonitorWindow();
monitorWindow.show();
}
}

Expand Down Expand Up @@ -296,10 +298,19 @@ function buildTray() {
tray.setContextMenu(trayContextMenu);
}

function mdns_close_browsers(){
mdns_browser_propresenter.stop();
mdns_browser_midirelay.stop();

mdns_browser_propresenter = undefined;
mdns_browser_midirelay = undefined;
}

function findHosts() {

mdns_browser_propresenter = mdns.createBrowser(mdns.tcp('pro7stagedsply'));
mdns_browser_midirelay = mdns.createBrowser(mdns.tcp('midi-relay'));
//mdns_browser_midirelay = mdns.createBrowser();
mdns_window_timer = setTimeout(mdns_close_browsers, 5000)

mdns_browser_propresenter.on('ready', function onReady() {
mdns_browser_propresenter.discover();
Expand Down Expand Up @@ -382,6 +393,7 @@ function mdns_midirelay_addhost(host, ip, port) {
console.log('mdns hosts', mdns_midirelay_hosts);
}


function propresenter_connect() {
let ip = config.get('propresenterIP');
let port = config.get('propresenterPort');
Expand Down Expand Up @@ -413,7 +425,6 @@ function propresenter_connect() {

propresenter_socket.on('message', function(message) {
// Handle the stage display message received from ProPresenter
console.log('PP message:' + message)
handleStageDisplayMessage(message);
});

Expand All @@ -435,6 +446,7 @@ function propresenter_connect() {
propresenter_socket.on('close', function(code, reason) {
console.log('ProPresenter disconnected.');
//console.log('Current State: ' + propresenter_status);

if (propresenter_status !== 'force_disconnected') {
setTimeout(propresenter_reconnect, 5000); //attempt to reeconnect until the user forces it to stop
}
Expand Down Expand Up @@ -894,6 +906,10 @@ function sendHttpMessage(httpObj) {

function createCompanionConnection() {
if (config.get('plugin_companion')) {
if (companionClient !== undefined){
companionClient.destroy()
companionClient = undefined
}
companionClient = new net.createConnection(51234, config.get('companionIP'));
console.log('Connecting to Companion.');

Expand Down Expand Up @@ -946,6 +962,9 @@ function SendStatusMessage() {
//IPCs
ipcMain.on('propresenter_status', function (event) {
event.sender.send('propresenter_status', propresenter_status);
});

ipcMain.on('monitor_status', function (event) {
event.sender.send('cs', propresenter_cs);
event.sender.send('csn', propresenter_csn);
event.sender.send('ns', propresenter_ns);
Expand All @@ -960,6 +979,10 @@ ipcMain.on('mdns_midirelay_hosts', function (event) {
event.sender.send('mdns_midirelay_hosts', mdns_midirelay_hosts);
});

ipcMain.on('mdns_rescan', function (event) {
findHosts();
});

ipcMain.on('propresenter_connect', function (event, ip, port, password) {
propresenter_disconnect(false);
propresenter_status = 'connecting';
Expand All @@ -971,7 +994,7 @@ ipcMain.on('propresenter_disconnect', function (event) {
propresenter_disconnect(false);
});

ipcMain.on('propresenter_disconnect', function (event) {
ipcMain.on('propresenter_force_disconnect', function (event) {
propresenter_disconnect(false);
});

Expand Down
33 changes: 9 additions & 24 deletions monitor.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
<script>

const ipc = require('electron').ipcRenderer;
const remote = require('electron').remote;
//const remote = require('electron').remote;
const { shell } = require('electron')

const config = require('./config');

const marked = require("marked");
const helpFile = './help.md';
//const marked = require("marked");
//const helpFile = './help.md';

const fs = require('fs')
//const fs = require('fs')

ipc.on('cs', function(event, cs) {
$('#divCurrentSlide').html(cs.replace(/\n/g, '<br />'));
Expand All @@ -37,6 +37,11 @@
ipc.on('nsn', function(event, nsn) {
processSlideNotes('nsn', nsn);
});

$( document ).ready(function() {
ipc.send('monitor_status');
});

function processSlideNotes(type, text) {
switch(type) {
case 'csn':
Expand Down Expand Up @@ -276,26 +281,6 @@ <h2>Created by <a href="#" onclick="openAuthor();">techministry.blog</a></h2>
<div class='row'><b>Next Slide:</b></div>
<div class='row' style='height: 150px;border: #eeeeee 1px solid;' id='divNextSlide'></div>
<div class='row' id='divNextSlideNotes'></div>

<div class="modal fade" id="helpModal" tabindex="-1" role="dialog" aria-labelledby="helpModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="helpModalLabel">Help</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body" id='divHelpBody'>

</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<footer></footer>
</div>
</body>
</html>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "presentationbridge-client",
"productName": "PresentationBridge Client",
"version": "1.0.4",
"version": "1.0.5",
"description": "Links data from your Presentation/lyrics software to other software.",
"license": "MIT",
"repository": "josephdadams/presentationbridge-client",
Expand Down

0 comments on commit 02958ca

Please sign in to comment.