@sndwrks/osc-cli 1.0.0 → 1.0.1
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/README.md +8 -1
- package/dist/cli.js +3 -3
- package/dist/index.js +39 -31
- package/package.json +10 -5
package/README.md
CHANGED
|
@@ -37,7 +37,7 @@ npm install
|
|
|
37
37
|
### Install from npm (if published)
|
|
38
38
|
|
|
39
39
|
```bash
|
|
40
|
-
npm install -g osc-cli
|
|
40
|
+
npm install -g @sndwrks/osc-cli
|
|
41
41
|
```
|
|
42
42
|
|
|
43
43
|
## Build
|
|
@@ -50,6 +50,12 @@ npm run build
|
|
|
50
50
|
|
|
51
51
|
Once installed globally, use the `osc-cli` command. If not installed globally, use `npm start` instead.
|
|
52
52
|
|
|
53
|
+
```bash
|
|
54
|
+
npm start -- listen-udp <port>
|
|
55
|
+
npm start -- listen-tcp <port>
|
|
56
|
+
npm start -- listen-both <udp-port> <tcp-port>
|
|
57
|
+
```
|
|
58
|
+
|
|
53
59
|
### Listen for OSC Messages
|
|
54
60
|
|
|
55
61
|
**UDP (default port 57121):**
|
|
@@ -79,6 +85,7 @@ osc-cli send-udp /synth/note 440 0.5 localhost 8000
|
|
|
79
85
|
```
|
|
80
86
|
|
|
81
87
|
**TCP:**
|
|
88
|
+
NOTE: This is currently broken due to issue in osc.js
|
|
82
89
|
```bash
|
|
83
90
|
osc-cli send-tcp /test hello 123 127.0.0.1 57122
|
|
84
91
|
osc-cli send-tcp /synth/note 440 0.5 localhost 8001
|
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { listenUDP, listenTCP, sendUDP, sendTCP, logger } from './index.js';
|
|
2
|
+
import { listenUDP, listenTCP, sendUDP, sendTCP, logger, } from './index.js';
|
|
3
3
|
// CLI Interface
|
|
4
4
|
const args = process.argv.slice(2);
|
|
5
5
|
const command = args[0];
|
|
@@ -25,7 +25,7 @@ switch (command) {
|
|
|
25
25
|
process.exit(1);
|
|
26
26
|
}
|
|
27
27
|
const udpAddress = args[1];
|
|
28
|
-
const udpArgs = args.slice(2, -2).map(arg => {
|
|
28
|
+
const udpArgs = args.slice(2, -2).map((arg) => {
|
|
29
29
|
const num = parseFloat(arg);
|
|
30
30
|
return isNaN(num) ? arg : num;
|
|
31
31
|
});
|
|
@@ -39,7 +39,7 @@ switch (command) {
|
|
|
39
39
|
process.exit(1);
|
|
40
40
|
}
|
|
41
41
|
const tcpAddress = args[1];
|
|
42
|
-
const tcpArgs = args.slice(2, -2).map(arg => {
|
|
42
|
+
const tcpArgs = args.slice(2, -2).map((arg) => {
|
|
43
43
|
const num = parseFloat(arg);
|
|
44
44
|
return isNaN(num) ? arg : num;
|
|
45
45
|
});
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import osc from 'osc';
|
|
2
2
|
import { beginLogging, configureLogger } from '@sndwrks/lumberjack';
|
|
3
|
+
import * as net from 'node:net';
|
|
3
4
|
// Configure logger globally
|
|
4
5
|
configureLogger({
|
|
5
6
|
logToConsole: {
|
|
6
7
|
enabled: true,
|
|
7
|
-
type: 'pretty'
|
|
8
|
+
type: 'pretty',
|
|
8
9
|
},
|
|
9
10
|
logLevel: 'info',
|
|
10
|
-
service: 'osc-cli'
|
|
11
|
+
service: 'osc-cli',
|
|
11
12
|
});
|
|
12
13
|
// Create logger instance
|
|
13
14
|
const logger = beginLogging({ name: 'OSC-CLI' });
|
|
@@ -18,7 +19,7 @@ export function listenUDP(port = 57121) {
|
|
|
18
19
|
const udpPort = new osc.UDPPort({
|
|
19
20
|
localAddress: '0.0.0.0',
|
|
20
21
|
localPort: port,
|
|
21
|
-
metadata: true
|
|
22
|
+
metadata: true,
|
|
22
23
|
});
|
|
23
24
|
udpPort.on('ready', () => {
|
|
24
25
|
logger.info(`Listening for OSC over UDP on port ${port}`);
|
|
@@ -26,7 +27,7 @@ export function listenUDP(port = 57121) {
|
|
|
26
27
|
udpPort.on('message', (oscMsg) => {
|
|
27
28
|
logger.info('UDP OSC message received:', {
|
|
28
29
|
address: oscMsg.address,
|
|
29
|
-
args: oscMsg.args
|
|
30
|
+
args: oscMsg.args,
|
|
30
31
|
});
|
|
31
32
|
});
|
|
32
33
|
udpPort.on('error', (err) => {
|
|
@@ -39,25 +40,31 @@ export function listenUDP(port = 57121) {
|
|
|
39
40
|
* Listen for OSC messages via TCP
|
|
40
41
|
*/
|
|
41
42
|
export function listenTCP(port = 57122) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
});
|
|
47
|
-
tcpPort.on('ready', () => {
|
|
48
|
-
logger.info(`Listening for OSC over TCP on port ${port}`);
|
|
49
|
-
});
|
|
50
|
-
tcpPort.on('message', (oscMsg) => {
|
|
51
|
-
logger.info('TCP OSC message received:', {
|
|
52
|
-
address: oscMsg.address,
|
|
53
|
-
args: oscMsg.args
|
|
43
|
+
let tcpPort;
|
|
44
|
+
const tcpServer = net.createServer((socket) => {
|
|
45
|
+
tcpPort = new osc.TCPSocketPort({
|
|
46
|
+
socket,
|
|
54
47
|
});
|
|
48
|
+
tcpPort.on('ready', () => {
|
|
49
|
+
logger.info(`Listening for OSC over TCP on port ${port}`);
|
|
50
|
+
});
|
|
51
|
+
tcpPort.on('data', (oscMsg) => {
|
|
52
|
+
logger.info('TCP OSC message received:', {
|
|
53
|
+
address: oscMsg.address,
|
|
54
|
+
args: oscMsg.args,
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
tcpPort.on('error', (err) => {
|
|
58
|
+
logger.error('TCP Error:', err);
|
|
59
|
+
});
|
|
60
|
+
tcpPort.listen();
|
|
55
61
|
});
|
|
56
|
-
|
|
57
|
-
logger.error(
|
|
62
|
+
tcpServer.on('error', (e) => {
|
|
63
|
+
logger.error(e);
|
|
64
|
+
});
|
|
65
|
+
tcpServer.listen(port, '0.0.0.0', () => {
|
|
66
|
+
logger.info('TCP server listening on port');
|
|
58
67
|
});
|
|
59
|
-
tcpPort.open();
|
|
60
|
-
return tcpPort;
|
|
61
68
|
}
|
|
62
69
|
/**
|
|
63
70
|
* Send OSC message via UDP
|
|
@@ -66,13 +73,13 @@ export function sendUDP(address, args, host = '127.0.0.1', port = 57121) {
|
|
|
66
73
|
const udpPort = new osc.UDPPort({
|
|
67
74
|
localAddress: '0.0.0.0',
|
|
68
75
|
localPort: 0,
|
|
69
|
-
metadata: true
|
|
76
|
+
metadata: true,
|
|
70
77
|
});
|
|
71
78
|
udpPort.on('ready', () => {
|
|
72
79
|
logger.info(`Sending OSC message via UDP to ${host}:${port}`);
|
|
73
80
|
udpPort.send({
|
|
74
|
-
address
|
|
75
|
-
args
|
|
81
|
+
address,
|
|
82
|
+
args,
|
|
76
83
|
}, host, port);
|
|
77
84
|
logger.info('Message sent:', { address, args });
|
|
78
85
|
// Close after sending
|
|
@@ -90,27 +97,28 @@ export function sendUDP(address, args, host = '127.0.0.1', port = 57121) {
|
|
|
90
97
|
*/
|
|
91
98
|
export function sendTCP(address, args, host = '127.0.0.1', port = 57122) {
|
|
92
99
|
const tcpPort = new osc.TCPSocketPort({
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
remoteAddress: host,
|
|
96
|
-
remotePort: port,
|
|
97
|
-
metadata: true
|
|
100
|
+
address: '0.0.0.0',
|
|
101
|
+
port: 52000,
|
|
98
102
|
});
|
|
103
|
+
logger.info(`Attempting send... address: ${address}, args: ${args}, host: ${host}, port: ${port}`);
|
|
104
|
+
logger.info({ tcpPort });
|
|
99
105
|
tcpPort.on('ready', () => {
|
|
100
106
|
logger.info(`Sending OSC message via TCP to ${host}:${port}`);
|
|
101
107
|
tcpPort.send({
|
|
102
|
-
address
|
|
103
|
-
args
|
|
108
|
+
address,
|
|
109
|
+
args,
|
|
104
110
|
});
|
|
105
111
|
logger.info('Message sent:', { address, args });
|
|
106
112
|
// Close after sending
|
|
107
113
|
setTimeout(() => {
|
|
108
114
|
tcpPort.close();
|
|
115
|
+
logger.info('TCP Port closed.');
|
|
116
|
+
process.exit(0);
|
|
109
117
|
}, 100);
|
|
110
118
|
});
|
|
111
119
|
tcpPort.on('error', (err) => {
|
|
112
120
|
logger.error('TCP Send Error:', err);
|
|
113
121
|
});
|
|
114
|
-
tcpPort.open();
|
|
122
|
+
tcpPort.open(host, port);
|
|
115
123
|
}
|
|
116
124
|
export { logger };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sndwrks/osc-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Simple OSC command-line tool",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"osc",
|
|
@@ -31,17 +31,22 @@
|
|
|
31
31
|
],
|
|
32
32
|
"scripts": {
|
|
33
33
|
"build": "tsc",
|
|
34
|
-
"start": "node dist/
|
|
35
|
-
"dev": "tsc && node dist/
|
|
34
|
+
"start": "node dist/cli.js",
|
|
35
|
+
"dev": "tsc && node dist/cli.js",
|
|
36
36
|
"prepublishOnly": "npm run build",
|
|
37
37
|
"prepack": "npm run build"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@sndwrks/lumberjack": "^0.8.0",
|
|
41
|
-
"osc": "^2.4.
|
|
41
|
+
"osc": "^2.4.5"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@types/node": "^20.0.0",
|
|
45
|
-
"typescript": "^5.0.0"
|
|
45
|
+
"typescript": "^5.0.0",
|
|
46
|
+
"@typescript-eslint/eslint-plugin": "^8.50.1",
|
|
47
|
+
"@typescript-eslint/parser": "^8.34.1",
|
|
48
|
+
"eslint": "^8.57.1",
|
|
49
|
+
"eslint-config-airbnb-base": "^15.0.0",
|
|
50
|
+
"eslint-import-resolver-typescript": "^4.4.3"
|
|
46
51
|
}
|
|
47
52
|
}
|