Signalr connection state between two android activities - connection

Now i'm try to developing android and multi client live chat application usin signalr. But i got a problem with signalr connection state. One thing is I don't know how to keep connection state between two android activities. Second is, I don't know how to keep signalr connection state in android. I tried to disconnect signalr connection state when android activity destroy, that's is ok but i got problem when user clean recent application from OS my android client is try to connect new connection oncreate. That's why i want to know how to keep Signalr connection state between android two activity and how to keep signalr connection state.
Another thing is should i use signalr for android instant messaging application. Because i want to create instant messaging application using signalr.
Thanks.

Related

How to schedule a task every certain time interval in Xamarin IOs?

I have an application in Xamarin Forms of messaging through signalR.
The problem is that when the application falls asleep, the connection with signalR is lost and messages stop reaching the client.
I am investigating how I can from time to time check if the status of the connection with signalR is active and if it is not, make a reconnection.
This is my lines of code that would do the process.
Device.BeginInvokeOnMainThread(async () =>
{
await MainViewModel.Instance.LobbyViewModel.ReConnectFromBackGround();
});
I've been through this documentation:
https://learn.microsoft.com/en-us/xamarin/ios/app-fundamentals/backgrounding/ios-backgrounding-techniques/ios-backgrounding-with-tasks
https://learn.microsoft.com/en-us/xamarin/ios/app-fundamentals/backgrounding/ios-backgrounding-techniques/
In the case of Android I have not had problems but in IOs I do not know what approach I should take and how to do it.

Websocket connections on iPhone get lost when safari is un-focused/hidden

I use a single websocket connection for my web app's notification and chat system. Everything works fine except that when using an iPhone, after closing/hiding Safari (which is actually just a hide/un-focus of the window I think) the connection gets lost and there will be no automatic re-connect after re-opening the Safari window. This might also occur on all other smartphones when hiding the browser window.
On desktop browsers this problem can't occur, as closing tab/window/browser will reload everything on the user's next visit ... But on mobile it seems to be more like:
Lose focus/hide window -> Cancel all client/server connections
Show window again -> Just show the rendered DOM and call Interval/Timeout functions
A solution I thought of is running an interval function every X minutes to check if a websocket connection exists otherwise create one ... This is ok, but I don't like this approach too much and was wondering if there is something I am doing wrong or missing on websockets as I used XHR Polling till now.
I use "Rails Action Cable" for my web app's websocket connections. As I use Vue.js for my frontend, so I wrote a custom package to use action cable's client side functionality instead of rail's full integration (https://www.npmjs.com/package/vue-action-cable) but I think the problem is more specific about websocket connections on mobile devices which un-focus the app window.
Experiencing this on an XHR polling app and a websocket app that uses Action Cable and React. The solution I did for the XHR polling was to utilize document.addEventListener('visibilitychange') and trigger on document.hidden to make a API call to the server whenever they come back to the tab. Essentially an "away" and "back" trigger. I plan to use that same trigger idea in React to then make sure the Action Cable connections are good. I can share that solution with you when it's done if you want.

Websockets service crashes after unexpected closing connections

I have an Asp.Net MVC backend and a mobile application (cordova).
I added a websockets service to backend using this library as starting point.
Websockets service crashes if client disconnects very often without normal closing connection (just close application). Usually three times enough for reproducing.
I added try-catch block to this function and it works fine for one unexpectedly closed connection.
After reproducing service responses "503 Service Unavailable" some times, after that works fine.
I added try-catch to all functions and use ILooger object in catch block for logging but I don't see errors in logs and on Azure portal.
Any ideas?
I moved a websockets code to a separate app service and it works fine. I use sevice bus for communication between a general service and the websockets service.

Mobilefirst Plaform handle client event

I'm using mobilefirst platform 8.0 to develop my application, i'm handling back-end side, i have a question:
a client got an event like some news update, and when client hit the
button it want another clients will be get notification about. How to
do it ?
can I use adapter to send events from a client to another clients ?
No - you can't send push notifications directly from one mobile device to another...
I might recommend that you build it this way:
Mobile user 1 calls an adapter function that updates or inserts a row to a database table in the backend;
A server process detects that a new row has been inserted (maybe with a database trigger or some polling component), and calls the MFP server-side API to send a push notification for a specific tag;
All the mobile clients that have subscribed to that tag will get the notification;
-Paul Horan-
IBM

Communication between asp.net app and a serviceworker, via signalR?

I'm new to serviceworkers and I wonder how could I connect my serviceworker to my asp.net application. My js client already is communicated with a service worker and it's able to show notifications.
However, I've seen that some webs (e.g facebook) send notifications even the browser's tab ins't opened (not inactive, not opened). I use signalR to communicate my app with the server. Would it be possible to communicate the serviceworker with the server? It would require to add signalR code to the serviceworker if I'm not wrong, but I don't think it's possible. I've seen that google has another way of communication, Google Cloud Communication
I can't use that, so any ideas of how could I solve this problem?
To make use of offline notifications (i.e., your browser is open but your page isn't), the browser itself needs to know about a messaging service that it can respond to, and which would let it know to wake up your service worker and give it a notification. These services are hard-coded into the browser. In Chrome's case, the service is GCM. And I believe Firefox is rolling out something of its own. You cannot wake up your service worker yourself from your server without going through one of these messaging services.
Remember that generally your service worker is asleep. The browser only wakes it up in response to specific events, and, if your pages are closed, there is no way to trigger a service worker event from your server, unless the browser provides a messaging service such as GCM.

Resources