system-bus-radio/In Javascript/airgap.js
William Entriken efc865ddd6 Merge branch 'master' of https://github.com/rocketinventor/system-bus-radio into rocketinventor-master
* 'master' of https://github.com/rocketinventor/system-bus-radio:
  Added comments to source code
  Implemented Web Workers
  Preperations for web using a worker
  moved var definition
  created var for window log
  fixed description meta
  Added a delay function and fixed time being *1000.
  improved link styling
  removed red outline around text box
  removed more unused CSS
  removed unused and unrelated  CSS classes
  Improved formatting
2016-11-30 21:44:10 -05:00

29 lines
845 B
JavaScript

var player; // Define "player" var to make my code linter happy
function start() { // Start Web Worker & send song data to player
var logs = document.getElementById('logs'); // Define log element
// Create Web Worker if it doesn't already exist
if (window.Worker && typeof(player) == "undefined") {
var player = new Worker("worker.js");
window.player = player; // Make variable Global
player.onmessage = function(event) {
var data = event.data;
window.logs.value += data;
};
// Send song data to player
var song = document.getElementById("tones").innerHTML;
player.postMessage(song);
}
}
function end() { // Stops the Web Worker
player.terminate();
}
function pause(time) {
window.logs.value += "\nPaused / " + time*.001 + " seconds";
var dt = new Date();
while ((new Date()) - dt <= time) { /* Do nothing */ }
}