You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
iot/projects/IoTCenter/wwwroot/js/message.js

20 lines
694 B

var connection = new signalR.HubConnectionBuilder().withUrl(hubUrl).build();
var connectionId;
function connect() {
if (connection.state === signalR.HubConnectionState.Disconnected) {
connection.start().then(function () {
console.log('signalR 连接成功');
}).catch(function (err) {
console.log(err);
setTimeout(connect, 15 * 1000);
});
}
}
connection.on('Connected', function (id) {
connectionId = id;
console.log('signalR 连接Id:' + connectionId);
});
connection.on("ServerToClient", function (method, message, to, from) {
console.log(method + ':' + message);
onMessage(method, message, to, from);
});