mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
dix bugs
This commit is contained in:
@@ -81,45 +81,66 @@ class ReconnectingWebSocketSignalR {
|
||||
|
||||
connect() {
|
||||
console.log("try to connect=================================")
|
||||
this.stop = false
|
||||
this.stop = false;
|
||||
|
||||
// Limpar a conexão anterior, se existir
|
||||
|
||||
if (this.connection && this.connection.state !== signalR.HubConnectionState.Disconnected) {
|
||||
this.connection.stop();
|
||||
}
|
||||
|
||||
this.connection = new signalR.HubConnectionBuilder()
|
||||
.withUrl("https://gdcmapi-dev.dyndns.info/FileHub", {
|
||||
transport: signalR.HttpTransportType.LongPolling,
|
||||
accessTokenFactory: () => SessionStore.user.Authorization
|
||||
}).configureLogging(signalR.LogLevel.Information)
|
||||
.build();
|
||||
|
||||
.withUrl('https://gdcmapi-dev.dyndns.info/FileHub', {
|
||||
transport: signalR.HttpTransportType.LongPolling,
|
||||
accessTokenFactory: () => SessionStore.user.Authorization
|
||||
})
|
||||
.configureLogging(signalR.LogLevel.Information)
|
||||
.build();
|
||||
|
||||
this.connection.start()
|
||||
.then(() => {
|
||||
this.isOpen = true;
|
||||
console.log('WebSocket connection established');
|
||||
.then(() => {
|
||||
this.isOpen = true;
|
||||
console.log('WebSocket connection established');
|
||||
this.onConnect.forEach(callback => callback());
|
||||
this.whenConnected.forEach(callback => callback());
|
||||
|
||||
}).catch((error) => {
|
||||
|
||||
this.onConnect.forEach(callback => callback());
|
||||
this.whenConnected.forEach(callback => callback())
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error starting SignalR connection:", error);
|
||||
});
|
||||
console.error("Error starting SignalR connection:", error);
|
||||
// Adicione tratamento de erros detalhado conforme necessário
|
||||
// Exemplo: Verificar se o erro é devido à perda de conexão com a internet
|
||||
|
||||
if (error.message.includes("Failed to fetch")) {
|
||||
console.error("Erro de conexão com a internet");
|
||||
}
|
||||
// Tentar reconectar após um atraso
|
||||
if (!this.stop) {
|
||||
setTimeout(() => {
|
||||
this.connect();
|
||||
}, 1000); // Ajuste o atraso conforme necessário
|
||||
}
|
||||
});
|
||||
|
||||
this.connection.on("ReceiveMessage", (message) => {
|
||||
const data: any = JSON.parse(message)
|
||||
console.log("ReceiveMessage", data)
|
||||
|
||||
const data = JSON.parse(message);
|
||||
|
||||
console.log("ReceiveMessage", data);
|
||||
|
||||
this.callbacks.forEach(callback => callback(data));
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
this.connection.onclose((error) => {
|
||||
console.log('WebSocket connection closed..');
|
||||
this.isOpen = false;
|
||||
this.onDisconnect.forEach(callback => callback());
|
||||
// Attempt to reconnect after a delay
|
||||
if(this.stop == false) {
|
||||
// Tentar reconectar após um atraso
|
||||
if (!this.stop && (!error || error.message !== "Connection stopped by client.")) {
|
||||
setTimeout(() => {
|
||||
this.connect();
|
||||
}, 1000); // Adjust the delay as needed
|
||||
}, 1000); // Ajuste o atraso conforme necessário
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
@@ -179,7 +200,6 @@ class ReconnectingWebSocketSignalR {
|
||||
}
|
||||
|
||||
interface socketResponse {
|
||||
|
||||
index: string
|
||||
Guid: string
|
||||
IsCompleted: Boolean
|
||||
|
||||
Reference in New Issue
Block a user