ionic realtime database updates - angularjs

I'm developing a coffee ordering app using ionic and angularJS and I'm using a mysql database with a laravel backend.
Now i want to check whether a certain order has completed or not in real time. Instead of sending $http requests every second to check with the server is there a way to update the app only when the mysql database gets changed in ionic?
I was told pusher.js does the trick but I have no idea how to integrate it with ionic.
Thank you in advanvce

Using socket should be a best solution for real time updates without repetitive requests from front-end. You can use http://socket.io/ on front-end and on PHP backend as mentioned at http://php.net/manual/en/function.socket-create.php.

Related

Application that receives data in real time without refresh

I am developing a desktop program, a website and an application and they both communicate through the same database. I started researching about making these apps real-time, that I don't need to update to receive a new registration or a change to something. I discovered websockets and socket.io, saw some examples and read a lot about it, but then I saw that there are some databases that already do this and one of the most famous is firebase. What I would like to ask here is, using firebase can I make an application in real time? An application that when registering data to the database, all other connected applications receive this data in real time?
In google firebase, you can create listeners on the client-side to respond to any changes in the backend. Check out https://firebase.google.com/docs/firestore/query-data/listen.
This is great if you need to store data, but if you are purely looking to send information between clients and there is no need for any persistence, I would recommend using WebSockets.

How to use API as backend in ionic mobile app development?

I am having a web application built using JAVA spring which has API feature to read and write into database.
Now i have to develop an ionic mobile app for the same application. How to read and write data into database.
I know Firebase and other alternatives can do the job.
But i need my own API code(written for web app) to be used. Is there any way to achieve that?
I guess calling the respective API when the web application is live is achievable.
But how can i achieve that while developing(When the web app is under construction)
Well depending on how you set up the API this could become quite difficult.
You're saying/guessing that you can call the API when the webapplication is live. This makes me assume you've created a REST API? Or did you create a Spring MVC application?
If the webapplication is directly linked to your Spring application (f.e. going to localhost:8080/my-profile shows a page (not JSON) of your profile) then I'm not sure if you can achieve the above mentioned target.
If you get a JSON response, or are somehow able to retrieve it from the webpage, you can just simply call (in typescript:)
this.http.get('http://localhost:8080/my-profile').map(response => console.log(response.json() );
Else, you probably will have to create a basic REST API (check out Spring boot for a 5 minute setup) and provide it, either with hardcoded data or connect it with your database.

How to make Ionic app work with an API written in Laravel but still works offline

I would like to ask how to create an ionic app that talks to Laravel API but still works offline when there's no connection.
Let's say i have to write a quiz mobile app in Ionic and it requests for Laravel API to retrieve the questions as well as store the scores in db.
I'm just starting to learn Ionic and i'm really confused right now on how to approach this.
What confuses me most are:
Does the Ionic source live inside the Laravel source code w/c serves the API?
If i want the Ionic app to be installable, should the Laravel source code be included as well during the compilation process?
Thanks in advance for any help.
Your php or in general server side code is completely independent from your ionic application. If you want your app to work offline you should think about something like fetching a high number of information initially and work with this data without making any additional requests.
However your ionic app does only contain the frontend. You could implement some logic for local storage, but if you want to keep information hidden from the user (e.g. solutions) you have to put that logic on a dedicated server.
In the few details you provided, I can say the Laravel code does not live inside the ionic app. The ionic app is separate from the backend API by Laravel. You are possibly trying for a ReST based architecture where you communicate with your Laravel Server with an API. You need to keep those codes separate.
However without any internet, you won't be able to access those APIs, so you will just be able to show some static data, or you could serve from a DB and show later. For how to use the sqlite db you can look here
In your backend you can have an API like
http://example.com/api/v1/questions/1/
Which will fetch a question with options and if you want the app to have the answer for offline storage you may have that as well. When a user answers, you may check whether you have internet access and send answer and verify if you do, else you may save the answer in your DB and sync when you do have access. You can fetch multiple questions so that a user may answer multiple questions in case he/she will not have internet access.
Hope it helps. :)

FireBase and Php (Laravel)

I have a Laravel + mySQL app that use either ajax or Angular $http service and I want to integrate websockets into that mix.
So I thought of trying Firebase, which is great and easy to use, but am a bit confused about a couple of things. I am seeking for someone's help in clearing that confusion.
is it possible to change the app url name for firebase ?
So instead of something like https://vivid-torch-xxx.firebaseio.com can I change it to https://myawesomesite.firebaseio.com?
how the schema on Firebase should be structured ?
Or better yet how not to use it all and just use Firebase as websocket server instead of ajax ?
I essentially don't want to have 2 databases to manage the data.
there is a Firebase package for php/laravel, but I don't know why would I need it. Or what exactly is the benefit of using it if am already using a REST-ful backend with angular.
The schema will basically be how you want your JSON for your front-end will read it. Are you displaying notifications? Then investigate how that would be structured. Firebase will give you the power to push updates to the front-end which then will no longer have to pull data via the API on what the actual data is it needs to display the notification.

session time out with angularjs and asp. net web api

Im using mvc4 web api project. i have included angularjs.
as i have read an articles that session is not supported in we api as it is stateless.
basically we used to do coding with asp. net session. which is now not there. (it is there but i havent implemented yet).
if i dont plan to use session, how should i go ahead? currently i m storing user name in html local storage but it doesnt seem promising as it resides at client side.
how can i show msg of session time out after 10 mins?
should i go with client side js only?
ot there are some ways???
i dont know to handle such situation?
timerjs or something? what should i do?
IMO, storing client session in client side is a bad practice as it can be hack easily which result in a vulnerable website. I recommend to use OAUTH2 if you are developing web api. On the client side, you can use ng-idle to show the users if they are idle for a long time and log them out on timeout.
Hope this help

Resources