Jump to content

How to get window.open on variable when new session start


irigsoft

Recommended Posts

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");}');
 

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

@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;

Link to comment
Share on other sites

@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 ?

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

@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.

Link to comment
Share on other sites

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  ???

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...