Browse Source

* OnDisconnect called too often

Michaël Van Canneyt 3 years ago
parent
commit
50af4d0388

+ 2 - 2
packages/fcl-web/src/websocket/fpcustwsserver.pp

@@ -248,7 +248,7 @@ Type
     Property OnAllow : TWSAllowConnectionEvent Read FOnAllow Write FOnAllow;
     // Called when a text message is received.
     property OnMessageReceived: TWSMessageEvent read FOnMessageReceived write FOnMessageReceived;
-    // Called when a connection is disconnected. Sender is TWSServerConnection
+    // Called when a connection is disconnected. Sender is Self
     property OnDisconnect: TNotifyEvent read FOnDisconnect write FOnDisconnect;
     // Called when a control message is received.
     property OnControlReceived: TWSControlEvent read FOnControl write FOnControl;
@@ -549,7 +549,7 @@ end;
 procedure TCustomWSServer.DoDisconnect(Sender: TObject);
 begin
   if Assigned(OnDisconnect) then
-    OnDisconnect(Sender);
+    OnDisconnect(Self);
 end;
 
 procedure TCustomWSServer.FreeConnectionHandler;

+ 2 - 1
packages/fcl-web/src/websocket/fpwebsocket.pp

@@ -1746,7 +1746,8 @@ end;
 
 destructor TWSServerConnection.Destroy;
 begin
-  DisConnect;
+  if Assigned(FTransport) then
+    DisConnect;
   FreeAndNil(FExtraHeaders);
   inherited;
 end;