62 lines
1.5 KiB
JavaScript
62 lines
1.5 KiB
JavaScript
$(function () {
|
|
console.log("signalRJs Starts");
|
|
|
|
// 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",
|
|
});
|
|
|
|
// 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 () {
|
|
start();
|
|
});
|
|
|
|
// Global function to send a message to the server
|
|
window.sendMessageToServer = function (messageType, senderId, data) {
|
|
var messageWrapper = {
|
|
MessageType: messageType,
|
|
SenderId: senderId,
|
|
Data: data
|
|
};
|
|
|
|
connection.invoke("ReceiveMessageFromClient", messageWrapper)
|
|
.then(() => {
|
|
console.log("Message successfully sent to the server.");
|
|
})
|
|
.catch(err => {
|
|
console.error("Error sending message to the server:", err);
|
|
});
|
|
};
|
|
|
|
start();
|
|
});
|