Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mossroy opened this issue Oct 2, 2013 · 6 comments

Comments

@mossroy
Copy link

mossroy commented Oct 2, 2013

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 kiwix/kiwix-js#19

@astro
Copy link
Owner

astro commented Oct 2, 2013

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.

@mossroy
Copy link
Author

mossroy commented Oct 3, 2013

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

@astro
Copy link
Owner

astro commented Oct 5, 2013

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...

@mossroy
Copy link
Author

mossroy commented Oct 6, 2013

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
Copy link
Author

mossroy commented Nov 24, 2013

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?

@astro
Copy link
Owner

astro commented Nov 28, 2013

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, ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants