locked
Notification via signalr RRS feed

  • Question

  • User1338262655 posted

    Hello.
    How can I send notification from user A to user B if I don't know client B connectionId ? For Example i have a chat page between two users, first A-user send message to B, but user-B not located in chat-page. Of cause except A and B -users I have a lot of and I dont need to user-X or Y or X ect catched notivication from user-A to user-B.
    Thank you.

    Monday, April 15, 2019 2:21 PM

All replies

  • User283571144 posted

    Hi Alter,

    As far as I know, we couldn't send the notification through the Signalr if he doesn't have a connectionId.

    I suggest you consider using javascript Push ,notification to achieve this requirement.

    The Push API gives web applications the ability to receive messages pushed to them from a server, whether or not the web app is in the foreground, or even currently loaded, on a user agent. This lets developers deliver asynchronous notifications and updates to users that opt in, resulting in better engagement with timely new content.

    More details, you could refer to below article:

    https://medium.com/izettle-engineering/beginners-guide-to-web-push-notifications-using-service-workers-cb3474a17679 

    Best Regards,

    Brando

    Tuesday, April 16, 2019 9:45 AM
  • User1338262655 posted

    So, I need connectionId to send any notification to user via signalR or use `Push Api`? `But Push Api` do not supported in IE, Safari, iOS Safari and Opera mini. Maybe exist some other way? For example when user-A open a web site -> signalR write his own `connectionId` to DB and other users can easy send him some notification because his `connectionId` already exist in BD. I think when user disconnected itself, old connectionId-entry in DB cleared.

    Tuesday, April 16, 2019 4:07 PM
  • User765422875 posted

    <g class="gr_ gr_13 gr-alert gr_gramm gr_inline_cards gr_run_anim Punctuation only-ins replaceWithoutSep" id="13" data-gr-id="13">Yes</g> you need a connection id. You should read about SignalR connection lifetime events.

    https://docs.microsoft.com/en-us/aspnet/signalr/overview/guide-to-the-api/handling-connection-lifetime-events

    Wednesday, April 17, 2019 12:24 PM
  • User1338262655 posted

    ok, got it. I have a new idea, but I need one more advice. Can I via SignalR Hub-A call Hub-B method ? Because I can't connect to 2 or more hubs at one time, but different hubs contain different logic. I think, it will be not correct merge all logic to one Hub.

    Tuesday, April 23, 2019 3:18 PM
  • User765422875 posted

    You want to use Groups for this.

    See section "Groups in SignalR"

    https://docs.microsoft.com/en-us/aspnet/core/signalr/groups?view=aspnetcore-2.2

    Friday, April 26, 2019 1:29 PM