Are websocket, playing audio in background, and storing files locally possible in KaiOS app?

205 Views Asked by At

I am planning to develop a chat and voice messaging app in KaiOS, but want to make sure whether these things are possible in KaiOS:

  • web sockets in background (can receive the data when app is not opened)
  • playing audio in background without user interaction
  • storing files locally
2

There are 2 best solutions below

0
On
  • Background WebSockets aren't supposed by any browser, or on KaiOS. You can use Web Push to receive push notifications in the background.
  • Background audio playback is supported
  • Files can be read and saved locally using the Device Storage API
0
On

Web Sockets : Web sockets can work only if the app is at foreground. You can use window.MozWebSocket or websock.js.

If you want to do any data exchange activity in background, then make use of push notification, serviceworker and indexed db/cache API.

Storing files : Yes you can read and write files

To read,

var sdcard = navigator.getDeviceStorage('sdcard');
var request = sdcard.get("fileName");
request.onsuccess = function () {
        var fileObject = this.result;
};
request.onerror = function () {
   console.warn("Unable to get the file: " + this.error);
};

To write,

    var sdcard = navigator.getDeviceStorage("sdcard");

    var request = sdcard.addNamed("file data", "test.txt");

    request.onsuccess = function () {
      var name = this.result;
      console.log('File "' + name + '" successfully wrote !!');

    };
   request.onerror = function () {
     console.warn('Unable to write the file: ' + this.error);
   }