@sndwrks/osc-cli 1.0.0
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 +137 -0
- package/dist/cli.js +68 -0
- package/dist/index.js +116 -0
- package/package.json +47 -0
package/README.md
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# OSC CLI Tool
|
|
2
|
+
|
|
3
|
+
**DISCLAIMER: this was written by AI, but it will be maintained by humans (probably)**
|
|
4
|
+
|
|
5
|
+
A simple command-line application for sending and receiving OSC (Open Sound Control) messages via TCP and UDP.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- Listen for OSC messages via UDP
|
|
10
|
+
- Listen for OSC messages via TCP
|
|
11
|
+
- Listen on both protocols simultaneously
|
|
12
|
+
- Send OSC messages via UDP
|
|
13
|
+
- Send OSC messages via TCP
|
|
14
|
+
- Logging with @sndwrks/lumberjack
|
|
15
|
+
- **Installable as a global CLI tool**
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
### Install Globally
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install -g .
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
After installation, you can use the `osc-cli` command from anywhere:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
osc-cli listen-udp 8000
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Install as Dependency
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npm install
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Install from npm (if published)
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npm install -g osc-cli
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Build
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
npm run build
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Usage
|
|
50
|
+
|
|
51
|
+
Once installed globally, use the `osc-cli` command. If not installed globally, use `npm start` instead.
|
|
52
|
+
|
|
53
|
+
### Listen for OSC Messages
|
|
54
|
+
|
|
55
|
+
**UDP (default port 57121):**
|
|
56
|
+
```bash
|
|
57
|
+
osc-cli listen-udp
|
|
58
|
+
osc-cli listen-udp 8000
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
**TCP (default port 57122):**
|
|
62
|
+
```bash
|
|
63
|
+
osc-cli listen-tcp
|
|
64
|
+
osc-cli listen-tcp 8001
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**Both UDP and TCP:**
|
|
68
|
+
```bash
|
|
69
|
+
osc-cli listen-both
|
|
70
|
+
osc-cli listen-both 8000 8001
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Send OSC Messages
|
|
74
|
+
|
|
75
|
+
**UDP:**
|
|
76
|
+
```bash
|
|
77
|
+
osc-cli send-udp /test hello 123 127.0.0.1 57121
|
|
78
|
+
osc-cli send-udp /synth/note 440 0.5 localhost 8000
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
**TCP:**
|
|
82
|
+
```bash
|
|
83
|
+
osc-cli send-tcp /test hello 123 127.0.0.1 57122
|
|
84
|
+
osc-cli send-tcp /synth/note 440 0.5 localhost 8001
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Message Format
|
|
88
|
+
|
|
89
|
+
- **Address**: OSC address pattern (e.g., `/test`, `/synth/freq`)
|
|
90
|
+
- **Args**: Space-separated values (automatically parsed as numbers if possible)
|
|
91
|
+
- **Host**: Target hostname or IP address (default: 127.0.0.1)
|
|
92
|
+
- **Port**: Target port number
|
|
93
|
+
|
|
94
|
+
## Examples
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
# Install globally
|
|
98
|
+
npm install -g .
|
|
99
|
+
|
|
100
|
+
# Start listening on UDP port 8000
|
|
101
|
+
osc-cli listen-udp 8000
|
|
102
|
+
|
|
103
|
+
# In another terminal, send a message
|
|
104
|
+
osc-cli send-udp /hello world 127.0.0.1 8000
|
|
105
|
+
|
|
106
|
+
# Listen on both protocols
|
|
107
|
+
osc-cli listen-both 9000 9001
|
|
108
|
+
|
|
109
|
+
# Send via TCP
|
|
110
|
+
osc-cli send-tcp /synth/freq 440 127.0.0.1 9001
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Development
|
|
114
|
+
|
|
115
|
+
If you haven't installed globally, you can use npm scripts:
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
npm run build # Build TypeScript
|
|
119
|
+
npm start listen-udp # Run with npm start
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Uninstall
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
npm uninstall -g osc-cli
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Publishing to NPM
|
|
129
|
+
|
|
130
|
+
See [PUBLISHING.md](PUBLISHING.md) for detailed instructions on how to publish this package to npm with the TypeScript build step.
|
|
131
|
+
|
|
132
|
+
## Dependencies
|
|
133
|
+
|
|
134
|
+
- `osc`: OSC protocol implementation
|
|
135
|
+
- `@sndwrks/lumberjack`: Winston-based logging library
|
|
136
|
+
|
|
137
|
+
**Note:** This package includes custom TypeScript type definitions for the `osc` library in `src/types/osc.d.ts` since the osc package doesn't provide its own types.
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { listenUDP, listenTCP, sendUDP, sendTCP, logger } from './index.js';
|
|
3
|
+
// CLI Interface
|
|
4
|
+
const args = process.argv.slice(2);
|
|
5
|
+
const command = args[0];
|
|
6
|
+
switch (command) {
|
|
7
|
+
case 'listen-udp':
|
|
8
|
+
const udpPort = parseInt(args[1]) || 57121;
|
|
9
|
+
listenUDP(udpPort);
|
|
10
|
+
break;
|
|
11
|
+
case 'listen-tcp':
|
|
12
|
+
const tcpPort = parseInt(args[1]) || 57122;
|
|
13
|
+
listenTCP(tcpPort);
|
|
14
|
+
break;
|
|
15
|
+
case 'listen-both':
|
|
16
|
+
const udpBothPort = parseInt(args[1]) || 57121;
|
|
17
|
+
const tcpBothPort = parseInt(args[2]) || 57122;
|
|
18
|
+
listenUDP(udpBothPort);
|
|
19
|
+
listenTCP(tcpBothPort);
|
|
20
|
+
logger.info('Listening on both UDP and TCP');
|
|
21
|
+
break;
|
|
22
|
+
case 'send-udp':
|
|
23
|
+
if (args.length < 2) {
|
|
24
|
+
logger.error('Usage: send-udp <address> [args...] [host] [port]');
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
const udpAddress = args[1];
|
|
28
|
+
const udpArgs = args.slice(2, -2).map(arg => {
|
|
29
|
+
const num = parseFloat(arg);
|
|
30
|
+
return isNaN(num) ? arg : num;
|
|
31
|
+
});
|
|
32
|
+
const udpHost = args[args.length - 2] || '127.0.0.1';
|
|
33
|
+
const udpSendPort = parseInt(args[args.length - 1]) || 57121;
|
|
34
|
+
sendUDP(udpAddress, udpArgs, udpHost, udpSendPort);
|
|
35
|
+
break;
|
|
36
|
+
case 'send-tcp':
|
|
37
|
+
if (args.length < 2) {
|
|
38
|
+
logger.error('Usage: send-tcp <address> [args...] [host] [port]');
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
const tcpAddress = args[1];
|
|
42
|
+
const tcpArgs = args.slice(2, -2).map(arg => {
|
|
43
|
+
const num = parseFloat(arg);
|
|
44
|
+
return isNaN(num) ? arg : num;
|
|
45
|
+
});
|
|
46
|
+
const tcpHost = args[args.length - 2] || '127.0.0.1';
|
|
47
|
+
const tcpSendPort = parseInt(args[args.length - 1]) || 57122;
|
|
48
|
+
sendTCP(tcpAddress, tcpArgs, tcpHost, tcpSendPort);
|
|
49
|
+
break;
|
|
50
|
+
default:
|
|
51
|
+
console.log(`
|
|
52
|
+
OSC CLI Tool
|
|
53
|
+
|
|
54
|
+
Usage:
|
|
55
|
+
osc-cli listen-udp [port] - Listen for UDP OSC messages (default port: 57121)
|
|
56
|
+
osc-cli listen-tcp [port] - Listen for TCP OSC messages (default port: 57122)
|
|
57
|
+
osc-cli listen-both [udpPort] [tcpPort] - Listen on both UDP and TCP
|
|
58
|
+
osc-cli send-udp <address> [args...] [host] [port] - Send OSC via UDP
|
|
59
|
+
osc-cli send-tcp <address> [args...] [host] [port] - Send OSC via TCP
|
|
60
|
+
|
|
61
|
+
Examples:
|
|
62
|
+
osc-cli listen-udp 8000
|
|
63
|
+
osc-cli listen-both 8000 8001
|
|
64
|
+
osc-cli send-udp /test hello 123 127.0.0.1 8000
|
|
65
|
+
osc-cli send-tcp /synth/freq 440 localhost 8001
|
|
66
|
+
`);
|
|
67
|
+
break;
|
|
68
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import osc from 'osc';
|
|
2
|
+
import { beginLogging, configureLogger } from '@sndwrks/lumberjack';
|
|
3
|
+
// Configure logger globally
|
|
4
|
+
configureLogger({
|
|
5
|
+
logToConsole: {
|
|
6
|
+
enabled: true,
|
|
7
|
+
type: 'pretty'
|
|
8
|
+
},
|
|
9
|
+
logLevel: 'info',
|
|
10
|
+
service: 'osc-cli'
|
|
11
|
+
});
|
|
12
|
+
// Create logger instance
|
|
13
|
+
const logger = beginLogging({ name: 'OSC-CLI' });
|
|
14
|
+
/**
|
|
15
|
+
* Listen for OSC messages via UDP
|
|
16
|
+
*/
|
|
17
|
+
export function listenUDP(port = 57121) {
|
|
18
|
+
const udpPort = new osc.UDPPort({
|
|
19
|
+
localAddress: '0.0.0.0',
|
|
20
|
+
localPort: port,
|
|
21
|
+
metadata: true
|
|
22
|
+
});
|
|
23
|
+
udpPort.on('ready', () => {
|
|
24
|
+
logger.info(`Listening for OSC over UDP on port ${port}`);
|
|
25
|
+
});
|
|
26
|
+
udpPort.on('message', (oscMsg) => {
|
|
27
|
+
logger.info('UDP OSC message received:', {
|
|
28
|
+
address: oscMsg.address,
|
|
29
|
+
args: oscMsg.args
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
udpPort.on('error', (err) => {
|
|
33
|
+
logger.error('UDP Error:', err);
|
|
34
|
+
});
|
|
35
|
+
udpPort.open();
|
|
36
|
+
return udpPort;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Listen for OSC messages via TCP
|
|
40
|
+
*/
|
|
41
|
+
export function listenTCP(port = 57122) {
|
|
42
|
+
const tcpPort = new osc.TCPSocketPort({
|
|
43
|
+
localAddress: '0.0.0.0',
|
|
44
|
+
localPort: port,
|
|
45
|
+
metadata: true
|
|
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
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
tcpPort.on('error', (err) => {
|
|
57
|
+
logger.error('TCP Error:', err);
|
|
58
|
+
});
|
|
59
|
+
tcpPort.open();
|
|
60
|
+
return tcpPort;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Send OSC message via UDP
|
|
64
|
+
*/
|
|
65
|
+
export function sendUDP(address, args, host = '127.0.0.1', port = 57121) {
|
|
66
|
+
const udpPort = new osc.UDPPort({
|
|
67
|
+
localAddress: '0.0.0.0',
|
|
68
|
+
localPort: 0,
|
|
69
|
+
metadata: true
|
|
70
|
+
});
|
|
71
|
+
udpPort.on('ready', () => {
|
|
72
|
+
logger.info(`Sending OSC message via UDP to ${host}:${port}`);
|
|
73
|
+
udpPort.send({
|
|
74
|
+
address: address,
|
|
75
|
+
args: args
|
|
76
|
+
}, host, port);
|
|
77
|
+
logger.info('Message sent:', { address, args });
|
|
78
|
+
// Close after sending
|
|
79
|
+
setTimeout(() => {
|
|
80
|
+
udpPort.close();
|
|
81
|
+
}, 100);
|
|
82
|
+
});
|
|
83
|
+
udpPort.on('error', (err) => {
|
|
84
|
+
logger.error('UDP Send Error:', err);
|
|
85
|
+
});
|
|
86
|
+
udpPort.open();
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Send OSC message via TCP
|
|
90
|
+
*/
|
|
91
|
+
export function sendTCP(address, args, host = '127.0.0.1', port = 57122) {
|
|
92
|
+
const tcpPort = new osc.TCPSocketPort({
|
|
93
|
+
localAddress: '0.0.0.0',
|
|
94
|
+
localPort: 0,
|
|
95
|
+
remoteAddress: host,
|
|
96
|
+
remotePort: port,
|
|
97
|
+
metadata: true
|
|
98
|
+
});
|
|
99
|
+
tcpPort.on('ready', () => {
|
|
100
|
+
logger.info(`Sending OSC message via TCP to ${host}:${port}`);
|
|
101
|
+
tcpPort.send({
|
|
102
|
+
address: address,
|
|
103
|
+
args: args
|
|
104
|
+
});
|
|
105
|
+
logger.info('Message sent:', { address, args });
|
|
106
|
+
// Close after sending
|
|
107
|
+
setTimeout(() => {
|
|
108
|
+
tcpPort.close();
|
|
109
|
+
}, 100);
|
|
110
|
+
});
|
|
111
|
+
tcpPort.on('error', (err) => {
|
|
112
|
+
logger.error('TCP Send Error:', err);
|
|
113
|
+
});
|
|
114
|
+
tcpPort.open();
|
|
115
|
+
}
|
|
116
|
+
export { logger };
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sndwrks/osc-cli",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Simple OSC command-line tool",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"osc",
|
|
7
|
+
"cli",
|
|
8
|
+
"tcp",
|
|
9
|
+
"udp",
|
|
10
|
+
"open-sound-control"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://github.com/sndwrks/osc-cli#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/sndwrks/osc-cli/issues"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/sndwrks/osc-cli.git"
|
|
19
|
+
},
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"author": "john mckenna",
|
|
22
|
+
"type": "module",
|
|
23
|
+
"main": "dist/index.js",
|
|
24
|
+
"bin": {
|
|
25
|
+
"osc-cli": "dist/cli.js"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist",
|
|
29
|
+
"README.md",
|
|
30
|
+
"LICENSE"
|
|
31
|
+
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsc",
|
|
34
|
+
"start": "node dist/index.js",
|
|
35
|
+
"dev": "tsc && node dist/index.js",
|
|
36
|
+
"prepublishOnly": "npm run build",
|
|
37
|
+
"prepack": "npm run build"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@sndwrks/lumberjack": "^0.8.0",
|
|
41
|
+
"osc": "^2.4.4"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/node": "^20.0.0",
|
|
45
|
+
"typescript": "^5.0.0"
|
|
46
|
+
}
|
|
47
|
+
}
|