How to work with Camera API in Firefox OS - firefox-os

I want to work with camera api in firefox os simulator. Docs suggests that it is only available for certified apps. If i want to take picture using camera in my app, how can i proceed developing the app?? Thanks in advance

You have to use the Web Activities API to take pictures. Simply put, it's the equivalent of Android's Intents for the Open Web.
I'd write a lot about it, but there are good code examples out there, like this one, implementing just that. You have to a few stuff:
Create a Web Activity:
var recordActivity = new MozActivity({ name: "record" });
Set a onsuccess callback, and do whatever you want with the result on it:
recordActivity.onsuccess = function () { console.log(this); }
There are a few more details, and all of them are listed on this post on Hacks.

So some stuff changed in the past year. Web Activities are still the way to go for most apps, but we have two APIs that were previously not exposed.
From Firefox OS 1.4 you have access to getUserMedia so you can get a direct camera stream. From Firefox OS 2.0 you now have access to the mozCameras API that allows for stuff like camera switching and control of the flash.

Related

Audio in safari

Hello developers community,
Currently I have task to create walkie talkie app,
I am using React.js,socket.io(for real time communication) & express js.
I am not able to play audio continuously which arrives from socket listener.
specifically in IOS safari.
I can play audio with static url(base64 data url) but not with dynamic base64.
Is there any way to contionuosly pass & play the audio.
I am free to adopt any other framework or protocol also. just need some guidence for create this type of application.
I tried Audio() api and also set UX flow to get user activity in website so that browser allows Audio() to play.

Panasonic API for Firefox OS Apps

Thanks to MDN I successfully deployed a simple app on my Panasonic CXW754. So far so good. Now I'd like to have access to screen settings like brightness etc. Is there an API provided by Panasonic or can I do it with plain Firefox OS API somehow?
I already looked at https://github.com/mozilla-b2g/gaia/tree/master/tv_apps
But navigator.mozSettings is null and navigator.tv does not exist on my TV runtime :(
You should be able to change screen brightness using navigator.mozPower.screenBrightness from the PowerManager API. Only certified apps can access this API though.
I would use the SettingsManager API instead of using directly navigator.mozPower.screenBrightness.
The SettingsManager let you change almost any setting by firstly requesting and locking that setting. It can even let you add Observers:
https://developer.mozilla.org/en-US/docs/Web/API/SettingsManager
For example: https://github.com/shawnjohnjr/releases-mozilla-central/blob/8355c4efc146c9e58f7d11cdb5f567908b5754c0/toolkit/mozapps/update/test/marionette/update_smoketest_ota_same_version.js
But as pointed out by #kumar303, it is only for certified apps.

Store data in FirefoxOS

I'm trying to do some FirefoxOS apps, but I have not seen any easy way to store local data. I hear about IndexedDB, but it seems too complex. Is there any other alternative? If not, is there any easy tutorial about it?
I have considered to store and recove remote data (doing a croos domain request), but I'm having some issues with the permissions. Is there any tutorial about XHR for FirefoxOS?
Thanks.
The best IndexDB doc I can found is Using IndexDB in MDN.
And there are plenty of default Firefox OS apps (gaia) such as gallery, browser using IndexDB. You can see how it works in real life.
Or you can use the more lightweight window.localStorage API, which works like a dictionary.
localStorage.setItem(key, value);
localStorage.getItem(key);
EDIT: Note that localStorage is not recommend because its block the main thread. You should use gaia/shared/asyncStorage instead.
For XHR you can check Firefox-OS-Boilerplate-App for a working XHR demo
I recommend you using asyncStorage over localStorage, is an asynchronous version of localStorage, with the same api and the benefits of IndexedDB.
You can see the code and learn how to use it reading the comments of the file:
https://github.com/mozilla-b2g/gaia/blob/master/shared/js/async_storage.js
The podcasts reference app talks about both IndexedDB and SystemXHR, which is the privileged API for doing cross-domain requests:
https://marketplace.firefox.com/developers/docs/apps/podcasts
You can use DataStore in firefox Os by using data store you can also share that data with other apps and you can also give permission to other apps to write in data store or not.
you can follow this link.
https://developer.mozilla.org/en-US/docs/Archive/Firefox_OS/API/Data_Store_API/Using_the_Data_Store_API
Just for using data store your app need to certified.
navigator.getDataStores('mystore').then((store)=>{
store[0].getLength().then((ln)=> console.log(ln))
})

Method(s) used to pass data to and from WebKit based browser

I'm using WebKitGTK+ ( WebKit ) application that will be a very simple web browser running in a Linux environment as a separate executable that will need to exchange data between another application. The system is described in the following image:
Example scenario:
Event such as smart card insertion detected in Backend processing Application
smart card data is read and passed to the WebKitGTK+ GUI Application
User interacts with "web page" displayed in WebKitGTK+ Application
Data is passed from WebKitGTK+ Application back to the Backend processing Application
What are the common methods of passing data between the WebKitGTK+ Application and the Backend processing Application?
Does `WebKitGTK+ provide some hooks to do this sort of thing? Any help at all would be appreciated.
I know this is a old question, but will try to answer it to best of my abilities so that it can be useful to someone else.
Webkit is basically rendering a html page. You can connect to various signals that webkit provides and act on these signals. More details at http://webkitgtk.org/reference/webkitgtk/stable/webkitgtk-webkitwebview.html
For your back end application, if something interesting happens, you can update page either by navigating to a new url, new page contents or just by setting text of desired element. Webkit provides DOM api functions and all of these are possible.
It becomes interesting when getting data from webkit and sending it to your back end system. Again, this depends upon your specific design, but generally you can hook up signals such as navigation signals when user clicks on a button and get contents. Another alternative is to use alert handler and simply use javascript alert and process the alert data on backend side.
Shameless plug for example : https://github.com/nhrdl/notesMD. It uses a simple database backend, probably can be good use case as it sends data back and forth between database and webpage. Even manipulates the links so that desired actions take place.

Creating Spotify playlist with standalone web app

I just want to be able to create a playlist by sending / receiving http requests ( a standalone web app, not with Spotify Apps and the desktop client). I've dug around the docs and can't find a clear solution. Can someone point me in the right direction? Thanks in advance.
You can pass a list of songs—not a playlist—to the desktop player by adding the track ids to a link as below
Play
UPDATE
As of today there is an api for creating playlists: https://developer.spotify.com/web-api/create-playlist/
I just want to be able to create a playlist by sending / receiving
http requests
This isn't possible at the moment — Spotify doesn't have a web API for manipulating playlists. You may be able to hack a solution together using libSpotify, although using libSpotify in a server service this way is against the ToS.
You might want to look at https://github.com/liesen/spotify-api-server
It is limited to just one spotify account (the one you configure it with) but does allow playlist creation/manipulation via RESTish calls.

Resources