Jazz-Soft.net
We make it sound!
Home » Documentation » JZZ.js » JZZ.RTC

JZZ.RTC - MIDI via WebRTC

Use JZZ.RTC in WebRTC sessions to let participants expose and access each other's MIDI ports.

For a quick start, please check the WebRTC MIDI test/demo at GitHub.

For client-server applications, please check JZZ.WS.

Usage

// in Node.js:
var JZZ = require('jzz');
require('jzz-midi-rtc')(JZZ);
// or in HTML:
<script src="JZZ.js"></script>
<script src="JZZ.midi.RTC.js"></script>

Peers

WebRTC is a symmetric peer-to-peer connection.
Each peer can both act as a server that exposes MIDI port to the remote peer, and as a client that can access remote MIDI ports.

constructor

var peer = new JZZ.RTC(name) - create a MIDI via WebSocket server,
where name - name to be used as preffix for remote MIDI ports. If not set, will be WebRTC, WebRTC1, WebRTC2, etc...

connect()

peer.connect(rtc) - connect to WebRTC session,
where rtc - a RTCPeerConnection object.

close()

peer.close() - disconnect and close all associated MIDI ports.

addMidiIn()

peer.addMidiIn(name, port) - expose local MIDI-In port to the remote peer,
where name - MIDI port name; port - local MIDI port (real or virtual).

addMidiOut()

peer.addMidiOut(name, port) - expose local MIDI-Out port to the remote peer, all as above.

removeMidiIn()

peer.removeMidiIn(name) - hide local MIDI-In port from the remote peer; name - port name.

removeMidiOut()

peer.removeMidiOut(name) - hide local MIDI-Out port from the remote peer, all as above.

Example

const ws = require('ws');
const JZZ = require('jzz');
require('jzz-midi-rtc')(JZZ);

// start a WebRTC session
var rtc = new RTCPeerConnection();
// ...
// ... skipped WebRTC boilerplate code ...
// ...

var peer = new JZZ.RTC();
peer.connect(rtc);

// add actual MIDI ports
JZZ().and(function() {
    var info = JZZ().info();
    for (var p of info.inputs) peer.addMidiIn(p.id, JZZ().openMidiIn(p.id));
    for (var p of info.outputs) peer.addMidiOut(p.id, JZZ().openMidiOut(p.id));
});
// and/or virtual ports
peer.addMidiIn('Dummy', JZZ.Widget());
peer.addMidiOut('Debug', JZZ.Widget({ _receive: function(msg) { console.log(msg.toString()); }}));

See also