Last active
June 8, 2019 13:01
-
-
Save alistairjevans/3a0fbcda65e799f5b182573e22dd6a49 to your computer and use it in GitHub Desktop.
Initial app javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
// Define my connection (note the /feed address to specify the hub) | |
var connection = new signalR.HubConnectionBuilder().withUrl("/feed").build(); | |
// Get the elements I need | |
var speedValue = document.getElementById("currentSpeed"); | |
var countValue = document.getElementById("currentCount"); | |
var resetButton = document.getElementById("reset"); | |
window.onload = function () { | |
// Start the SignalR connection | |
connection.start().then(function () { | |
console.log("Connected"); | |
}).catch(function (err) { | |
return console.error(err.toString()); | |
}); | |
resetButton.addEventListener("click", function () { | |
// When someone clicks the reset button, this | |
// will call the ResetCount method in my FeedHub. | |
connection.invoke("ResetCount"); | |
}); | |
}; | |
// This callback is going to fire every time I get new data. | |
connection.on("newData", function (time, speed, count) { | |
speedValue.innerText = speed; | |
countValue.innerText = count; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment