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

27 lines
772 B

var hubUrl = config.baseUrl +'/IoTCenter/hub?group=page';
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 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;
});
connection.on("ServerToClient", function (method, message, to, from) {
PubSub.publish(method, {message:message,to:to,from:from});
});
connect();