Mango.Nop.Plugins/Nop.Plugin.Misc.AuctionPlugin/Content/Js/LiveAnnouncement.js

136 lines
3.4 KiB
JavaScript

// Define the message handler library
// SignalR connection setup
$(function () {
console.log("signalRJs Starts");
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();
});
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();
});
// Function to send a message to the server
//$(function () {
// console.log("signalRJs Starts");
// var connection = new signalR.HubConnectionBuilder()
// .withUrl('/auctionhub')
// .build();
// connection.on('send', data => {
// showannouncement(data);
// });
// function start() {
// connection.start().catch(function (err) {
// setTimeout(function () {
// start();
// }, 100000);
// });
// }
// connection.onclose(function () {
// start();
// });
// start();
//});
//function showannouncement(announcemant) {
// console.log("announcement arrived!");
// if (announcemant) {
// toastr.options = {
// "closeButton": true,
// "debug": false,
// "newestOnTop": false,
// "progressBar": false,
// "positionClass": "toast-bottom-right",
// "preventDuplicates": false,
// "onclick": null,
// "showDuration": 300,
// "hideDuration": 10000,
// "timeOut": 100000,
// "extendedTimeOut": 20000,
// "showEasing": "swing",
// "hideEasing": "linear",
// "showMethod": "fadeIn",
// "hideMethod": "fadeOut"
// };
// tostView = '<div class="item announcemantToast">' + announcemant + '</div>'
// toastr["info"](tostView);
// $('.toast-info').css("background-color", "#008080");
// toastr.options.onclick = function () {
// $("html, body").animate(
// { scrollTop: 0 },
// 1000);
// }
// $(".toast").click(function () {
// $("html, body").animate(
// { scrollTop: 0 },
// 1000);
// });
// $(".toast-info").click(function () {
// $("html, body").animate(
// { scrollTop: 0 },
// 1000);
// });
// toastr.options = {
// onclick: function () {
// $("html, body").animate(
// { scrollTop: 0 },
// 1000);
// }
// }
// $(".announcemantToast").on("click", function () {
// $("html, body").animate(
// { scrollTop: 0 },
// 1000);
// });
// }
//}