diff --git a/README.md b/README.md index ba39466..62a6537 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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) diff --git a/app.js b/app.js index 4e70e8b..ca6590a 100644 --- a/app.js +++ b/app.js @@ -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 @@ -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 } @@ -17,17 +18,19 @@ 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'){ @@ -35,6 +38,7 @@ if(mode === 'server'){ listenerModeSendPort = 7405 } + // ***** Local UDP-Sender ******* // // this is used by either mode! function init(){ @@ -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 @@ -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) => { @@ -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) => { diff --git a/args.js b/args.js deleted file mode 100644 index b7979f0..0000000 --- a/args.js +++ /dev/null @@ -1,11 +0,0 @@ -const yargs = require('yargs/yargs') -const { hideBin } = require('yargs/helpers') -const argv = yargs(hideBin(process.argv)).argv - - -console.log(argv.ships) -if (argv.ships > 3 && argv.distance < 53.5) { - console.log('Plunder more riffiwobbles!') -} else { - console.log('Retreat from the xupptumblers!') -} \ No newline at end of file diff --git a/tester.js b/tester.js new file mode 100644 index 0000000..1315ceb --- /dev/null +++ b/tester.js @@ -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); + }); + } + + +