How to use node-osc - 10 common examples

To help you get started, we’ve selected a few node-osc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github moxuse / Kusabi / index.js View on Github external
// });
  // psci.stderr.setEncoding("utf-8");
  // psci.stderr.on("data", data => {
  //   console.log(data);
  //   socket.emit("response", data);
  // });
  /**
   * interaction with editor of render process
   */

  console.log("sthart watching Main.purs");

  /**]
   * osc listen
   */
  const oscServer = new OscServer(config.osc.port, config.osc.host);
  oscServer.on("message", function(msg) {
    // console.log("on osc msg:", msg);
    socket.emit(msg[0], msg[1]);
  });
});
github MAKIO135 / aioi / desktop / src / scripts / helpers.js View on Github external
const parseInputMsg = data => {
    const parseInputArg = arg => {
        // Float
        if (/\b\d+\.d?\b/.test(arg) || /\b\d?\.d+\b/.test(arg)) {
            return { type: 'f', value: parseFloat(arg) }
        }
        // Integer
        else if (/\b\d+\b/.test(arg)) {
            return parseInt(arg)
        }
        // String
        return `${arg}`
    }

    const [path, ...args] = data.split(' ').filter(d => d !== '')
    const oscMsg = new osc.Message(`${path}`)

    // console.log(args.map(parseInputArg))

    args.map(parseInputArg)
        .forEach(arg => oscMsg.append(arg))

    return oscMsg
}
github kn0ll / osc.io / lib / osc.io.js View on Github external
function server_channel_handler(socket) {
  var ns = socket.namespace.name,
    port = parse_io_ns_option(ns),
    osc_server = new osc.Server(port, '0.0.0.0');

  // proxy osc messages from udp to socket.io
  osc_server.on('message', function(msg) {
    socket.emit('message', msg);
  });
}
github triss / duplex-nexus-osc / nxserver.js View on Github external
// set up serving of static pages from this folder
    app = connect().use(connect.static(__dirname)).listen(8080),

    // set up web service port
    io = require('socket.io').listen(app);
    
    console.log('http server on 8080');

// osc client
var osc = require('node-osc'),
    oscClient = new osc.Client('localhost', 57120);
    console.log('osc client on 57120');

// osc server
var oscServer = new osc.Server(4444, '0.0.0.0');
    console.log('osc server on 4444');
    

////////////////////////////////////////////////////////////////////////////////
// widget management and messaging to web clients is handled here
////////////////////////////////////////////////////////////////////////////////

// a collection to store info about our widgets - this cache is used to update 
// new clients upon connection
var widgets = {};

// creates a widget
function createWidget(name, type, x, y, w, h) {
    // update our cache of widget information
    widgets[name] = {
        'name': name,
github MAKIO135 / aioi / desktop / js / clients.js View on Github external
const sendFromInput = (index, inputString) => {
        const client = clients[index];
        
        if (client.type === 'udp') {
            client.send(Buffer.from(inputString), sendCallback);
        }
        else {
            if (!inputString.startsWith('/')) {
                inputString = `/${inputString}`;
                document.querySelector(`p.msg[data-index="${index}"]`).innerText = inputString;
            }
            
            const [path, ...args] = inputString.split(' ').filter(d => d !== '');
            client.path = path;
            const oscMsg = new osc.Message(`${path}`);
        
            args.map((arg) => {
                    // Float
                    if (/\b\d+\.d?\b/.test(arg) || /\b\d?\.d+\b/.test(arg)) return { type: 'f', value: parseFloat(arg) };
                    // Integer
                    else if (/\b\d+\b/.test(arg)) return parseInt(arg);
                    // String
                    return `${arg}`;
                })
                .forEach(arg => oscMsg.append(arg));
            client.send(oscMsg, sendCallback);
        }

        client.oscString = client.udpString = inputString;
        
        const updatedHost = {
github MAKIO135 / aioi / desktop / js / clients.js View on Github external
helpers.saveConfig();
                    
                    app.ui.bangHost(index);
                });

            return;
        }
        
        if (clientPath.includes('#')) { // specified hosts 
            const [clientArg, pathArg] = clientPath.split('#');
            indices = clientArg.split('').map(d=>parseInt(d, 36));
            path = `/${pathArg}`;
            udpMsg = Buffer.from(`${msg}`.split('#')[1]);
        }
        
        const oscMsg = new osc.Message(path);
        oscArgs.forEach(arg => oscMsg.append(arg));

        const oscString = oscArgs.reduce((acc, arg) => {
            return acc.concat(arg.value !== undefined ? arg.value : arg);
        }, [path]).join(' ');
        
        indices.filter((index) => index < clients.length)
            .forEach((index) => {
                const client = clients[index];
                client.send(client.type === 'udp' ? udpMsg : oscMsg, sendCallback);

                client.path = path;
                client.oscString = oscString;
                client.udpString = `${udpMsg}`;
                    
                const updatedHost = {
github stimulant / ampm / model / network.js View on Github external
}

        //// Set up OSC connection from app.
        this.transports.oscFromApp = new osc.Server(this.get('oscFromAppPort'));

        // handle straight messages
        this.transports.oscFromApp.on('message', _.bind(function(message, info) {
            // handle bundles
            if (message[0] == '#bundle')
                this._handleOsc(this.transports.oscFromApp, message[2], info);
            else
                this._handleOsc(this.transports.oscFromApp, message, info);
        }, this));

        //// Set up OSC connection to app.
        this.transports.oscToApp = new osc.Client('127.0.0.1', this.get('oscToAppPort'));

        //// Set up socket connection to app.
        this.transports.socketToApp = ioServer.listen(this.get('socketToAppPort'));
    },
github kn0ll / osc.io / lib / osc.io.js View on Github external
function client_channel_handler(socket) {
  var ns = socket.namespace.name,
    port = parse_io_ns_option(ns),
    osc_client = new osc.Client('127.0.0.1', port);

  // proxy osc messages from udp to socket.io
  // expects 'message' in form of [path, value]
  // ie. ['/osc/test', 200]
  socket.on('message', function(message) {
    osc_client.send(message[0], message[1]);
  });

  // expose a method to modify the client host. see readme.
  // at the moment, this just creates a whole new
  // client rather than configuring the host
  // of the existing client.
  socket.on('set-host', function(host) {
    osc_client = new osc.Client(host, port);
  });
}
github termie / node-osc / examples / client.js View on Github external
var osc = require('node-osc');

var client = new osc.Client('127.0.0.1', 3333);
client.send('/oscAddress', 1, 1, 2, 3, 5, 8);

// or
// var msg =  new osc.Message('/address')
// msg.append("testing");
// msg.append("testing");
// msg.append(123);
// client.send(msg)

// or
// var msg = new osc.Message('/address', 1, 2, 3);
// client.send(msg);
github stimulant / ampm / model / network.js View on Github external
key: 'sessionId',
                secret: secret,
                store: store,
                success: function(data, accept) {
                    logger.info('Socket access authorized for user', data.user);
                    accept(null, true);
                },
                fail: function(data, message, error, accept) {
                    logger.info('Socket access unauthorized.', message, error);
                    accept(null, false);
                }
            }));
        }

        //// Set up OSC connection from app.
        this.transports.oscFromApp = new osc.Server(this.get('oscFromAppPort'));

        // handle straight messages
        this.transports.oscFromApp.on('message', _.bind(function(message, info) {
            // handle bundles
            if (message[0] == '#bundle')
                this._handleOsc(this.transports.oscFromApp, message[2], info);
            else
                this._handleOsc(this.transports.oscFromApp, message, info);
        }, this));

        //// Set up OSC connection to app.
        this.transports.oscToApp = new osc.Client('127.0.0.1', this.get('oscToAppPort'));

        //// Set up socket connection to app.
        this.transports.socketToApp = ioServer.listen(this.get('socketToAppPort'));
    },

node-osc

pyOSC inspired library for sending and receiving OSC messages

LGPL-3.0
Latest version published 2 months ago

Package Health Score

74 / 100
Full package analysis