B4J Question [ABMaterial] Session variables in safari

PCastagnetti

Member
Licensed User
Longtime User
Last edited:

Harris

Expert
Licensed User
Longtime User
@mindful that's a good point!
So, how does one overcome multiple browser windows with/when open on different tabs?
Or should one worry? We would not want additional complexity over and above what you have to deal with at current (session storage per page, per window, per WTF).
 
Upvote 0

mindful

Active Member
Licensed User
You can create a global map and initialize it by calling the server's CreateThreadSafeMap method and then:
1. in websocket_connected sub from each page you check if it contains the session id as key, if it doesn't then you add it in the map as key (map key or values cannot be null) and if it contains the session id as key then you redirect (NavigateToPage) the user to a static html file that states you message (eg. this application is made to run only in one browsers tab - it works)

2. in websocket_disconnected you remove the session id from the thread safe map.

This is how I do it ...

Note: You mush use a thread safe map because it will be accessed and mobified by more than one thread ..
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
So I guess the real concern is the second tab will (potentially) create a new/different set of vars. If the first tab re-load this saved copy, nothing would match?

I am using my app with two tabs and everything seems fine at this point (2.01).
I would like users to be able to us 2 or more tabs as well. Tab 1 shows grid results from one section of app. Tab 2 shows a graph from 1 particular line of detail from tab 1 grid.

Perhaps we need to ID the page (tab) and save/restore those session vars from a thread safe map...???

golly gee willikers...
 
Upvote 0

mindful

Active Member
Licensed User
you could keep a "page id" saved in the browser local storage as that is unique for each tab and also save in session using that page id as attribute.. and sync them when the connection is available again ... but i think this can be done by AB ...

The only downside of this is that on Chrome if you use Duplicate Tab function it will use the same local storage ... bummer

I added the one tab per browser because my project needed this "rule"...
 
Upvote 0

mindful

Active Member
Licensed User
In the past I was using VisualWebGUI ... it's like abmaterial for VisualStudio ... but they closed up shop ... They had a property that added a unique query string at the location for each window/tab opened and when you saved cookie/session cookies that value was referenced ...

This is just an ideea maybe AB could do something like this too ...
 
Last edited:
Upvote 0

Harris

Expert
Licensed User
Longtime User
I am sure he is thinking about and will come up with some solution - if deemed important.
The easiest would like forget about saving and restoring - just hit the refresh button...

I am trying to demonstrate this - save tab 1 - restore tab 2 to see what happens. Unplug the NIC cable to drop internet? Hard to do from the IDE I suppose.
 
Upvote 0

mindful

Active Member
Licensed User
Take this scenario:

page A has a variable x with value 0

Tab 1 is on page A and after it runs a method that variable value is 1
Tab 2 is also on page A and after it runs a method that variable value is 2

Now you internet connection drops .. and ABMaterial will save those values in the session under the attribute x .. so the page A from tab 1 will save the value 1 and page A from tab 2 will overwrite that value so it becomes 2...

When the connection restores it will reload x as 2 on both tabs ..
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
Yes, that's what I was figuring.

I have maps and lists that could be affected - particularly when I use the same names in different pages - containing different data.
 
Upvote 0

mindful

Active Member
Licensed User
This is just a raw ideea ... if using query string in the address is not good (i personnally do not like them especially for webapps) then we can use the browsers window.name property .. so we setup a page_id with a uuid ... and in the websocket_conect we set the windows.name = page_id ... maybe AB can use this and reference the page_id when he saves data into session ...
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
Seems to work mith a minor change instead of using ABMPage as session variable. Now it is saved per page, per tab.

B4X:
Dim myUUID As String = ABM.getUUID(Name,ws) ' NEW 2.02
If session.HasAttribute(myUUID) = False Or session.HasAttribute("ABMNewSession") = True Then ' CHANGED 2.02
     Log("saving session")
     ' IMPORTANT!
     session.RemoveAttribute("ABMNewSession")
     ' IMPORTANT: Redim to reinit the page object
     Dim page As ABMPage
     ' reload the BuildPage
     BuildPage     
     ' connect our page with the websocket   
     page.SetWebSocket(ws)
     ' Prepare the page
     page.Prepare
     ' save at least page
     session.SetAttribute(myUUID, page)  ' CHANGED 2.02   
     ' And all other variables you need for your program
     page.SaveSessionVariables(Me, session)
Else
     ' restore the page
     Log("Loading session")
     ' load at least the page
     page = session.GetAttribute(myUUID)  ' CHANGED 2.02   
     ' and load all your own variables previously saved
     page.RestoreSessionVariables(Me, session, myUUID) ' CHANGED 2.02
     ' connect our page with the websocket   
     page.SetWebSocket(ws)     
     ' refresh the page
     page.Refresh
     ' because we use ShowLoaderType=ABM.LOADER_TYPE_MANUAL
     page.FinishedLoading
End If   
Log(myUUID)

I'll send the 'mini testing team' a mail with a final (hopefully) test version. (I include you too @mindful)
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
Wow!

2.02 is very fast page loading! Rockets are jealous...
Logo fixed (with or without sidebar)!
Template and Feedback are up to 2.02 standard!

I do have many : Waiting for value (11 ms) in release mode in IDE logs ( normal ?) .

the uuid logged:

---Employees uuid: Employees27633040-f0e1-466c-8342-9dd72944d263
---AboutPage uuid: AboutPage27633040-f0e1-466c-8342-9dd72944d263
---ProdPage uuid: ProdPage27633040-f0e1-466c-8342-9dd72944d263
---HomePage uuid: HomePage27633040-f0e1-466c-8342-9dd72944d263

My WebSocket_Connected sub... same just includes page name in logs so I know which page did what / when...

B4X:
Private Sub WebSocket_Connected(WebSocket1 As WebSocket)
    Log("  ----"&Name&" view ws Connected")
    ws = WebSocket1  
    Dim session As HttpSession = ws.UpgradeRequest.GetSession ' NEW 2.01
    If ABMShared.NeedsAuthorization Then
        If session.GetAttribute2("IsAuthorized", "") = "" Then
            ABMShared.NavigateToPage(ws, "../")
            Return
        End If
    End If
    Dim myUUID As String = ABM.getUUID(Name,ws) ' NEW 2.02  
    If (session.HasAttribute(myUUID) = False) Or (session.HasAttribute("ABMNewSession") = True) Then ' NEW 2.01 (*1*)
        Log("   saving "&Name&" view session")
        ' IMPORTANT!
        session.RemoveAttribute("ABMNewSession")
        ' IMPORTANT: Redim to reinit the page object
        Dim page As ABMPage
        ' reload the BuildPage
        BuildPage
        ' connect our page with the websocket  
        page.SetWebSocket(ws)
        ' Prepare the page
        page.Prepare
        ' save at least page
        session.SetAttribute(myUUID , page)      
        ' And all other variables you need for your program
        InitPublicVars
        page.SaveSessionVariables(Me, session)
   '     page.Prepare
    Else                                                                                                      ' (*2*)
        ' restore the page
        Log("Loading "&Name&"  session")
        ' load at least the page
        page = session.GetAttribute(myUUID)      
        ' and load all your own variables previously saved
        page.RestoreSessionVariables(Me, session , myUUID)
        ' connect our page with the websocket  
        page.SetWebSocket(ws)      
        ' refresh the page
        page.Refresh
        ' because we use ShowLoaderType=ABM.LOADER_TYPE_MANUAL
        page.FinishedLoading
    End If
    Log("   ---"&Name&"  uuid: "&myUUID)
End Sub


Two words: SHIP IT! (as project managers are always shouting - regardless the state of stability).
( aaahhh... perhaps wait for other testers to respond.... )

I will upload copy to my server and try it out over the net... and respond.
 
Last edited:
Upvote 0

Harris

Expert
Licensed User
Longtime User
Just as fast on remote server.
Looks, works great. Thanks again AB. Your skills and understanding of this topic are quite amazing.
More amazing is - you do it for our (community) benefit. I am sure you have other (more lucrative) issues to with.

Quite frankly, I would be lost without this... Swimming in the same steamy stew with all else (want to be's - novice) - trying to figure out web and make it work for ourselves.
If ABM was outside of B4X, I never would have found or considered it. How lucky and fortunate I am.

Just have to say as an aside; I am really impressed with Google Charts API. Fast, simple to integrate and complete. Wasted many hours coming to this conclusion... but don't we all at times?

Thanks
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
This is great news! Excellent team effort (yes, I consider testing equally important). I have now two confirmed replies from the mini beta team. Today I will make the changes to the demo app and hope in the meantime to receive a third/forth confirmation. So ETA for 2.03 (I'll move the version up one number so no confusion can happen) is tomorrow.

Pfew. This has been the toughest update so far. I apologize for the struggle some of you have had to go through. You are my donators, but still I use you as my guinea pigs . However, I think this will benifit the masses when 2.x hits the 'free' shelves in the future because then, it isn't managable any more. The multiple browser tab system opens ABMaterial up to more application types and I consider this a great new feature I did not deem possible a couple of weeks ago.

I've learned that putting those 'mini' teams inbetween versions was good for the framework. It was easier/faster to communicate and fun to work with people without any panic attacks when something stopped working (well, in fairness, maybe I did myself a couple of times ). So, Thanks team! I wonder what 2.50 will have in store...
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…