B4J Question [ABMaterial] Auto-Update Connected Browsers

rwblinn

Well-Known Member
Licensed User
Longtime User
A cross check if below is the right appraoch to auto-update all connected browers to an ABMaterial application.
The solution is based on this thread. Have tested and is working fine.

Question: Is this also the right approach using ABMaterial?

Tested Example Code Snippets

Project.b4j
B4X:
Public ConnectedBrowsers As Map
...
ConnectedBrowsers = srvr.CreateThreadSafeMap
ProjectShared.Initialize
...

Code Class ProjectShared
Class to handle datacollection and trigger update connected browsers.
B4X:
...
Sub Process_Globals
...
   Public DataCollectionTimer As Timer
...
End Sub

Public Sub Initialize
...
   DataCollectionTimer.Initialize("DataCollectionTimer", 5000)
   DataCollectionTimer.Enabled = True
...
End Sub

Sub DataCollectionTimer_Tick
   For Each clt As ABMPageTest In Main.ConnectedBrowsers.Keys
     CallSubDelayed3(clt, "updatepage", Value,DateTime.Time(DateTime.Now))
   Next
End Sub

Module Class ABMPageTest
Update the browser page.
B4X:
Private Sub WebSocket_Connected (WebSocket1 As WebSocket)
  Main.ConnectedBrowsers.Put(Me, "")
  ...

Private Sub WebSocket_Disconnected
  Main.ConnectedBrowsers.Remove(Me)
  ...

Sub UpdatePage(Value As Double, TimeStamp As String)
   labelTestValue.Text = $"${Value} ${TimeStamp}"$
   page.Refresh
End Sub
...
 
Top