Skip to content

Instantly share code, notes, and snippets.

@alistairjevans
Last active June 8, 2019 13:01
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 alistairjevans/3a0fbcda65e799f5b182573e22dd6a49 to your computer and use it in GitHub Desktop.
Save alistairjevans/3a0fbcda65e799f5b182573e22dd6a49 to your computer and use it in GitHub Desktop.
Initial app javascript
"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