bitford icon indicating copy to clipboard operation
bitford copied to clipboard

Improvement proposal : use DeviceStorage API as an alternative to FileSystem API

Open mossroy opened this issue 12 years ago • 6 comments

It's a request I had made for https://github.com/kzahel/jstorrent , but you already know it has disappeared.

The FileSystem API is only available on Chrome. But Mozilla implemented the DeviceStorage API that should let you do the same things. You get File objects, on which you can read/write some slices. See https://developer.mozilla.org/en-US/docs/Web/API/DeviceStorage and https://wiki.mozilla.org/WebAPI/FileHandleAPI#Atomic_increment_of_a_counter_somewhere_in_the_file

This DeviceStorage API is currently implemented on Firefox OS (you can test it on the Firefox OS Simulator : https://addons.mozilla.org/en-US/firefox/addon/firefox-os-simulator/ ), and is planned to be available on Firefox Android and desktop. See https://wiki.mozilla.org/index.php?title=WebAPI

It would make your app available on some more devices. And it also might let you win a Firefox OS phone : https://hacks.mozilla.org/2013/09/calling-all-app-ports/ ;-)

NB : it would also be very useful for an application I made, for which the user needs to download big files with bittorrent. For now it's not possible to download them from the device itself. See https://github.com/mossroy/evopedia-html5/issues/19

mossroy avatar Oct 02 '13 20:10 mossroy

Porting to Firefox OS is an important objective. I have already joined the Phones for App Ports programme, expecting the Keon to arrive soon. I'd still appreciate any help. :)

It should be noted that TCP server and UDP sockets are scheduled to arrive in Firefox OS 1.2! There's not much point in P2P apps if you cannot open TCP server sockets.

One area where you could especially help is to implement an interface to let other apps & websites communicate with Bitford.

Anyway, thanks for telling me about DeviceStorage. However, I dropped Chrome's FileSystem API in favour of IndexedDB because the former does not support sparse files and seemed to have issues with concurrency. After that, new buffer logics have lowered pressure on the storage backend. So I'm confident to try that once Bitford runs on Firefox OS with IndexedDB.

astro avatar Oct 02 '13 22:10 astro

That's really cool!

Regarding communication between apps, there's at least the Web Activities. See https://hacks.mozilla.org/2013/01/introducing-web-activities/ The application could call an activity, passing the bittorrent hash/servers/etc This activity would be implemented by bitford, that would open up and download the file(s) The calling application would wait for the onsuccess event, where it would find either the file content itself, or its location. Maybe there are better ways : it's the first idea that came to my mind

Regarding IndexedDB, that means that the downloaded file itself is stored in it, as a big blob? Does it still work properly with files of several GB? I thought an application or website could not access the IndexedDB of another application/website. But maybe I did not understand properly...

In any case, my congratulations for being accepted in the Phones for App Ports program! I hope you'll like your Keon

mossroy avatar Oct 03 '13 11:10 mossroy

Sounds like that could work with Web Activities!

File size is not an issue, because the data is not stored in one large chunk. For streaming, Bitford serves the data as an HTTP resource over localhost.

I fear the Keon will be quite low-end...

astro avatar Oct 05 '13 22:10 astro

I've never implemented Web Activities myself, but it looks like it can be (easily?) feasible, yes.

Regarding the file storage, if I understood correctly, the files are not readable on the filesystem by another application (if IndexedDB is used). It is split in chunks stored in the indexedDB tables. So, if another application needs to read these files on the filesystem, DeviceStorage or FileSystem API are needed , right? Another way would be to read the file through the localhost HTTP interface you were talking about. It might be feasible, but looks a bit more complicated.

Regarding the Keon, it has a single core 1.2 GHz ARM processor and 512MB of RAM. I find the interface really reactive and I do not feel to use a low-cost device. There's only the screen that I find a bit "cheap" because of a low color-depth that makes the images look not-so-good. But it's a good developer phone, for sure. In any case, you'll soon make your own opinion... ;-)

mossroy avatar Oct 06 '13 18:10 mossroy

Hi! Did you receive your Keon? Version 1.1 of FxOS hash been recently deployed on this device, which improved a lot of things. What do you think of Firefox os, and of this device?

mossroy avatar Nov 24 '13 21:11 mossroy

I've done some experiments with TCP client sockets but will wait until FxOS 1.2 for UDP and TCP server sockets. There's some shim code in my sawrocket repository.

In general the capabilities of the APIs are a bit disappointing. Examples: customize controls in notifications, get the number of visible GPS satellites, ...

astro avatar Nov 28 '13 11:11 astro