Use JZZ.WS for advanced network setups, or when it is impossible to connect MIDI instrument directly to your device (e.g. VR headsets).
For quick testing, please check the WebSocket MIDI Server at GitHub.
WebSocket MIDI suggests a server that exposes MIDI ports over the network, and a single or multiple clients that communicate with these ports.
For a symmetric peer-to-peer connection, please check JZZ.RTC.
// in Node.js: var JZZ = require('jzz'); require('jzz-midi-ws')(JZZ);
// or in HTML: <script src="JZZ.js"></script> <script src="JZZ.midi.WS.js"></script>
Makes remote MIDI ports visible locally.
JZZ.WS.connect(ws, timeout) - connect to the remote server (see below),
where ws - the WebSocket address, normally in the form host:port,
timeout - (optional) time after which the call fails if not connectedd successfully;
default: 5s.
client.close() - disconnect and close all associated MIDI ports.
var connection = JZZ.WS.connect('ws://localhost:8888').or('Cannot open websocket!').and(function() { JZZ().openMidiOut('ws://localhost:8888 - Microsoft GS Wavetable Synth') .noteOn(0, 'C5', 127) .wait(500); .noteOff(0, 'C5') .and(function() { connection.close(); }); });
Exposes local MIDI ports to remote clients.
var server = new JZZ.WS.Server(wss) - create a MIDI via WebSocket server,
where wss - an underlying WebSocket server (secure or insecure).
server.addMidiIn(name, port) - expose local MIDI-In port to remote clients,
where name - MIDI port name; port - local MIDI port (real or virtual).
Clients will see this port as "{url} - {name}".
server.addMidiOut(name, port) - expose local MIDI-Out port to remote clients, all as above.
server.removeMidiIn(name) - hide local MIDI-In port from remote clients; name - port name.
server.removeMidiOut(name) - hide local MIDI-Out port from remote clients, all as above.
const ws = require('ws'); const JZZ = require('jzz'); require('jzz-midi-ws')(JZZ); // start a WebSocket server const wss = new ws.Server({ port: 8888 }); // start a MIDI via WebSockets server const server = new JZZ.WS.Server(wss); // add actual MIDI ports JZZ().and(function() { var info = JZZ().info(); for (var p of info.inputs) server.addMidiIn(p.id, JZZ().openMidiIn(p.id)); for (var p of info.outputs) server.addMidiOut(p.id, JZZ().openMidiOut(p.id)); }); // and/or virtual ports server.addMidiIn('Dummy', JZZ.Widget()); server.addMidiOut('Debug', JZZ.Widget({ _receive: function(msg) { console.log(msg.toString()); }}));