|
|
|
@ -1,15 +1,21 @@
|
|
|
|
|
var connection = new signalR.HubConnectionBuilder().withUrl(hubUrl).withAutomaticReconnect().build();
|
|
|
|
|
var connection = new signalR.HubConnectionBuilder().withUrl(hubUrl).build();
|
|
|
|
|
var connectionId;
|
|
|
|
|
var connectionKeeper;
|
|
|
|
|
function connect() {
|
|
|
|
|
console.log('check connection state :' + connection.state);
|
|
|
|
|
if (connection.state === signalR.HubConnectionState.Disconnected) {
|
|
|
|
|
connection.start().then(function () {
|
|
|
|
|
console.log('signalR 连接成功');
|
|
|
|
|
}).catch(function (err) {
|
|
|
|
|
console.log(err);
|
|
|
|
|
setTimeout(connect, 15 * 1000);
|
|
|
|
|
console.log('connect successful');
|
|
|
|
|
}).catch(function () {
|
|
|
|
|
console.log('connect failed');
|
|
|
|
|
setTimeout(connect,5000);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
connection.onclose(function () {
|
|
|
|
|
console.log('connect closed');
|
|
|
|
|
connect();
|
|
|
|
|
});
|
|
|
|
|
connection.on('Connected', function (id) {
|
|
|
|
|
connectionId = id;
|
|
|
|
|
console.log('signalR 连接Id:' + connectionId);
|
|
|
|
|