I'm building an app with offline capability and I need a way to check quickly if I'm offline or not .
I'm currently using #SYS_WEB.online but it seem unreliable so I do a call to the server module and if it failed that means I'm offline.
It is working but it takes about 20 seconds so I want a better way of handling it.
Here's the code that I'm working on:
Evtroutine Handling(#SaveIcon.Click)
If (#COM_OWNER.Validate( Update #xContacts ))
* this don't appear to be working
If (#SYS_WEB.online *EQ True)
#COM_OWNER.Save
Else
#COM_OWNER.SaveOffline
Endif
Endif
Endroutine
Mthroutine Name(Save) Access(*PRIVATE)
Define_Com Class(#EX_DataServer.Save) Name(#Save)
#SYS_MSGQ.ClearAll
#ErrorText.Visible := False
#Save.ExecuteAsync( #Fields #STD_BLOB #STD_CODE )
Evtroutine Handling(#Save.Completed)
If (#STD_CODE = "OK")
#COM_OWNER.Close
Signal Event(ItemSaved) Action(#DF_EFLAG) Id(#xContactIdentification)
Else
#ErrorText.Caption := ""
For Each(#Message) In(#SYS_MSGQ.Messages)
#ErrorText.Caption += #Message.Text + (10).AsUnicodeString
Endfor
#ErrorText.Visible := True
#Details.VerticalScrollPos := 0
* #COM_OWNER.Close
Endif
Endroutine
Evtroutine Handling(#Save.Failed) Handled(#handled)
#COM_OWNER.SaveOffline
#handled := true
#COM_OWNER.Close
Endroutine
Endroutine
Thanks,
Eduardo
How to check if offline or online (quickly)
Re: How to check if offline or online (quickly)
Hi Eduardo
You can use the navigator information
https://developer.mozilla.org/en-US/doc ... ine/onLine
1. create a widget
2. add methode 3. add eventlistener (optional)
4. finalize Methode
5. Integrate Widget
6. Test widget in browser
Hope that helps
You can use the navigator information
https://developer.mozilla.org/en-US/doc ... ine/onLine
1. create a widget
2. add methode 3. add eventlistener (optional)
Code: Select all
function( PROTOTYPE, WIDGET )
{
window.addEventListener('offline', function(e) { console.log('offline'); });
window.addEventListener('online', function(e) { console.log('online'); });
...
return WIDGET.Completed;
Code: Select all
//
// isOnline - Check if Device has connection
//
// Return Type: Boolean
//
PROTOTYPE.isOnline = function()
{
return window.navigator.onLine;
}Code: Select all
Define_Com Class(#wMobileWebAppInfo) Name(#wMobileWebAppInfo) Scope(*APPLICATION)
Mthroutine Name(isOnline)
Define_Map For(*RESULT) Class(#PRIM_BOLN) Name(#O_Result Result)
#O_Result := #wMobileWebAppInfo.isOnline
Endroutine
Re: How to check if offline or online (quickly)
I was hoping there's a quick way to check if you can connect to the server or not but I guess the request timeout differs from browser to browser.
But this will be helpful to 'mimic' offline/online when testing. Thanks
But this will be helpful to 'mimic' offline/online when testing. Thanks
-
dannyoorburg
- Posts: 177
- Joined: Mon Jan 04, 2016 9:50 am
- Location: Australia
Re: How to check if offline or online (quickly)
Isn't that exactly what #sys_web.online does?
https://docs.lansa.com/15/en/lansa016/c ... online.htm
https://docs.lansa.com/15/en/lansa016/c ... online.htm
Re: How to check if offline or online (quickly)
Yes, it's probably the same as sys_web.online. Using the navigator.online is the most common way to check if a connection is etablished or not. The only difference is the eventlistener.