Check Meteor "Call Queue" - meteor

I may have the terminology wrong however I am looking for ways to check the queue of meteor.call functions that are being retried due to a user being offline.
Some context: I have a system that allows users to book appointments in a diary. Some users with (very) poor wifi coverage are seeing appointments appear however subsequently disappear and it seems this is due to them being created when offline and then the page reloaded / disconnected before the page comes back online or before the local and remote data are synced. I have implemented an approach to inform the user that they are offline and as such should not change / reload the page however I would like to be able to check this queue so that once the connection is back, I know how long to wait until it has caught up.

Related

Firebase - Automatically sign out user onDisconnect

Since I have noticed that once a user signs in with email and password, on reopening the application the session will not have expired and there is no need for a new authentication, I wish to avoid this.
I want to automatically .signOut() a user when .onDisconnect is triggered. How can I achieve this? I have tried with the following code, but unsuccessfully:
firebase.auth().onDisconnect().signOut();
When you say "onDisconnect", I'm assuming that you mean Realtime Database onDisconnect triggers.
The first thing to know about onDisconnect is that it triggers when the socket connection between Realtime Database and the client app is closed. This could happen for any number of reasons, and it can happen at any time, even if the app seemingly has a good internet connection. So, be careful about what you're trying to do here.
Also, onDisconnect triggers can only affect data in the database directly, and nothing else. So, this limits what you can effectively accomplish. You can't perform any action in the client app in response on an onDisconnect.
Between these two facts, what you're trying to do isn't really possible, and, I don't think it's desirable. You could end up logging out the user just because their train went underground momentarily, or if they simply switched out of the application for some time. This would be massively inconvenient to the user.
If you want to automatically log out the user, I strongly suggesting finding some other way to do this, such as writing some code to remember how long it's been since the user used your app, and forcing the logout on the on the client app based on your preferred logic.
The onDisconnect() is related to the database connection, and has little to do with your authenticated user. As in: onDisconnect() may fire when your user is signed in, simply because the connection to the database drops temporarily.
But more importantly: onDisconnect handlers run server-side, once the server detects that the client has disappeared. When this is because if a dirty disconnect (e.g. the app crashes), there is no way for the client to detect this anymore.
The most likely approach you'll want is to simply sign the user out when they close the app.
Alternative you might want to attach a listener to .info/connected in your client. This is a client-side listener that fires when the client detects that it is connected or disconnected.

SignalR just for checking if user is online or not

I would like to ask, if it is a good idea to use SinglR just for knowing if the current user now online or not?
For example I have an small website with log in system, and some where on the side i would like to show the logged in members.
Is this a good idea to use signalr for that?
And if it the case should I then on each page start the connection with hub? (In this case when user navigates on the pages, will be the ReConnected method called on hub, or OnDisconnected and OnConnected)?
I'm just starting with signalr, so curious what ppl think.
You could use SignalR though there might be better methods to do this. So when a user logs in, logs out or becomes inactive - you would have some sort of message being sent from the client to the server that indicates the change in status. You can store that information in a temporary database and whenever a value in the database changes you can use SignalR to relay that information to all the connected clients.
Signalr will get reconnected when the user moves from one page to another page. Whenever a user logs into a website the user security details will be persisted in a cookie assuming you are using Cookiebase authentication. So till the user logs out or session timesout the cookie will be active. So there is no real need for Signalr here.
I have been investigating the same thing. From my research, I would say that you COULD do this, but I'm on the fence of whether it's the best way to go about it. I would expect a LOT of disconnecting, connecting and reconnecting. If you're persisting this data in a database, you should anticipate a lot of database traffic. if you're only on a single server though, you could just persist this in memory.
Something to also note is that the ConnectionId changes with each page refresh. At first, I thought that was dumb because I wanted the connection id to be consistent so i could keep a handle on a user with it. However, if you open a link in a new tab and then close one of them, you have to still keep the other connection in storage. If the id was the same you would remove it on disconnect even though the other tab was open, so your user would incorrectly be marked as offline.
However, the other issue that i'm thinking about is that if you're just browsing around the site in a single tab, you will disconnect for a split second between each page load. So you might run into connection consistency issues with that.
I'd say online presence with signalr is more common to be used for a chat room or game lobby. So I'd say this is possible, but whether it's a good solution -- i'm unsure.

Event of browser crash in asp.net

I want to execute a action on the event of browser crash in asp.net. I want to destroy the item added in the cart and revert back to the original state of the application and database if the browser crashes.
How can I do this?
Sadly, not possible, due to several factors.
1) the net is stateless, that is to say that the web server has no idea about the web browser, other than that it requested something. After it's serviced the request, it has no way of communicating with the browser.
2) the browser has the same issue. Once it's asked the server for the content and got it, that's it. If the user closes their browser, or lets their session time out, or if the browser crashes, the server doesn't know about it, and the browser doesn't tell it.
3) if the browser crashes, it's crashed, so it can't send any information anywhere, on account of the fact that it isn't working any more.
You can hook into the session_end event, which will fire when a user's session ends (a session ends when the user hasn't asked for anything for a certain period of time, 20 minutes is the default for this), however there's no way to tell WHY the session ended. the users browser may have crashed, they may have closed their browser, or they may have got bored and gone to another site.
Normally I wouldn't update the application state until after a user checks out, so the basket would be the only thing I'd need to delete. To do that I set a datetime column on my cart table, and update it every time the cart is updated. I then run a scheduled task on the database every day that deletes all baskets that are older than the amount of time I keep the baskets for.

SignalR with unreliable or paused & reconnected connections?

I'm considering updating an existing site to use SignalR. My site polls a third party service for data changes, does some magic on it, and clients poll it once every few minutes to refresh their view with any updates.
SignalR seems like a great way to eliminate the polling from the client, but I want to know how SignalR handles dropped & reconnected connections, especially with regards to mobile web apps which may have been suspended for some time. Will it automatically negotiate and queue up any updates that were missed in the meantime, or does the client need to resynch from scratch in these cases? I looked but couldn't find any docs on this so guidance would be appreciated.
All this is definitely possible since the client keeps track of the last message id it saw. If it happened to miss messages, it'll get those the next time it goes back to the server (asking for all messages since the last one it saw).
By default the server side of SignalR stores messages in memory (and it purges those every few seconds), but you can change it to persist to some persistent store (see IMessageStore) if you're thinking about clients going offline and catching up.
You could even persist messages yourself in your own app logic while SignalR stores stuff in memory. It really depends on the application.
We haven't added any special support for mobile clients, but you can persist the message id in whatever local storage you need to for your mobile client.
Those details aren't very specific but what you want to do is all possible with SignalR.
Read Understanding and Handling Connection Lifetime Events in SignalR, especially these sections:
How to continuously reconnect - required to recover from a disconnected state;
How to notify the user about disconnections - so your app can not only inform the user, but detect state changes (disconnected, reconnecting, reconnected) to refresh your app's state in other ways.
That document was written in 2014 and basically obsoletes many of the wrong or incomplete StackOverflow SignalR-related questions/answers from the 2011-2012 era.

Workflow 4 with ASPNET: concurrency and status checking

I'm trying to model a request submission/ approval /completion scenario. I'm using a flowchart workflow hosted as a service in a console app using WorkflowServiceHost. The workflow has a service reference to a WCF Service hosted in IIS this second service interacts with the application database. I have an aspnet front end with a service reference to the hosted workflow service and call its methods from a proxy client.
The workflow is using a persistence database that I have created using the scripts provided.
The scenario is that a request for a service is made by a user. The request must be approved once by a specific person (I'm using a pick with a delay in one branch to remind the person if no decision arrives, the other branch is receive decision). For some services the request must have a second approval which can be done by any one of a pool of approvers. Once approval is all finished the request goes to a different pool of people for completion.
I have it working but 3 questions:
In the aspnet home page I have a list of requests with links to pages to approve/complete as appropriate and call methods on the proxy after which they redirect back but because it's all asynchronous I am having to manually refresh the home page to see the changed list. Am I stuck with forcing the page to refresh itself every x seconds to get around this or is there a way to make it synchronous/check state of workflow/wait for a message back? It's not terribly interactive just hitting a button and not knowing whether the action succeeded or not.
Is there a way to stop someone approving a request just after someone else in the pool has approved it? At the moment nothing happens for the second person when they hit the button (which is good). In the workflow persistence database I can see that the blocking bookmark is the next activity along (presumably set by the person who got there first) so it looks as though the second receive just doesn't happen. I have concurrency checking code in the WCF data service but this never fires because there is no attempt to update the database. I would like to be able to warn the second person that another user got there first.
My homepage list in the web app is built by querying the application database, but is it possible to query the workflow to find the status of each item, passing the item's id (I'm using the id as the correlation handle)? Is it normal to do this or do people usually just query the application database?
I guess you could create an Ajax call that would check if any state change occurs and only refresh the page when that is the case.
If you send a WCF request for an operation that is no longer valid you should receive an error, unless you are using one way messaging because there is no message to send the error back. Mind you that due to a bug in WF4 the message could be a timeout after 60 seconds. There is no real way to avoid the problem because you are checking the workflow state as persisted and letting the user do an action based on that. Even when you query the state the workflow could have been resumes but not saved yet.
Either can work but I normally query the workflow instance store as that is the closest to the actual workflow state.

Resources