rodgc / ngx-socket-io

Socket.IO module for Angular
MIT License
261 stars 89 forks source link

Angular ngx-socket-io duplicates message #116

Closed moti-malka closed 2 months ago

moti-malka commented 2 years ago

When I connect to the socket event for the first time I get the number of messages from the server (python flask_socket) properly but when I close the window and do socket.disconnect() and connect again using socket.connect() I get the same messages twice for example: If for the first time I get 100 messages then after closing and reopening the window I get 200 messages. On the server side it seems to be sending the correct number of messages I think I'm not really doing something right on the client side

server.py

@socketio.on('join_log_request')
def join_log_request(containerid, sessionId):

    container_logs = Sdk.docker_client.logs(containerid, stream=True, timestamps=True)   

    while True:
        try:
            log = next(container_logs).decode("utf-8")
            socketio.emit('stream_logs_response', {'log': log,  'containerid':containerid, 'sessionId':sessionId })
            print(sessionId)
            socketio.sleep(0)

        except StopIteration:
            socketio.emit('stream_logs_response', {'log': 'CONTAINER NOT RUNNING','containerid':containerid, 'sessionId':sessionId })
            break

client.ts

containerLogs(container: Container): void {

    this.socket.ioSocket.connect();

    this.sessionId = UUID.UUID()

    console.log('Connect sessionId: ' + this.sessionId)

    this.logContainerContext = container;

    this.sidenav_logs = true;

    this.socket.emit('join_log_request', container.id, this.sessionId);

    this.socket.on('stream_logs_response', (response: any) =>{
      console.log(response.sessionId)
      if(response.sessionId == this.sessionId){
          this.logs.push(response.log)
      }  
    })
  }
github-actions[bot] commented 2 months ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 2 months ago

This issue was closed because it has been inactive for 7 days since being marked as stale.