'Class module
Sub Class_Globals
Private ws As WebSocket 'ignore
' will hold our page information
Public page As ABMPage
' page theme
Private theme As ABMTheme
' to access the constants
Private ABM As ABMaterial 'ignore
' name of the page, must be the same as the class name (case sensitive!)
Public Name As String = "AboutPage"
' name of the app, same as in ABMApplication
' Public AppName As String = "template"
Private ABMPageId As String = ""
' your own variables
Private myToastId As Int
Private Count1 As Int
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
' build the local structure IMPORTANT!
BuildPage
If (Count1 = 0) Then Count1 = 100
Log("session initialized")
End Sub
Private Sub WebSocket_Connected (WebSocket1 As WebSocket)
'----------------------MODIFICATION-------------------------------
Log("Connected")
ws = WebSocket1
ABMPageId = ABM.GetPageID(page, Name,ws)
Dim session As HttpSession = ABM.GetSession(ws, ABMShared.SessionMaxInactiveIntervalSeconds)
If session.IsNew Then
Log("new session: " & session.Id)
session.Invalidate
ABMShared.NavigateToPage(ws, "", "./")
Return
End If
If ABMShared.NeedsAuthorization Then
If session.GetAttribute2("IsAuthorized", "") = "" Then
ABMShared.NavigateToPage(ws, ABMPageId, "../")
Return
End If
End If
ABM.UpdateFromCache(Me, ABMShared.CachedPages, ABMPageId, ws)
If page.ComesFromPageCache Then
' when we have a page that is cached it doesn't matter if it comes or not from a new connection we serve the cached version.
Log("Comes from cache")
page.Refresh
page.FinishedLoading
Else
If page.WebsocketReconnected Then
Log("Websocket reconnected")
' when we have a client that doesn't have the page in cache and it's websocket reconnected and also it's session is new - basically when the client had internet problems and it's session (and also cache) expired before he reconnected so the user has content in the browser but we don't have any on the server. So we need to reload the page.
' when a client that doesn't have the page in cache and it's websocket reconnected but it's session is not new - when the client had internet problems and when he reconnected it's session was valid but he had no cache for this page we need to reload the page as the user browser has content, reconnected but we have no content in cache
ABMShared.NavigateToPage (ws, ABMPageId, "./" & page.PageHTMLName)
Else
' when the client did not reconnected it doesn't matter if the session was new or not because this is the websockets first connection so no dynamic content in the browser ... we are going to serve the dynamic content...
Log("Websocket first connection")
page.Prepare
ConnectPage
End If
End If
Log(" -- This Page ID: "&ABMPageId)
Count1 = Count1 + 1
Log ("session# : " & session.Id & " count1 : " & Count1)
End Sub