Skip to content

Instantly share code, notes, and snippets.

@marcoscaceres
Last active December 10, 2015 04:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcoscaceres/4384745 to your computer and use it in GitHub Desktop.
Save marcoscaceres/4384745 to your computer and use it in GitHub Desktop.
Re-imagining the Web MIDI API security model as well as some other parts... this is just a strawman.

Thinking about the security model.

Lets say I'm a making game... I want to just use the system's standard output.

This case handles the user having a standard output port, plus the user has plugged in some other output device.

(function() {
  var midi = navigator.midi, 
      out;
  //going to try to get the output ports... 
  try{
    out = midi.outputs();
    //got it! no problem. 
    outputReady(out);
    
  //could not get access...   
  }catch(e){
    //we don't have permission
    if(e.name === "SecurityError"){
        //request could take "inputs" "outputs" "all"
        midi.request("outputs", success, fail);
    }
  }
  
  //reqested ports can be in an object {inputs: null, outputs: [...]}
  function success(ports){ 
     outputReady(ports.outputs)
  }
  
  function outputReady(out){
    if(out.length > 0){
        ...    
    }
  }
 
  function fail(){}
}());

Having a midi object could give a way to listen to all incoming messages.

navigator.midi.onmessage = function(e){
      
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment