Serviceworker push event not called when web app is running on server - push-notification

I have asp.net web application sending the web push notifications. Notifications should be received in my listener registered in service worker as self.addEventListener('push', function (event) {...}.
It works when I run the application at local host. But when I run application from the server (azure) at https domain I'm not getting any events in the listener. I can see in debugger the server sends the notification request and there is the same success response from fcm.googleapis.com like when I' running it from localhost, but notification never arrives to the browser. I have enabled notifications from my domain in the browser, I've tried desktop chrome, edge and also mobile chrome, nothing works. What can be wrong? What is the difference in notifications when application is running at localhost?
Notification was send from server, but breakpoint was not hit in browser's debugger in service worker's push handler and no notification was shown.
Update:
I've got notification on mobile phone my application was updated 1 or 2 days after my last touch to application. And next day I've started receiving notifications. But I'm still not getting them on desktop though.

Related

Firebase Notification is received at local but not received at server

Our application is .net core api backend and reactjs frontend and hosted in Azure.
We have implemented firebase CM for both applications.
Client sends token to api to receive notification and api sends notifications.
Once we test local it works as expected but same code/application is not working at server.
I have logged the response and response status 200 and succeed 1 and got a message_id
We are stuck at the moment!
What is missing? Any idea?

PWA, Firebase and Google login: Unable to process request

I'm trying to make a PWA app for android out of my existing Angular app, where I use Firebase authentication (Google login - Sign in with popup). Everything works fine on my web app, but when I try to sign in on PWA on android, I can't login with Google. (BTW, Sign-in with password and username works fine.) It stops working after clicking on e-mail address within Google Sign-In popup. Page is blank. If I copy URL into the "normal" web browser, page is blank with the following error: Unable to process request due to missing initial state. This may happen if browser sessionStorage is inaccessible or accidentally cleared. What does this mean? Since is my first PWA app, I left the settings of 'webmanifest' and service worker config file as they were when created with ng add #angular/pwa.

Can Azure Web App receive email SMTP, and send email (SendGrid)?

Presently I use VisualBasic .NET web app (with SendGrid for email) running on my Azure server VM. I receives SMTP email from public Internet directly to the VM ok. It send email using SendGrid addon ok.
Will this all work if I switch to Azure Web App (formerly Web Site)?
Should my web app code work as-is without modification, even the SendGrid calls?
Outgoing email using SendGrid will not be a problem at all. Using it on App Service is common and you probably don't need to change any code at all.
Inbound may require changes depending on what you're doing. Are you simply polling a mailbox somewhere else and then doing something with the messages? If so, you could convert that to a scheduled WebJob poll at a specific interval and act on incoming messages.
If you're running an SMTP server on your VM to receive mail, then that's something you cannot easily replicate on App Service.

SignalR: Reply to Web Forms client on same machine as web application originating request

I'm looking for a way to support the following process:
Button is clicked in web application running on machine named PC1234.
Call is made to server (either the web server or an API on another server, it doesn't matter) to Do Something.
The server sends a notification to a Windows Forms client installed on PC1234 that the action is complete.
I've got the easy part working using SignalR. I can call a method on the web server and then send a notification with SignalR to ALL clients that the method has completed. The problem is notifying ONLY the client on the originating machine.
My initial plan was to include some unique identifying attribute of the machine with the call to the server which could then be used to direct the SignalR notification back to just that machine, but that doesn't seem to be possible.
An alternative idea was to have the call to the server include a unique reference and also update a file locally (i.e. a Cookie) with that reference, then have the client app poll the Cookie for new references and filter all SignalR messages received for that unique reference. This would be a bit clunky even if it worked, which it doesn't really, not least because I want this to work cross-browser, and different browsers store cookies in different places.
Ultimately this is to support printing locally and silently from a web application. The user selects a document in the web application, hits a print button, the request is sent to the server which retrieves the document from the database, saves it to a network share and sends a notification to a client app on the machine from which the print request was generated. The client app then prints the document from the network share and deletes it.
I never found a way to do exactly what I described in my question, but I came up with an alternative which worked well enough.
In both my web application and my Windows Forms client, the user was logged in with the same Windows credentials. I was therefore able to have the server respond to the button click in the web application by broadcasting a SignalR message to all SignalR clients where the same user was logged in, using
Clients.User(userId).send(message)
See this article for more detailed examples and instructions.
In my Windows Forms client, I included code to track how many instances of the client were connected to the SignalR Hub with the same user credentials and code to handle the receipt of a SignalR message from the server when multiple client instances were connected with the same user details (in my case, this meant displaying a message saying something like "You've requested a print from the web application but you're logged in at multiple workstations. Do you want the document to print here?").

SignalR using websockets keeps the same User Identity when login/logout during active connection

I am running ASP.NET MVC 4.5 application on server2012 using SignalR with settings enabling websockets.
On the page there is Log In / Log Out button, and I have to maintain active connections on server.
When server used for transport serverSentEvents everything works fine and when user changed authentication I got callback to
$.connection.hub.error(function (error) {
// stop current signalR connection and start new one
createNewConnection();
});
but when I set up server for websockets, it stopped to call error function. I found in fora that common solution would be to ping server periodically and update cookies, but when I ping server using signalR - websockets, server does not recognize that user identity has changed.
Basically when I start connection with user logged already in and then click on log out, server will maintain websocket connection unchanged, with the same user identity:
Context.User.Identity.Name
will be the same after user logged out.
I know that user identity cannot change during active signalR connection, but I would need to check if cookies didn't change, as it can change from another opened tab or window.
So what you're seeing is 100% expected. With all transports EXCEPT WebSockets they all have intermittent communication.
Ex: SSE - There's 1 connection that's established and never broken to receive information and there's AJAX requests that are triggered whenever you attempt to send data from the client to the server, the AJAX requests being the intermittent requests.
Now, on each request to the server SignalR validates the user identity. Sooo for every client -> server send in SSE the user identity is validated. However, in WebSockets there's only ever 1 request active (to instantiate the connection) and sends and receives flow bidirectionally over the connection.
Therefore, since WebSockets only ever has 1 request it never knows about identity changes.
On the other hand, if you are using SignalR 2.0.0+ your connection will learn of an invalid user identity within a 5 minute time span (SignalR sends an ajax request every 5 mins to the server).
Hope this information helps!

Resources