Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently December 22nd, 2024, 7:27 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 19 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: Android Publishing
PostPosted: April 15th, 2019, 6:26 pm 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
I've never seen or managed to get appcache working and now that it's depreciated, it's recommended to avoid it for new projects.

The serviceworkers for PWAs looks really exciting. The idea of a proxy between the browser and server has some brilliant implications including caching.

I've got the basics working with SA, but I imagine as all the code is external except initiating the worker - which could go in the publish > settings > header - that this should also work with Opus.

</mack>

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject: Re: Android Publishing
PostPosted: April 15th, 2019, 7:01 pm 
Offline
Godlike
Godlike

Joined: November 11th, 2004, 1:18 pm
Posts: 1213
Location: New York
Opus: Opus Pro 9.75
OS: Windows 10 Pro 64 bit
System: Core i7, 16G RAM, Nvidia 640GT (desktop), plus Windows 10 and Android tablets
WPA's look like a useful way to extend Opus HTML5 pubs. Would like to try adding the necessary code to the headers, then users would be able to download/play the breath exercise in the HTML5 pub, avoid the Android sound play/sync problems.

Here's an interesting YouTube on WPA's from Microsoft.
https://www.youtube.com/watch?v=VNpoqUNMrh8

Wrote you a PM elsewhere (SA).

_________________
Stephen


For this message Stephen has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Android Publishing
PostPosted: April 16th, 2019, 8:39 am 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
Cheers Stephen,

At the moment, I've taken three very wobbly steps into the serviceworkers API necessary for cached PWAs.

See here: https://sandbox.interaktiv.co.uk/opus-pwa

1. The serviceworker is successfully registered - can be seen in the console tab of Chrome Developer Tools using the following code in the header.

Code:
<script>
if ("serviceWorker" in navigator) {
navigator.serviceWorker.register("serviceworker.js")
.then(function(registration) {
console.log("Service Worker registered with scope:", registration.scope);
}).catch(function(err) {
console.log("Service worker registration failed:", err);
});
}
</script>


2. Initially this step simply checked that the fetch process for any URL was successfully intercepted by the serviceworker. But once it was clear that it was working okay, I switch to caching resources using the following code and confirmed by reviewing the appropriate cache storage (ims-cache) in the Application Tab of the Developer Tools in Chrome:

Code:
var CACHED_URLS = [
    "index.htm",
    "Opus.js",
    "9-3.jpg",
    "42468.jpg",
    "apples3.jpg",
    "NoHTML5FallBack.jpg"
];

self.addEventListener("install", function (event) {
    event.waitUntil(
        caches.open("ims-cache").then(function (cache) {
            return cache.addAll(CACHED_URLS);
        })
    );
});


This is a slightly more advanced version of my initial code that simply cached a single URL.

3. The last step was to retrieve the cached URLs if offline. Again this is a slightly more advanced version that tries to return all the URLs from the cache rather than a single named URL. It's also the least understood and underdeveloped step at the moment. If working, you should be able to reload the PWA when the network is unavailable. This can be triggered using the offline mode in the Network Tab of the Development Tools in Chrome. Additionally, you should monitor this tab to check what is initiating the URL call and if the resource is retrieved from cache.

Code:
self.addEventListener("fetch", function (event) {
    event.respondWith(
        fetch(event.request).catch(function () {
            return caches.match(event.request).then(function (response) {
                if (response) {
                    return response;
                } else if (event.request.headers.get("accept").includes("text/html")) {
                    return caches.match("index.htm");
                }
            });
        })
    );
});


Lastly some other points:

a. I'm not supporting this in Opus or promising that it will work. It seemed a little hit and miss when tested.

b. This will only work under localhost or a HTTPS site.

c. Steps 2 & 3 belong in an external JS file named in the code at step one - serviceworker.js.

d. I've not included a source files because I think it's important to build each step and test and review what is happening in the Development Tools of your browser.

e. This is really cool and going to be the next big shift in the web. No more building web apps for different devices - Create an online application with PWA functionality and it will allow your users to continue using your application offline or over slow connections with no loss of user experience.

I found a more advanced tutorial for the first three steps, so I'm going to look at updating my SA example and see if it answers some of the questions I have.

</mack>

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject: Re: Android Publishing
PostPosted: April 16th, 2019, 12:50 pm 
Offline
Godlike
Godlike

Joined: November 11th, 2004, 1:18 pm
Posts: 1213
Location: New York
Opus: Opus Pro 9.75
OS: Windows 10 Pro 64 bit
System: Core i7, 16G RAM, Nvidia 640GT (desktop), plus Windows 10 and Android tablets
Wow! Impressive progress.

It will take a while for me to learn this.

Yes, definitely the future: create once in HTML5, deploy across devices, be able to run even if the internet connection is weak or lost.

_________________
Stephen


For this message Stephen has been thanked by : mackavi


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 19 posts ]  Go to page Previous  1, 2

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 12 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group