mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-20 05:16:07 +00:00
fix signalR
This commit is contained in:
@@ -70,16 +70,13 @@ export class SocketConnectionMCRService {
|
||||
class ReconnectingWebSocketSignalR {
|
||||
|
||||
private connection: any
|
||||
isOpen: boolean
|
||||
isOpen: boolean = false
|
||||
private callbacks: Function[] = []
|
||||
private onDisconnect: Function[] = []
|
||||
private onConnect: Function[] = []
|
||||
private stop = true
|
||||
|
||||
constructor() {
|
||||
this.isOpen = false;
|
||||
this.connect();
|
||||
}
|
||||
constructor() {}
|
||||
|
||||
connect() {
|
||||
console.log("try to connect=================================")
|
||||
@@ -113,11 +110,11 @@ class ReconnectingWebSocketSignalR {
|
||||
})
|
||||
|
||||
this.connection.onclose((error) => {
|
||||
console.log('WebSocket connection closed');
|
||||
console.log('WebSocket connection closed..');
|
||||
this.isOpen = false;
|
||||
this.onDisconnect.forEach(callback => callback());
|
||||
// Attempt to reconnect after a delay
|
||||
if(this.stop) {
|
||||
if(this.stop == false) {
|
||||
setTimeout(() => {
|
||||
this.connect();
|
||||
}, 1000); // Adjust the delay as needed
|
||||
@@ -128,16 +125,18 @@ class ReconnectingWebSocketSignalR {
|
||||
|
||||
disconnect() {
|
||||
this.stop = true
|
||||
this.connection.stop()
|
||||
.then(() => {
|
||||
console.log('WebSocket connection closed');
|
||||
this.isOpen = false;
|
||||
this.onDisconnect.forEach(callback => callback());
|
||||
console.log("SignalR connection stopped.");
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error stopping SignalR connection:", error);
|
||||
});
|
||||
if(this.isOpen == true) {
|
||||
this.connection.stop()
|
||||
.then(() => {
|
||||
console.log('WebSocket connection was closed by client');
|
||||
this.isOpen = false;
|
||||
this.onDisconnect.forEach(callback => callback());
|
||||
console.log("SignalR connection stopped.");
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error stopping SignalR connection by client:", error);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
subscribe(callback) {
|
||||
@@ -160,7 +159,7 @@ interface socketResponse {
|
||||
|
||||
index: string
|
||||
Guid: string
|
||||
isCompleted: Boolean
|
||||
IsCompleted: Boolean
|
||||
}
|
||||
// class ReconnectingWebSocket {
|
||||
|
||||
@@ -256,7 +255,7 @@ interface socketResponse {
|
||||
// // })
|
||||
|
||||
// // this.socket.subscribe((data: socketResponse) => {
|
||||
// // if(data.isCompleted == true) {
|
||||
// // if(data.IsCompleted == true) {
|
||||
// // this.callbacks[data.Guid](data)
|
||||
// // delete this.callbacks[data.Guid]
|
||||
// // }
|
||||
@@ -302,38 +301,48 @@ export class ObjectMergeNotification{
|
||||
callbacks: {[GUID: string]: Function} = {}
|
||||
runWatch = true
|
||||
CMAPIService: CMAPIService = window["CMAPIAPIRepository"]
|
||||
watchCount = 0
|
||||
|
||||
constructor() {
|
||||
this.socket.onDisconnectCallback(()=> {
|
||||
console.log("run watch")
|
||||
this.runWatch = true
|
||||
this.watch()
|
||||
})
|
||||
|
||||
this.socket.onConnectCallback(()=> {
|
||||
|
||||
console.log("open trigger")
|
||||
this.runWatch = false
|
||||
})
|
||||
|
||||
|
||||
this.socket.subscribe((data: socketResponse) => {
|
||||
if(data.isCompleted == true) {
|
||||
if(data.IsCompleted == true) {
|
||||
console.log("==================!!!====================")
|
||||
this.callbacks[data.Guid](data)
|
||||
delete this.callbacks[data.Guid]
|
||||
} else {
|
||||
console.log("else", data)
|
||||
}
|
||||
})
|
||||
|
||||
this.socket.connect();
|
||||
this.watch()
|
||||
}
|
||||
|
||||
|
||||
close() {
|
||||
console.log("close=============================================")
|
||||
this.socket.disconnect();
|
||||
this.watchCount = 0;
|
||||
this.runWatch = false
|
||||
}
|
||||
|
||||
async watch() {
|
||||
|
||||
this.watchCount = 0;
|
||||
|
||||
if(this.runWatch) {
|
||||
setTimeout(async ()=> {
|
||||
setTimeout(async () => {
|
||||
for(const [key, funx] of Object.entries(this.callbacks)) {
|
||||
|
||||
const request = await this.CMAPIService.getVideoHeader(key)
|
||||
@@ -344,7 +353,13 @@ export class ObjectMergeNotification{
|
||||
}
|
||||
}
|
||||
|
||||
this.watch()
|
||||
this.watchCount++
|
||||
if(this.watchCount <= 15) {
|
||||
this.watch()
|
||||
} else {
|
||||
this.runWatch = false
|
||||
}
|
||||
|
||||
}, 1000)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user