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) { console.log(method + ':' + message); PubSub.publish(method, {message:message,to:to,from:from}); }); connect();