var MessageHandler = (function () { // Handlers for each message type var animation = "slideDown"; var handlers = { announcement: function (data) { var myObject = JSON.parse(data); var liveScreen = document.getElementById("auctionProductLiveScreenBox"); if (!liveScreen) { toastr.info(`
${myObject.message}
`, myObject.title, { "closeButton": true, "positionClass": "toast-bottom-left", "newestOnTop": true, "progressBar": true, "preventDuplicates": false, "onclick": null, "showDuration": "30000", "hideDuration": "1000", "timeOut": "5000", "extendedTimeOut": "1000", "showEasing": "swing", "hideEasing": "linear", "showMethod": animation, "hideMethod": "fadeOut" }); $('.toast-info').css("background-color", "#008080"); } }, bidNotification: function (data) { var audio = new Audio('../Plugins/Misc.AuctionPlugin/Content/ding.mp3'); audio.play(); console.log(data); var myObject = JSON.parse(data); console.log(myObject); var auctionDto = myObject.auctionDto; var productToAuctionDto = auctionDto.productToAuctionDtos[0]; //var productAuctionMappingId = productToAuctionDto.id; //console.log(productAuctionMappingId); var publicProductBidBox = document.getElementById("publicProductBidBox"); var liveScreen = document.getElementById("auctionProductLiveScreenBox"); var publicInfo = document.getElementById("publicInfoOverlay" + productToAuctionDto.productId); if (publicProductBidBox) { refreshPublicBidBox(myObject); } if (publicInfo) { var functionName = "refreshPublicInfo" + productToAuctionDto.productId; window[functionName](auctionDto); } if (liveScreen) { reloadOnUpdate(); } else { toastr.success(`

${myObject.currentPrice}

${myObject.productName}

`, "New bid arrived", { "closeButton": true, "positionClass": "toast-bottom-left", "newestOnTop": true, "progressBar": true, "preventDuplicates": false, "onclick": null, "showDuration": "30000", "hideDuration": "1000", "timeOut": "5000", "extendedTimeOut": "1000", "showEasing": "swing", "hideEasing": "linear", "showMethod": animation, "hideMethod": "fadeOut" }); $('.toast-success').css("background-color", "#4caf50"); } }, ProductToAuctionStatusNotification: function (data) { console.log(data); var myObject = JSON.parse(data); var auctionDto = myObject.auctionDto; var productToAuctionDto = auctionDto.productToAuctionDtos[0]; var publicProductBidBox = document.getElementById("publicProductBidBox"); var liveScreen = document.getElementById("auctionProductLiveScreenBox"); var publicInfo = document.getElementById("publicInfoOverlay" + productToAuctionDto.productId); if (!liveScreen) { var messageTitle = ""; var messageText = ""; var messageColor = ""; switch (productToAuctionDto.auctionStatus) { case AuctionStatus.None: messageTitle = `Item reset`; messageText = `The bids on item with index ${productToAuctionDto.sortIndex} has been resetted`; messageColor = "#6c757d"; break; case AuctionStatus.Active: messageTitle = `Item activated`; messageText = `The bids on item with index ${productToAuctionDto.sortIndex} has been activated`; messageColor = "#4caf50"; break; case AuctionStatus.FirstWarning: messageTitle = `First warning!`; messageText = `Hurry up! If no more bids, this item will be closed soon!`; messageColor = "#ffc107"; break; case AuctionStatus.SecondWarning: messageTitle = `Second warning!`; messageText = `Hurry up! If no more bids, this item will be closed soon!`; messageColor = "#dc3545"; break; case AuctionStatus.Pause: messageTitle = `Administrative message`; messageText = `The administrator has suspended the auction, it will go on soon probably`; messageColor = "#6c757d"; break; case AuctionStatus.Sold: messageTitle = `Item sold!`; messageText = `The item has been sold, we are transitioning to the next item!`; messageColor = "#4caf50"; break; case AuctionStatus.NotSold: messageTitle = `Item closed!`; messageText = `The item has been closed, we are transitioning to the next item!`; messageColor = "#6c757d"; break; default: break; } toastr.success(`

${messageText}

`, messageTitle, { "closeButton": true, "positionClass": "toast-bottom-left", "newestOnTop": true, "progressBar": true, "preventDuplicates": false, "onclick": null, "showDuration": "30000", "hideDuration": "1000", "timeOut": "5000", "extendedTimeOut": "1000", "showEasing": "swing", "hideEasing": "linear", "showMethod": animation, "hideMethod": "fadeOut" }); $('.toast-success').css("background-color", messageColor); } if (publicProductBidBox) { handleAuctionUpdate(myObject); } if (liveScreen) { reloadOnUpdate(); } if (publicInfo) { var functionName = "refreshPublicInfo" + productToAuctionDto.productId; window[functionName](auctionDto); } // var publicProductBidBox = document.getElementById("publicProductBidBox"); // if (publicProductBidBox) // { // refreshPublicBidBox(myObject); // } }, //openItemMessage: function (data) { // var myObject = JSON.parse(data); // toastr.success(`

${myObject.nextBidPrice}

${myObject.productName}

`, "Item auction is OPENED!", { // "closeButton": true, // "positionClass": "toast-top-right", // "newestOnTop": true, // "progressBar": true, // "preventDuplicates": false, // "onclick": null, // "showDuration": "30000", // "hideDuration": "1000", // "timeOut": "5000", // "extendedTimeOut": "1000", // "showEasing": "swing", // "hideEasing": "linear", // "showMethod": animation, // "hideMethod": "fadeOut" // }); // $('.toast-success').css("background-color", "#4caf50"); // var publicProductBidBox = document.getElementById("publicProductBidBox"); // if (publicProductBidBox) { // refreshPublicBidBox(myObject); // } //}, // Add more handlers as needed default: function (data) { console.warn("Unhandled message type:", data); } }; // Message router to route to the appropriate handler based on message type function messageRouter(message) { // Parse the JSON message try { var parsedMessage = JSON.parse(message); var messageType = parsedMessage.messageType; var senderId = parsedMessage.senderId; var messageData = parsedMessage.data; console.log("Message type:" + messageType); console.log("Message sender:" + senderId); console.log("Message content" + parsedMessage.data); // Route to appropriate handler, default if no match (handlers[messageType] || handlers.default)(messageData); } catch (e) { console.error("Error parsing message:", e); } } return { handle: messageRouter }; })();