Skip to content

Commit

Permalink
wspd now connects to remote, and has some cli args as well
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelpalumbo committed Nov 21, 2020
1 parent 82f0129 commit b47fbe3
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 35 deletions.
23 changes: 11 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Since first starting the code, it's become a lot more general than only being us

### Instructions
1. install nodejs
2. clone/download the wspd repository at https://github.com/michaelpalumbo/wspd
3. Open terminal, cd into the folder 'wspd' (the rest of this readme assumes that you're working from this directory)
2. Download the latest release of this code, making sure its the 'placeholder' version: https://github.com/michaelpalumbo/wspd/releases
3. Open terminal, cd into the downloaded folder 'wspd' (the rest of this readme assumes that you're working from this directory)
4. verify nodejs is installed:

```shell
Expand All @@ -21,25 +21,24 @@ node -v
```shell
npm install
```
### Test locally
1. start the server

### Usage

1. in terminal, type
```shell
npm start server
node app.js --mode client --name yournamewithnospaces
```

2.. open a 2nd terminal window, cd into wspd
and then hit enter to start the program

3.. start the client
2. If it is running correctly, the terminal should report the following:

```shell
npm start client localhost
Configure your local pd patch(es) to listen on UDP Port 7403
Configure your local pd patch(es) to send on UDP Port 7404
connected to server at ws://evening-retreat-29342.herokuapp.com/8081
```

4.. open the tester.maxpat (or tester.pd)

Click either of the toggles to confirm data is being sent from pd>nodejs>pd. You should be able to have both toggles clicked, this verifies bi-directionality.

### Telematic setup

1. whomever can configure their router with DMZ and port-forwarding should run the app in server mode. The diagram below assumes that Jen would be running the server (the code doesn't need to be modified if you choose to have Erin run the server instead)
Expand Down
28 changes: 16 additions & 12 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// this script runs at either side
// it's function as either a server or client is determined by a cli arg
// note: this version is for running wspd's server as a cloud instance on heroku, so to push updates, use:
// git push heroku placeholder:master

const yargs = require('yargs/yargs')
const { hideBin } = require('yargs/helpers')
const argv = yargs(hideBin(process.argv)).argv
Expand All @@ -8,7 +9,7 @@ const argv = yargs(hideBin(process.argv)).argv
// now we specify mode using argv.mode, and --mode flag in cli
const mode = argv.mode
console.log(mode + ' mode')
let host;
let host = 'evening-retreat-29342.herokuapp.com'
if(argv.host){
host = argv.host
}
Expand All @@ -17,24 +18,27 @@ let name;
if(argv.name){
name = argv.name
}
/* note: this removed for cloud version
if (mode === 'client' && !argv.host){
console.log('error: client mode requires --host flag to specify server IP address\nexample:\n\nnode app.js --mode client --host localhost')
process.exit()
}
*/

// ***** Local UDP Send & Receive Config ******* //
let localReceivePort;
let localSendPort;
if(mode === 'server'){
localReceivePort = 7402
localSendPort = 7401
} else if (mode === 'client'){


if (mode === 'client'){
localReceivePort = 7404
localSendPort = 7403
} else if (mode === 'listener'){
// localReceivePort = 7404
listenerModeSendPort = 7405
}


// ***** Local UDP-Sender ******* //
// this is used by either mode!
function init(){
Expand Down Expand Up @@ -168,7 +172,7 @@ if (mode === "server"){
const ReconnectingWebSocket = require('reconnecting-websocket');
const serverIP = host
const serverPort = '8081';
const serverWSAddress = `ws://${serverIP}:${serverPort}`;
const serverWSAddress = `ws://${serverIP}/${serverPort}`;
// options for the reconnecting websocket
const rwsOptions = {
// make rws use the webSocket module implementation
Expand All @@ -193,8 +197,8 @@ if (mode === "server"){
// on close:
ws.addEventListener('close', () => {
console.log("server connection closed");
localSend.close();
localReceive.close();
// localSend.close();
// localReceive.close();
});
// handle messages
ws.addEventListener('message', (data) => {
Expand Down Expand Up @@ -301,8 +305,8 @@ if (mode === "server"){
// on close:
ws.addEventListener('close', () => {
console.log("server connection closed");
localSend.close();
localReceive.close();
// localSend.close();
// localReceive.close();
});
// handle messages
ws.addEventListener('message', (data) => {
Expand Down
11 changes: 0 additions & 11 deletions args.js

This file was deleted.

21 changes: 21 additions & 0 deletions tester.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
localReceivePort = 7404
localSendPort = 7404

const { Client, Server } = require('node-osc');

const localSend = new Client('127.0.0.1', 7404);
console.log('wspd udp tester\n\nplease ensure the app.js program is also running')
// run the app in client mode

let msgTiming = setInterval(myTimer, 1000);

function myTimer() {
let tts = Math.random()
console.log('sending OSC msg "/testmsg ' + tts + '"')
localSend.send('/testmsg', tts, (err) => {
if (err) console.error(err);
});
}



0 comments on commit b47fbe3

Please sign in to comment.