Skip to content

Websocket Client Plugin

Andreas Dzialocha edited this page Nov 1, 2018 · 11 revisions

Basic setup

The WebsocketClientPlugin is the default plugin of osc-js. Usally you dont have to mention it explicitly, except when you need custom configuration.

It defaults to ws://localhost:8080 for connecting to a WebSocket server.

<button id="send">Send Message</button>
<script type="text/javascript" src="lib/osc.min.js"></script>
<script type="text/javascript">
  var osc = new OSC();
  osc.open(); // connect by default to ws://localhost:8080

  document.getElementById('send').addEventListener('click', () => {
    var message = new OSC.Message('/test/random', Math.random());
    osc.send(message);
  });
</script>

Options

The options can be passed on inside the constructor or open method (see example below).

{
  host: 'localhost',    // @param {string} Hostname of WebSocket server
  port: 8080            // @param {number} Port of WebSocket server
}

Examples

const plugin = new OSC.WebsocketClientPlugin({ port: 9912 })
const osc = new OSC({ plugin: plugin })
osc.open()
// recommended approach
const osc = new OSC() // defaults to WebsocketClientPlugin
osc.open({ port: 9912 })

Further reading

  • Documentation: Read about the WebsocketClientPlugin class here.