diff --git a/src/app/services/socket-connection-mcr.service.ts b/src/app/services/socket-connection-mcr.service.ts
index 9b6374b81..b2c71b7fe 100644
--- a/src/app/services/socket-connection-mcr.service.ts
+++ b/src/app/services/socket-connection-mcr.service.ts
@@ -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)
diff --git a/src/app/shared/publication/new-publication/new-publication.page.html b/src/app/shared/publication/new-publication/new-publication.page.html
index 4c4b9a21a..4af2e6448 100644
--- a/src/app/shared/publication/new-publication/new-publication.page.html
+++ b/src/app/shared/publication/new-publication/new-publication.page.html
@@ -56,7 +56,7 @@