Check internet connection

I want to check if there’s an internet connection. I know it’s been answered on the forum before, but there was no conclusive answer, and I was hoping that Fuse has come up with a way to check that in the meantime?

The solution we usually suggest is to make a fetch request against your backend and see if it’s successful.

Other than that, you might go with a more sophisticated (Foreign code) approach and see if you can extend the fuse-device library to detect the connectivity state.

I had the same problem. This works fine.

<App>
	<JavaScript>

		var Observable = require("FuseJS/Observable");
		var noConnection = Observable();

		module.exports = {
			 noConnection: noConnection
		}

		fetch('http://example.com', {

		}).then(function(response) {

		}).then(function(responseObject) {

		}).catch(function(error) {
			console.log("No internet connection");
			noConnection.value = true;
		});
		
	</JavaScript>
	
	<WhileTrue Value="{noConnection}">
		<StackPanel Alignment="Center">
			<Text Value="No internet connection" />
		</StackPanel>
	</WhileTrue>
	
</App>