"use strict"; var connection = new signalR.HubConnectionBuilder().withUrl("/chatHub").withAutomaticReconnect().build(); //Disable the send button until connection is established. document.getElementById("sendButton").disabled = true; var msgcount = 0; connection.on("ReceiveMessage", function (topic, message) { if (msgcount > 10) { document.getElementById("messagesList").innerHTML = ""; msgcount = 0; } var li = document.createElement("li"); document.getElementById("messagesList").appendChild(li); // We can assign user-supplied strings to an element's textContent because it // is not interpreted as markup. If you're assigning in any other way, you // should be aware of possible script injection concerns. li.textContent = `${topic} --> ${message}`; msgcount = msgcount + 1; }); connection.start().then(function () { document.getElementById("sendButton").disabled = false; }).catch(function (err) { return console.error(err.toString()); }); document.getElementById("sendButton").addEventListener("click", function (event) { var topic = document.getElementById("topicInput").Data; var message = document.getElementById("messageInput").Data; connection.invoke("SendMessage", topic, message).catch(function (err) { return console.error(err.toString()); }); event.preventDefault(); }); //以下是接口交互相关的内容 //小车的定时状态,多个小车,只有在线小车才有实时数据 connection.on("JgrStatus", function (jgrStatus) { if (msgcount > 10) { document.getElementById("messagesList").innerHTML = ""; msgcount = 0; } var li = document.createElement("li"); document.getElementById("messagesList").appendChild(li); // We can assign user-supplied strings to an element's textContent because it // is not interpreted as markup. If you're assigning in any other way, you // should be aware of possible script injection concerns. li.textContent = `jgrStatus:${jgrStatus}`; msgcount = msgcount + 1; }); //工位的定时状态,多个工位 connection.on("StationStatus", function (stationStatus) { if (msgcount > 10) { document.getElementById("messagesList").innerHTML = ""; msgcount = 0; } var li = document.createElement("li"); document.getElementById("messagesList").appendChild(li); // We can assign user-supplied strings to an element's textContent because it // is not interpreted as markup. If you're assigning in any other way, you // should be aware of possible script injection concerns. li.textContent = `stationStatus:${stationStatus}`; msgcount = msgcount + 1; }); //充电桩的定时状态,多个充电桩,只有在线才会回传数据 connection.on("ChargingStatus", function (chargingStatus) { if (msgcount > 10) { document.getElementById("messagesList").innerHTML = ""; msgcount = 0; } var li = document.createElement("li"); document.getElementById("messagesList").appendChild(li); // We can assign user-supplied strings to an element's textContent because it // is not interpreted as markup. If you're assigning in any other way, you // should be aware of possible script injection concerns. li.textContent = ` chargingStatus:${chargingStatus}`; msgcount = msgcount + 1; });