$(function () { console.log("signalRJs Starts"); window.RequestCount = 0; // AuctionStatus Enum window.AuctionStatus = Object.freeze({ None: 0, Active: 1, FirstWarning: 2, SecondWarning: 4, Pause: 8, Sold: 16, NotSold: 32, TEST: 64 }); // HUF Formatter window.HUFFormatter = new Intl.NumberFormat("hu-HU", { style: "currency", currency: "HUF", }); window.EURFormatter = new Intl.NumberFormat("eu-EU", { style: "currency", currency: "EUR", }); // SignalR connection setup var connection = new signalR.HubConnectionBuilder() .withUrl("/auctionhub") .build(); connection.on("send", data => { MessageHandler.handle(data); }); function start() { connection.start().catch(function (err) { setTimeout(function () { start(); }, 100000); }); } connection.onclose(function () { window.RequestCount = 0; start(); }); // Global function to send a message to the server window.sendMessageToServer = function (messageType, senderId, data) { window.RequestCount++; var messageWrapper = { MessageType: messageType, SenderId: senderId, RequestCount: window.RequestCount, Data: data }; console.log("Before send message to the server! " + messageType); connection.invoke("ReceiveMessageFromClient", messageWrapper) .then(() => { console.log("Message successfully sent to the server! " + messageType); }) .catch(err => { //window.RequestCount--; console.error("Error sending message to the server! " + messageType, err); }); }; start(); });