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/IoTNode/wwwroot/js/signalr.js

28 lines
786 B

var connection = new signalR.HubConnectionBuilder().withUrl(config.hubUrl).build();
var connectionId;
function connect() {
if (connection.state === signalR.HubConnectionState.Disconnected) {
connection.start().then(function () {
console.log('signalr connected');
}).catch(function (err) {
console.log(err);
setTimeout(connect, 5000);
});
}
}
connection.onclose(function () {
console.log('connect closed');
connect();
});
connection.on('Connected', function (id) {
connectionId = id;
PubSub.publish('Connected');
});
connection.on("ServerToClient", function (method, message, to, from) {
console.log(method);
PubSub.publish(method, { message: message, to: to, from: from });
});
connect();