Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
I am currently working on a personal project with React Native. I am a beginner in web/mobile development. Let me describe my situation first. The requirement of the current project is:
When the user (Host) logs into the app, he will go to the QR code screen and show a QR code to his/her friends (Guests). They all are in a restaurant.
Each of his/her friends will log in to their own account on the same app, and scan the QR code from the mobile phone.
The guests will then select some menu items to order. Until that, the Host screen will show a screen about each guest's order status. It will show Not Ready until the guests select some items. Once any of the guests select his/her item, the host screen will show the updated status for that guest saying 'Ready' with their selected items and price. I am providing a wireframe for you to understand.
My question is, how can the Host and Guest communicate with each other in real-time? My initial thought is, once a guest will select his/her order, it will call an API endpoint to update the database. On the other side, the host will call another endpoint every couple of seconds to see if the database has been updated. If yes, then the host will update his screen accordingly. Is it the right approach? While doing some research, I came across something called socket.io for two-way communication. Is my case suitable to use this technology? I am just asking for some ideas/technologies/tools which I can use to implement the idea. Thanks in advance.
Asking the server for updates every x duration is referred to as Polling. Polling is less efficient because it runs to check for updates even when there necessarily aren't.
A better approach to this would be by using Websockets. Socket.io is a good JavaScript library to do that.
A gist on how Websockets will work for you
All your guests, after scanning the QR code can connect to the same channel (also called room) based on the ID in the QR Code.
Now whenever someone chooses their order, you can "emit" an event (say we name it "order") with that payload to the server and it can broadcast it to everyone in that channel.
// guest client
socket.emit("order", payload)
The host client can listen to this event and update the UI as necessary.
// host client
socket.on("order", payload => {
console.log(payload);
});
This way, you can avoid polling completely. You can explore this guide to see how they implemented a chat application to get a flavour of the approach.
You can also use Firebase Realtime Database instead of Socket.io. In this approach, your guest clients will be directly updating the database and your host client will be observing or listening to those changes and updating its UI as necessary. Here's a guide to building a chat app using Firebase Realtime Database, so you can get an idea of how to go about it.
Hope this helped. :)
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
The premise
The issue at hand is a multifaceted one. What is the course that's being followed in a real production environment, what's considered a better solution in terms of safety vs production cost, etc.
I'm currently developing a React web app utilizing Redux for storing the state tree of the app. At the same time, I'm creating a RESTful API with Spring Boot to serve as a back-end server to which the React app can rely for various operations. I'm storing the user data (be it authentication, metadata and application specific data) in Firestore accessible only by the Spring backend (for security reasons). When a user correctly logins in the React App, a GET request is dispatched to fetch their data from Firestore.
The dilemma
Now, when a user alters their data while logged in I'm faced with the following dilemma.
Either update the local state, in Redux in particular, and then dispatch a POST request to update the
data stored in Firestore,
Or, straight up dispatch the POST request from the get-go and then dispatch another GET request to fetch the updated state.
Pros and cons
The first approach seems to be the better in terms of user experience as the user would have immediate visual feedback that his action was completed (say he wanted to delete a post from a list of posts, the post is immediately removed). The local storage is responsible for the rendering of the app so no matter the wait for the POST request to complete, the user will be correctly up to date. Of course, this isn't all good as modifying local storage when the actual data in the database are not yet updated isn't at all safe or really synchronous.
The second approach, it introduces a possibly strenuous operation that might (or might not) take a long time to conclude. BUT the state will always be correct, or at least as long as the Firestore database has a non-corrupted representation.
So, with all that said, what is your opinion on a correct approach that would satisfy both user experience and safety. (Please keep in mind, the local storage is NEVER looked up as a basis of synchronization with the database. If the local storage gets tampered with or corrupted, the changes will never reach the database.)
When you're using a client-side Firestore SDK, the two approaches are actually implemented in the same way.
You'd call the API to update the document, which then immediately fires events for any local listeners you have, even before sending the update to the servers. When it gets a response from the server (which may be much later in case the device is offline), the client either updates the metadata of the local cache to reflect the status, or (if the write failed/was rejected) reverts the local data to the correct state.
In your UI you can either just show the data that is fired to the local events (which is what most apps do), or you can reflect the metadata too. The latter takes the form of two flags in the DocumentSnapshot.metadata. From there:
hasPendingWrites: True if the snapshot contains the result of local writes (e.g. set() or update() calls) that have not yet been committed to the backend
fromCache: True if the snapshot was created from cached data rather than guaranteed up-to-date server data.
Check the documentation link for full details.
This question already has an answer here:
How to make user presence mechanism using Firebase?
(1 answer)
Closed 2 years ago.
Before explaining my question I just want to tell you that I know there is a function exist to check if a user is logged-in or not using this function:
firebase.auth().onAuthStateChanged(function(user) { ... };
But my requirement is a bit different, I am working on realtime chat app and for that I am using react and firebase. In this app I want to show the status (user is available or not), just like Facebook do. So for that what comes in my mind is, if there is some way to get the list of logged-in users in my firebase db or if there is some way to check if the user is logged-in by using email then my purpose will be solved.
So please let me know if there are some method exists or guide me some way by which I can achieve this.
Thanks in advance.
Auth States depend on variety of factors, like if the user gets disconnected from the internet for a long time. He would essentially be 'logged in' to the app (firebase remembers login) but he won't be active.
The best way moving forward is to check the last active time + disconnection with database. Firebase has a detailed documentation on preference.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Can I set an alarm on Alexa or Google Home by sending a text message, through integration such as IFTTT?
From the ifttt website, the integration all seems to be driving actions through Alexa or Google Home, I am looking for ways to drive actions on Alexa or Assistant.
https://ifttt.com/amazon_alexa
https://ifttt.com/google_assistant
Notifications (which are announced by a "bing" sound and a glowing yellow ring, and you listen to by saying, "Alexa, what are my notifications") can be pushed to your Alexa device using a skill I created called Notify Me and a REST API.
Notify Me works great with IFTTT via its Webhooks service. First, of course, you have to enable the Notify Me skill; then launch the skill to get an access code (say, "Alexa, launch Notify Me" and the skill will email you the access code). Next, you fill out the IFTTT Webhooks service like this...
URL: https://api.notifymyecho.com/v1/NotifyMe
Method: POST
Content Type: application/json
Body: {"notification": "HOWDY", "accessCode":"ACCESS_CODE"}
...replacing HOWDY with the actual message you want to send (it does not have to be all uppercase, of course) and replacing ACCESS_CODE with the access code you previously received via email.
See www.notifymyecho.com for more info.
At Alexa I am sure you can't do it with the Alexa Skills Kit currently at Google Home I think you can't.
The simple Problem here is that both device react only on user voice for the normal developer.
At Alexa a Notification system is planned or already there but it seems that it can't be used by the normal developer, from Outside. So you can't send anything to the device. Only if the device request Something like after an Intent it can push this to notifications and even for that i am not sure.
What you can do is built your on Alexa | or maybe Google Assitant device with the Alexa Voice Service | maybe Google Assistant tools (dialogflow, action sdk etc.) but there you have to do all handshakes by yourself.
I know people have probably asked this question before, but i have an additional use case. I want to track some particular events on my website, like user clicked on a particular button, or something like user opened this webpage, and log this on my server. How can i do that?
Also I don't want to flood my server with the log requests so any optimization I should keep in mind?
I am working with AngularJS framework.
Thanks
I want to create an online quiz website using Silverlight.
When the registered users are logged in, they can view and answer the quiz once per page.
To proceed to the next question, they must push next button, and the new data downloaded from the server.
The previous questions are not cached. Thereby everytime the question is requested, the question will be reloaded from the server again.
My question is how to do my scenario above in silverlight?
Thank you in advance.
Now that your intent is clear, you want to prevent discovery of the content in your assembly. The answer is you can't really protect your assembly. In order to run it the client needs to fetch it, if it can be fetched then the would be hacker can get it, trying to limit caching isn't really a prevention.
However the solution is to not put senstive stuff in your assembly to start with. Place code server side to do the sensitive stuff and access that code via a service interface such as WCF or Web services or even plain old XML in XML out posting.
You could use IsolatedStorage to store some state related info (and you can even encrypt it before you save if you want - it's your storage, do what you want with it). Another way to store state information is to use cookies, here and here.
The "state" information that i refer to is the state and/or progress of your Silverlight app, i.e. you can track where the user got to in the questions, and avoid requesting questions they have already completed. Both of these types of storage can be deleted by the end user, if they know what they are doing. But you shouldn't let that worry you - if they want to cheat, then let them.
Create the silverlight app to request the questions via a Web Service. As long as you're using a proper web service and not faking it in some way. The browser is not going to cache the webservice response.