const vorpal = require('vorpal')();
var osc = require('node-osc');


vorpal.command('start server')
  .action(function (args, cb) {
    var self = this;

    var promise = this.prompt([
      {
        type: 'input',
        name: 'name',
        message: 'Name: '
      },
      {
        type: 'input',
        name: 'address',
        message: 'Address: '
      },
      {
        type: 'input',
        name: 'port',
        message: 'Port: '
      }
    ], function (answers) {
        var serverName = answers.name;
        var oscServer = new osc.Server(answers.port, answers.address);
        oscServer.on("message", function (msg, rinfo) {
              console.log(msg);
        });
    });

    promise.then(function(answers) {
        self.log(answers.name + ' started on: ' + answers.address + ":" + answers.port );
      cb();
    });
  });



  vorpal.command('start client')
    .action(function (args, cb) {
      var self = this;

      var promise = this.prompt([
        {
          type: 'input',
          name: 'name',
          message: 'Name: '
        },
        {
          type: 'input',
          name: 'address',
          message: 'Address: '
        },
        {
          type: 'input',
          name: 'port',
          message: 'Port: '
        }
      ], function (answers) {
          var serverName = answers.name;
          var address = answers.address;
          var port= answers.port;
          var client = new osc.Client(address, port);
          client.send('/oscAddress', 200, function () {
              client.kill();
          });
      });

      promise.then(function(answers) {
          self.log(answers.name + ' started on: ' + answers.address + ":" + answers.port );
        cb();
      });
    });


    vorpal.command('send messages')
     .action(function (args, cb) {
       var self = this;

       var promise = this.prompt([
         {
           type: 'input',
           name: 'message',
           message: 'Message:'
         },
         {
           type: 'input',
           name: 'time',
           message: 'Interval (Ms): '
         }
       ], function (answers) {
           var client = new osc.Client('127.0.0.1', 3333);
           setInterval(function(){
             client.send(answers.message);
          }, answers.time);

       });

       promise.then(function(answers) {
           self.log('OSC Server started on: ' + answers.address + ":" + answers.port );
         cb();
       });
     });





vorpal
  .show()
  .parse(process.argv);

@@ -1779,16 +1779,13 @@
 end 
-messages
+group
 ')%0A 
@@ -2470,16 +2470,1136 @@
    %7D);%0A%0A
+     vorpal.command('send message')%0A      .action(function (args, cb) %7B%0A        var self = this;%0A%0A        var promise = this.prompt(%5B%0A          %7B%0A            type: 'input',%0A            name: 'message',%0A            message: 'Message:'%0A          %7D,%0A          %7B%0A            type: 'input',%0A            name: 'arg',%0A            message: 'Argument:'%0A          %7D,%0A          %7B%0A            type: 'input',%0A            name: 'address',%0A            message: 'Address: '%0A          %7D,%0A          %7B%0A            type: 'input',%0A            name: 'port',%0A            message: 'Port: '%0A          %7D%0A%0A%0A%0A        %5D, function (answers) %7B%0A            var message = answers.message;%0A            var argument = answers.arg;%0A            var address = answers.address;%0A            var port= answers.port;%0A            var client = new osc.Client(address, port);%0A            client.send(message, argument, function () %7B%0A                client.kill();%0A            %7D);%0A%0A%0A%0A        %7D);%0A%0A        promise.then(function(answers) %7B%0A            self.log('OSC Server started on: ' + answers.address + %22:%22 + answers.port );%0A          cb();%0A        %7D);%0A      %7D);%0A%0A
 %0A%0A%0A%0Avorp

Send Message