Permalink
Browse files

Step 3. Add BinaryJS to client.

  • Loading branch information...
alexeybondarenko committed Aug 5, 2017
1 parent ea94c59 commit 255c1d77d5c676e32cea1f4ba81d17c44dc21265
Showing with 25 additions and 0 deletions.
  1. +22 −0 client/app.js
  2. +1 −0 package.json
  3. +1 −0 server/index.js
  4. +1 −0 server/views/index.ejs
@@ -3,6 +3,26 @@
console.log('App is running');
// WEBSOCKETS
var client = new BinaryClient('ws://' + location.hostname + ':3001');
var MIDIStream = null;
client.on('open', function () {
MIDIStream = client.createStream();
MIDIStream.on('data', handleReceiveAudioData);
MIDIStream.on('end', handleEndAudioStream);
});
function handleReceiveAudioData(data) {
console.log('receive audio data', data);
}
function handleEndAudioStream(data) {
console.log('end', data);
}
// MIDI access
var midiAccess = null;
navigator.requestMIDIAccess().then(onMidiAccessSuccess, onMidiAccessFailure);
@@ -24,6 +44,8 @@
function handleMidiMessage(e) {
console.log(e);
if (!MIDIStream || e.data[0] !== 0x90) return;
MIDIStream.write(e.data);
}
@@ -10,6 +10,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"binaryjs": "^0.2.1",
"ejs": "^2.5.7",
"express": "^4.15.3"
}
@@ -9,6 +9,7 @@ app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, './views'));
app.use('/client', Express.static(path.join(__dirname, '../client')));
app.use('/modules', Express.static(path.join(__dirname, '../node_modules')));
app.get('/', (request, response) => {
response.render('index');
@@ -1,6 +1,7 @@
<html>
<head>
<title>MIDI API tutorials</title>
<script type="text/javascript" src="modules/binaryjs/dist/binary.js"></script>
<script type="text/javascript" src="client/app.js"></script>
</head>
<body>

0 comments on commit 255c1d7

Please sign in to comment.