nep-cli 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/image.html ADDED
@@ -0,0 +1,57 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+
4
+ <head>
5
+ <meta charset="UTF-8">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <title>NEP+ Image</title>
8
+ <!-- Include Vue 2 and Vuetify 2 from CDN -->
9
+ <link href="https://cdn.jsdelivr.net/npm/vuetify@2.6.3/dist/vuetify.min.css" rel="stylesheet">
10
+ <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
11
+ <script src="https://cdn.jsdelivr.net/npm/vuetify@2.6.3/dist/vuetify.js"></script>
12
+ </head>
13
+
14
+ <body>
15
+ <div id="app">
16
+ <v-app>
17
+ <v-container>
18
+ <v-toolbar dense color="transparent">
19
+ <v-toolbar-title>Camera USB</v-toolbar-title>
20
+ <v-spacer></v-spacer>
21
+
22
+ </v-toolbar>
23
+ <v-row>
24
+ <v-col>
25
+ <v-card color="#1A1A1A">
26
+ <v-img :src="imageSrc" alt="Streamed Image" contain></v-img>
27
+ </v-card>
28
+ </v-col>
29
+ </v-row>
30
+ </v-container>
31
+ </v-app>
32
+ </div>
33
+ <script src="/socket.io/socket.io.js"></script> <!-- Include the Socket.IO client library -->
34
+ <script>
35
+ // Initialize Vue and Vuetify
36
+ new Vue({
37
+ el: '#app',
38
+ vuetify: new Vuetify(),
39
+ data() {
40
+ return {
41
+ imageSrc: '', // Initialize the image source as empty
42
+ };
43
+ },
44
+ mounted() {
45
+ const image = document.getElementById('image');
46
+ const socket = io.connect('http://localhost:3000'); // Connect to your server
47
+
48
+ socket.on('image', (data) => {
49
+ // Set the received image data as the image source
50
+ this.imageSrc = `data:image/jpeg;base64,${data.image}`;
51
+ });
52
+ },
53
+ });
54
+ </script>
55
+ </body>
56
+
57
+ </html>
package/bin/index.js CHANGED
@@ -8,6 +8,14 @@ var nep_configuration = { current_port: 10000, IP: "127.0.0.1", brokers: {} }
8
8
  const { exec } = require('child_process');
9
9
  const { AutoComplete } = require('enquirer');
10
10
 
11
+ const open = require('open'); // Import the 'open' package
12
+
13
+ const express = require('express');
14
+ const http = require('http');
15
+ const socketIo = require('socket.io');
16
+ const fs = require('fs');
17
+ const zmqc = require("zeromq/v5-compat");
18
+
11
19
 
12
20
  // Node saved here
13
21
  var nodes_register = {};
@@ -246,6 +254,12 @@ var processMsg = function (json_msg, nodes_register, topic_register) {
246
254
  }
247
255
 
248
256
  const PORT_MASTER_INFO = 7010; // Default port for master info
257
+ const PORT_IMAGE = 3000;
258
+ const PORT_IMAGES = [];
259
+ for (let i = 3020; i <= 3040; i++) {
260
+ PORT_IMAGES.push(i);
261
+ }
262
+
249
263
 
250
264
  program
251
265
  .version('"0.1.2')
@@ -312,7 +326,49 @@ program
312
326
  .command('open [programName]')
313
327
  .description('Open a program in Windows/macOS')
314
328
  .action(async (programName) => {
315
- const programs = ['camera-js', 'hxri', 'rize', 'sharo'];
329
+ const programs = ['cameras', 'hxri'];
330
+
331
+ // If a program name is provided as an argument, use it; otherwise, show autocomplete
332
+ if (!programName) {
333
+ const autoComplete = new AutoComplete({
334
+ name: 'program',
335
+ message: 'Select a program:',
336
+ choices: programs,
337
+ });
338
+ programName = await autoComplete.run();
339
+ } else if (!programs.includes(programName)) {
340
+ const autoComplete = new AutoComplete({
341
+ name: 'program',
342
+ message: 'Invalid program name. Select a valid program:',
343
+ choices: programs,
344
+ });
345
+ programName = await autoComplete.run();
346
+ }
347
+
348
+ // Get the username of the logged-in user
349
+ const username = os.userInfo().username;
350
+
351
+ // Specify the path to the executable
352
+ const appFolderName = 'nepplus' + "-" + programName;
353
+ const executableName = 'nepplus' + "-" + `${programName}.exe`;
354
+ const executablePath = `C:\\Users\\${username}\\AppData\\Local\\Programs\\${appFolderName}\\${executableName}`;
355
+
356
+ // Run the executable with proper escaping
357
+ exec(`"${executablePath}"`, (error, stdout, stderr) => {
358
+ if (error) {
359
+ console.error(`Error: ${error.message}`);
360
+ return;
361
+ }
362
+ console.log(`stdout: ${stdout}`);
363
+ console.error(`stderr: ${stderr}`);
364
+ });
365
+ });
366
+
367
+ program
368
+ .command('open [programName]')
369
+ .description('Open NEP+ GUI')
370
+ .action(async (programName) => {
371
+ const programs = ['cameras', 'hxri'];
316
372
 
317
373
  // If a program name is provided as an argument, use it; otherwise, show autocomplete
318
374
  if (!programName) {
@@ -350,6 +406,9 @@ program
350
406
  });
351
407
  });
352
408
 
409
+
410
+
411
+
353
412
  program
354
413
  .command('master')
355
414
  .description('Start NEP master in Local host')
@@ -763,7 +822,7 @@ program
763
822
 
764
823
  program
765
824
  .command('listen <topic>')
766
- .description('Listen to a NEP+ topic')
825
+ .description('Subscribe to a NEP+ topic')
767
826
  .action(async (topic) => {
768
827
  const interfaces = os.networkInterfaces();
769
828
 
@@ -813,7 +872,7 @@ program
813
872
 
814
873
  program
815
874
  .command('eth-listen <topic>')
816
- .description('Listen to a NEP+ topic')
875
+ .description('Subscribe to a NEP+ topic over Ethernet')
817
876
  .action(async (topic) => {
818
877
  const interfaces = os.networkInterfaces();
819
878
 
@@ -874,7 +933,7 @@ program
874
933
 
875
934
  program
876
935
  .command('wifi-listen <topic>')
877
- .description('Listen to a NEP+ topic')
936
+ .description('Subscribe to a NEP+ topic over Wi-Fi')
878
937
  .action(async (topic) => {
879
938
  const interfaces = os.networkInterfaces();
880
939
 
@@ -994,6 +1053,84 @@ async function getAndDisplayTopics(master_ip) {
994
1053
  }
995
1054
  }
996
1055
 
1056
+ program
1057
+ .command('image <topic>')
1058
+ .description('Start image server')
1059
+ .action((topic, options) => {
1060
+ async function run() {
1061
+ var requester = new zmq.Request;
1062
+ var master_ip = "127.0.0.1"
1063
+ var port = PORT_IMAGE
1064
+
1065
+
1066
+
1067
+ requester.connect("tcp://" + master_ip + ":" + PORT_MASTER_INFO);
1068
+
1069
+ let msg = { "input": "topics" }
1070
+ var message = JSON.stringify(msg);
1071
+ await requester.send(message)
1072
+ const [result] = await requester.receive()
1073
+ var results = JSON.parse(result.toString())
1074
+ //console.log(results);
1075
+
1076
+
1077
+ const programs = results["input"];
1078
+ const filteredList = programs.filter(value => value.includes("image"));
1079
+
1080
+ if (!topic) {
1081
+ const autoComplete = new AutoComplete({
1082
+ name: 'program',
1083
+ message: 'Select a program:',
1084
+ choices: filteredList,
1085
+ });
1086
+ topic = await autoComplete.run();
1087
+ } else if (!filteredList.includes(topic)) {
1088
+ const autoComplete = new AutoComplete({
1089
+ name: 'program',
1090
+ message: 'Invalid program name. Select a valid program:',
1091
+ choices: filteredList,
1092
+ });
1093
+ topic = await autoComplete.run();
1094
+ }
1095
+
1096
+
1097
+ startServer(port, topic);
1098
+ open(`http://localhost:${port}`);
1099
+
1100
+ }
1101
+ run()
1102
+
1103
+ });
1104
+
1105
+ // Function to start the server
1106
+ function startServer(port, topic) {
1107
+ const app = express();
1108
+ const server = http.createServer(app);
1109
+ const io = socketIo(server);
1110
+
1111
+ var node = new nep.Node("nep-cli");
1112
+
1113
+ function getImage(msg) {
1114
+ // Send the received image data as-is to connected clients
1115
+ io.sockets.emit('image', { image: msg });
1116
+ }
1117
+
1118
+ var sub = node.new_sub(topic, "image", getImage);
1119
+
1120
+ app.get('/', (req, res) => {
1121
+ res.sendFile(__dirname + '/image.html'); // Serve your HTML file
1122
+ });
1123
+
1124
+ server.listen(port, () => {
1125
+ console.log(`Server is running on http://localhost:${port}`);
1126
+ });
1127
+
1128
+ io.on('connection', (socket) => {
1129
+ const frameRate = 30; // Desired frame rate
1130
+ const interval = 1000 / frameRate; // Interval between frames
1131
+ });
1132
+ }
1133
+
997
1134
  program.parse(process.argv);
998
1135
 
999
1136
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nep-cli",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "main": "./lib/nep.js",
5
5
  "bin": {
6
6
  "nep": "./bin/index.js"
@@ -11,10 +11,12 @@
11
11
  "dependencies": {
12
12
  "commander": "^11.0.0",
13
13
  "enquirer": "^2.4.1",
14
+ "express": "^4.18.2",
14
15
  "fix-path": "^2.1.0",
15
16
  "inquirer": "^9.2.10",
16
- "nep-js": "^0.2.2",
17
- "open": "^9.1.0",
17
+ "nep-js": "^0.3.0",
18
+ "open": "7.4.2",
19
+ "socket.io": "^4.7.2",
18
20
  "zeromq": "6.0.0-beta.6"
19
21
  }
20
22
  }