Skip to content

Commit

Permalink
Expose serial-ports option 🦾🤖
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminbarbe committed May 15, 2024
1 parent a4eeb8d commit e0878e1
Show file tree
Hide file tree
Showing 7 changed files with 502 additions and 51 deletions.
27 changes: 13 additions & 14 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
{
"env": {
"browser": true,
"es2021": true
},
"extends": [
"airbnb-base"
],
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module"
},
"rules": {
"no-restricted-syntax": "off"
}
"env": {
"browser": true,
"es2021": true
},
"extends": ["airbnb-base"],
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module"
},
"rules": {
"no-restricted-syntax": "off",
"operator-linebreak": "off"
}
}
10 changes: 5 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ name: Build

on:
push:
branches: [ "master" ]
branches: ['master']
pull_request:
branches: [ "master" ]
branches: ['master']
schedule:
- cron: "0 0 1 * *"
- cron: '0 0 1 * *'

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -20,7 +20,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: "16"
node-version: '16'
- name: Install dependencies
run: npm install
- name: Download new certs
Expand Down
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"tabWidth": 2,
"useTabs": false,
"singleQuote": true
"singleQuote": true,
"trailingComma": "all"
}
64 changes: 41 additions & 23 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,27 @@ const crypto = require('crypto');
const { program } = require('commander');

const { networkInterfaces } = require('os');
const { Bonjour } = require('bonjour-service');
// const { Bonjour } = require('bonjour-service');

program
.name('shared-schema')
.option('-k, --key <file>')
.option('-c, --cert <file>');
.option('-c, --cert <file>')
.option(
'-s, --serial-inspect [ports]',
'enable serial port inspection with optional list of ports',
undefined,
)
.option(
'-d, --delimiter <delimiter>',
'delimiter for serial port data',
'\n',
);

program.parse();

let { key: keyPath, cert: certPath } = program.opts();
const { serialInspect, delimiter } = program.opts();

if (!keyPath) {
keyPath = path.join(__dirname, 'certs/privkey.pem');
Expand All @@ -41,9 +52,11 @@ const { Server } = require('socket.io');

const debugServer = require('debug')('SERVER');
const debugClient = require('debug')('CLIENT');
const debugBonjour = require('debug')('BONJOUR');
// const debugBonjour = require('debug')('BONJOUR');
const jsondiffpatch = require('jsondiffpatch').create();

const { setupSerialPorts } = require('./src/serialManager');

const NUMERIC_DIFFERENCE = -8;
const PORT = process.env.PORT || 3000;
const PORT_HTTPS = process.env.PORT_HTTPS || 3443;
Expand Down Expand Up @@ -127,30 +140,35 @@ const printAdressesFromInterfaces = () => {
}
if (serverHttps) {
debugServer(
`listening on wss://${cert.subject.replace('CN=', '')}:${PORT_HTTPS}`
`listening on wss://${cert.subject.replace('CN=', '')}:${PORT_HTTPS}`,
);
}
};

const advertiseServer = () => {
const instance = new Bonjour(undefined, (e) => {
if (e) {
debugBonjour('error', e);
}
});
instance.publish({
name: 'PandaSuite Shared Schema',
type: 'http',
port: PORT,
});
if (serverHttps) {
instance.publish({
name: 'PandaSuite Shared Schema',
type: 'https',
port: PORT_HTTPS,
});
}
};
// const advertiseServer = () => {
// const instance = new Bonjour(undefined, (e) => {
// if (e) {
// debugBonjour('error', e);
// }
// });
// instance.publish({
// name: 'PandaSuite Shared Schema',
// type: 'http',
// port: PORT,
// });
// if (serverHttps) {
// instance.publish({
// name: 'PandaSuite Shared Schema',
// type: 'https',
// port: PORT_HTTPS,
// });
// }
// };

printAdressesFromInterfaces();
// advertiseServer();

if (serialInspect !== undefined) {
const ports = serialInspect.split(',');
setupSerialPorts(schema, io, delimiter, ports);
}

0 comments on commit e0878e1

Please sign in to comment.