irigsoft Posted September 3, 2021 Share Posted September 3, 2021 Hello, I'm looking for a method to find out when the mobile browser is closed. (I use mobile browser with uniGui - Professional) In the example here: https://dev.to/melvin2016/how-to-check-if-an-opened-browser-window-is-closed-or-not-in-javascript-gn1 , it is possible when a window is opened to attach its handle to a variable: const openedWindow = window.open(....); , but how to do this when the main form or session starts. Another examples of this: http://www.javascriptkit.com/javatutors/openclose.shtml https://arstechnica.com/civis/viewtopic.php?f=20&t=694501 Is it possible this to make a job on uniTimer of MainForm (or some other Form) and OnAjaxEvent ? unISession.AddJS ('if (window.opener.closed) {ajaxRequest(uniVars._mFrm_,"UniLogout"); ajaxRequest(uniVars._mFrm_,"closed");}'); Quote Link to comment Share on other sites More sharing options...
Sherzod Posted September 3, 2021 Share Posted September 3, 2021 4 hours ago, irigsoft said: Is it possible this to make a job on uniTimer of MainForm (or some other Form) and OnAjaxEvent ? No... To do this, you must manually (programmatically) call the window.open() method, which actually creates a window object, which can be held in a variable and manipulated according to your program's requirements... Quote Link to comment Share on other sites More sharing options...
irigsoft Posted September 3, 2021 Author Share Posted September 3, 2021 17 minutes ago, Sherzod said: No... To do this, you must manually (programmatically) call the window.open() method, which actually creates a window object, which can be held in a variable and manipulated according to your program's requirements... Thank You. I wrote this on another topic, but if you can help me. I want to end sessions in which the browser is closed by the user. Everything is fine when using desktop browsers, but I have a problem with mobile ones. I have an idea: 1. I put a variable (LastChecked) in uniMainModule and I will update its value every 5 minutes with the session to which it belongs 2. In uniServerModule - uniThreatTimer the value for each active session will be checked. 3. In each session I have a uniTimer to display the active date / time. So, through uniServerModule every 5 minutes I will check the value of the variable and if it is not updated, then the session will be closed How to get the value of a variable from a specific active session in unIServerModule. This already works through user messages, asking from user to confirm the active session. Now I need to do this check without interacting with the user. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted September 3, 2021 Share Posted September 3, 2021 \FMSoft\Framework\uniGUI\Demos\Desktop\Session List ? Quote Link to comment Share on other sites More sharing options...
irigsoft Posted September 3, 2021 Author Share Posted September 3, 2021 3 minutes ago, Sherzod said: \FMSoft\Framework\uniGUI\Demos\Desktop\Session List ? Thank You, is there a way to get from unisessionlist of speciffic session mainform.MyuniPanel.Caption ? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted September 3, 2021 Share Posted September 3, 2021 1 hour ago, irigsoft said: is there a way to get from unisessionlist of speciffic session mainform.MyuniPanel.Caption ? Can you please clarify? Quote Link to comment Share on other sites More sharing options...
irigsoft Posted September 3, 2021 Author Share Posted September 3, 2021 49 minutes ago, Sherzod said: Can you please clarify? OK, I have on MainForm uniPanel with userName, I want to use this uniPanel.Caption like mainmodule variable. So If i have uniPanel.Caption = ActiveUser, then I dont need mainmodule variable holding some data to check. Is it possible to get on uniServerModule for I := 0 to uniSessionList .Count do begin if uniSessionList [I]. MainForm.uniPanel.Caption <> 'Iron Man' then TuniSession (uniSessionList [I]).Terminate; Quote Link to comment Share on other sites More sharing options...
irigsoft Posted September 3, 2021 Author Share Posted September 3, 2021 @Sherzod, What happens when the browser is closed but uniSession is still active (is it possible to change the variable in unimainmodule from uniServerModule). Here is situation: uniMainModule public IsSessionActive : Boolean; end; on TUniMainForm.UniTimer1Timer (Interval = 1000 ms) UniMainModule.IsSessionActive := True; on TUniServerModule.UniThreadTimer1Timer (Interval = 5 * 60 * 1000 ms) Try SessionManager.Sessions.Lock; for I := SessionManager.Sessions.SessionList.Count - 1 downto 0 do begin Try U := SessionManager.Sessions.SessionList[I]; if (U.UniMainModule <> nil) then begin //Access custom MainModule variable if (U.UniMainModule as TUniMainModule).IsSessionActive <> True then begin U.Terminate(''); end else (U.UniMainModule as TUniMainModule).IsSessionActive := False; end; Except End; end; SessionManager.Sessions.Unlock; Except End; Quote Link to comment Share on other sites More sharing options...
irigsoft Posted September 4, 2021 Author Share Posted September 4, 2021 @Sherzod The example is useful, thanks. I'm sorry, but there's a problem. I want to automatically close sessions that are active in a closed browser (Mobile browser is closed). Here is my testcase. Project4.7z here is a plane: 1. I put a variable (IsSessionActive) in uniMainModule and I will update its value by pressing uniButton. I keep IsSessionActive = True, if is False then close Session. 2. In uniServerModule - uniThreatTimer the value for each active session will be checked. 3. In each session I have a uniTimer to display the active date / time. So, through uniServerModule every 30 seconds I will check the value of the variable and if it is not updated, then the session will be closed All work good if all browsers are active, but If i close some one this session is endless, can You tell me is this a bug or My error ? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted September 4, 2021 Share Posted September 4, 2021 Hello, Session will be terminated later. Quote Link to comment Share on other sites More sharing options...
irigsoft Posted September 4, 2021 Author Share Posted September 4, 2021 1 hour ago, Sherzod said: Hello, Session will be terminated later. when timeout expires ? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted September 4, 2021 Share Posted September 4, 2021 20 minutes ago, irigsoft said: when timeout expires ? No, after a few seconds. Quote Link to comment Share on other sites More sharing options...
irigsoft Posted September 4, 2021 Author Share Posted September 4, 2021 33 minutes ago, Sherzod said: No, after a few seconds. in testcase i never succeed to get expired this sessions where browser is closed - Prof. 1524 Quote Link to comment Share on other sites More sharing options...
Sherzod Posted September 4, 2021 Share Posted September 4, 2021 20 minutes ago, irigsoft said: in testcase i never succeed to get expired this sessions where browser is closed - Prof. 1524 Can you test "your case" with this demo? \FMSoft\Framework\uniGUI\Demos\Desktop\Session List Quote Link to comment Share on other sites More sharing options...
Sherzod Posted September 4, 2021 Share Posted September 4, 2021 1 minute ago, Sherzod said: Can you test "your case" with this demo? \FMSoft\Framework\uniGUI\Demos\Desktop\Session List 1. Close tab. 2. Delete session. Quote Link to comment Share on other sites More sharing options...
irigsoft Posted September 4, 2021 Author Share Posted September 4, 2021 27 minutes ago, Sherzod said: Can you test "your case" with this demo? \FMSoft\Framework\uniGUI\Demos\Desktop\Session List i use this exampĺe to create testcase. All settings of server and mainmodule are like real application explanation: I apply code from example to set isActiveSession=False to check if after 30 seconds user interactions will change value to True. Value is changed but session not expire. I use this code from example in uniServermodule.onThreatTimer procedure TMainForm.UniButton1Click(Sender: TObject); var S : TUniGUISessions; U : TUniGUISession; I : Integer; begin S := UniServerModule.SessionManager.Sessions; S.Lock; // Using Lock on session manager should be used with extreme care. // We should keep the "Lock duration" as short as we can. Session Manager stops working until lock is released. // Excessive use of lock/unlock or keeping the lock active for a long period will make uniGUI server slow/unresponsive. try SetLength(ASessionList, S.SessionList.Count); // Here we do a fast copy of list to another array for later use. for I := 0 to S.SessionList.Count - 1 do begin U := S.SessionList[I]; ASessionList[I].ASessionId := U.SessionId; ASessionList[I].AIP := U.RemoteIP; ASessionList[I].ALastTime := U.LastTimeStamp; if U.UniMainModule <> nil then // Check mainModule availability. Some sessions may not have a MainModule instance ASessionList[I].AMyVar := (U.UniMainModule as TUniMainModule).FMyStringVar; // Access custom MainModule props end; finally S.Unlock; // ... and finally don't forget to release lock! end; end; Quote Link to comment Share on other sites More sharing options...
irigsoft Posted September 5, 2021 Author Share Posted September 5, 2021 @Sherzod, I'm sorry, but can you tell me which code to use in the example. I'm trying it and I'm not successful in closing the session automatically. If I use a push of a button, everything is fine, but in the uniThreadTimer events of ServerModule not Don't forget, I have uniTimer for Chain Mode in MainForm. Quote Link to comment Share on other sites More sharing options...
Abaksoft Posted September 5, 2021 Share Posted September 5, 2021 18 hours ago, irigsoft said: I use this code from example in uniServermodule.onThreatTimer if U.UniMainModule <> nil then // Check mainModule availability. Some sessions may not have a MainModule instance ASessionList[I].AMyVar := (U.UniMainModule as TUniMainModule).FMyStringVar; // Access custom MainModule props end; finally S.Unlock; // ... and finally don't forget to release lock! end; end; 1. ServerModule.onThreatTimer do'nt like UniMainModule (AV exception) 2. Try S.Release instead of Unlock ??? Quote Link to comment Share on other sites More sharing options...
irigsoft Posted September 5, 2021 Author Share Posted September 5, 2021 38 minutes ago, Abaksoft said: 1. ServerModule.onThreatTimer do'nt like UniMainModule (AV exception) 2. Try S.Release instead of Unlock ??? Thak You, did You try my testcase? I can't understand why session not closing after browser is closed. Quote Link to comment Share on other sites More sharing options...
irigsoft Posted September 5, 2021 Author Share Posted September 5, 2021 thanks to all. My testcase work correct after change uniThreadTimer event : try //U.LockSession; U.Terminate; //U.ReleaseSession; finally //U.UnBusy; end; So, now i have a way to close session without activities even after close browser. I need that to control unused sessions with long timeout. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.