Using SignalR in Electron with Webpack

I’m putting together my first application using Electron (formerly atom-shell). My use case involves a Knockout frontend and a .NET console app which interacts with hardware. The console app is launched by the main node process. To communicate with the frontend I’m self hosting SignalR on OWIN. I’m using webpack in my build process and had a difficult time getting SignalR set up properly. Here’s how I made it work.

// In my index.js file:
// ugly jquery hack for signalr
(typeof global !== "undefined" ? global : window).$ = (typeof global !== "undefined" ? global : window).jQuery = require("jquery");
require("signalr");

// in my model:
this.ConnectToServer = () => {
	try {
		var connection = $.hubConnection("http://localhost:8003/signalr/hubs");
		var proxy = connection.createHubProxy("deviceHub");

		// define client-side methods:
		proxy.on("scannerEvent", (apiData) => {
			console.log(JSON.stringify(apiData));
		});

		// auto-reconnect logic:
		var tryingToReconnect = false;
		connection.connectionSlow(() => {
			//notify.connectionState("slow");
		});
		connection.reconnecting(() => {
			tryingToReconnect = true;
			//notify.connectionState("reconnecting");
		});
		connection.reconnected(() => {
			tryingToReconnect = false;
			//notify.connectionState("connected");
		});
		connection.disconnected(() => {
			tryingToReconnect = false;
			//notify.connectionState("disconnected");
			if(connection.lastError)
			{
				console.log("Disconnected. Reason: " +  connection.lastError.message);
			}
			setTimeout(function() {
				connection.start();
			}, 5000); // Restart connection after 5 seconds.
		});
		connection.start(() => {
			//notify.connectionState("connected");
		});
	} catch (e) {
		console.log(e);
	}
}