Permalink
Browse files

Step 2. Add client script to handle midi connection

  • Loading branch information...
alexeybondarenko committed Aug 5, 2017
1 parent 25281f6 commit ea94c5976dc7d0b1da13b0ef8769fa5741e984bc
Showing with 33 additions and 0 deletions.
  1. +30 −0 client/app.js
  2. +2 −0 server/index.js
  3. +1 −0 server/views/index.ejs
@@ -0,0 +1,30 @@
(function() {
'use strict';
console.log('App is running');
var midiAccess = null;
navigator.requestMIDIAccess().then(onMidiAccessSuccess, onMidiAccessFailure);
function onMidiAccessSuccess(access) {
midiAccess = access;
var inputs = midiAccess.inputs;
var inputIterators = inputs.values();
var firstInput = inputIterators.next().value;
if (!firstInput) return;
firstInput.onmidimessage = handleMidiMessage;
}
function onMidiAccessFailure(error) {
console.log('Oops. Something were wrong with requestMIDIAccess', error.code);
}
function handleMidiMessage(e) {
console.log(e);
}
})();
@@ -8,6 +8,8 @@ app.set('PORT', process.env.PORT || 3000);
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, './views'));
app.use('/client', Express.static(path.join(__dirname, '../client')));
app.get('/', (request, response) => {
response.render('index');
});
@@ -1,6 +1,7 @@
<html>
<head>
<title>MIDI API tutorials</title>
<script type="text/javascript" src="client/app.js"></script>
</head>
<body>
<h1>MIDI API. Hello!</h1>

0 comments on commit ea94c59

Please sign in to comment.