SignlaR multi user live chat desynchronisation

I have a live chat in which multiple people would be connected simultaneously. All public messaging works fine, but sometimes private messaging to a specific id doesn’t work. I believe i narrowed it down to when people disconnected and reconnected that they connected to a different instance (perhaps IIS had recycled and started a new hub).
I thought I had fixed it, but I haven’t and now I’m here because I’m stuck. What I thought would fix it was changing the connection variable within the startChat() function to refresh it with the correct information.
This is a cut down version of the code, as I didnt thing the rest would be necesary.

Issue is that when connected to signalR recipients of a message directly to them doean’t come through, even though the chat Id it’s being sent to it correct. Possible hub/socket mismatch?

var chat = $.connection.chatHub;

$(document).ready(function () {
    // Start the chat connection.
    startChat();

    //restart chat if disconnected
    $.connection.hub.disconnected(function () {
        setTimeout(startChat(), 5000);
    });

    $.connection.hub.error(function (error) {
        $('#messagebar').html('Chat ' + error + '. If this message doesn\'t go away, refresh your page.');
    });

    chat.client.addToChat = function (response) {
        $('#chat-' + response.Type).prepend(response.Message);
    };
});

function startChat() {
    chat = $.connection.chatHub;
    $.connection.hub.start().done(function () {
        //get recent chat from db and insert to page.
        //also saves user's chat id to their user for lookup when private messaging
        $.ajax({
            method: 'POST',
            url: '/api/Chat/SetupChat/'
        });

        $('#messagebar').html('Connected to chat.');
    });
}

Any help appreciated, Thanks.

47 thoughts on “SignlaR multi user live chat desynchronisation”

  1. Pingback: sildenafil uses
  2. Pingback: viagra prank
  3. Pingback: cialis pills
  4. Pingback: lasix 20 mg price
  5. Pingback: xenical
  6. Pingback: priligy 30mg
  7. Pingback: bimatoprost
  8. Pingback: cialis drug
  9. Pingback: cialis 600 mg
  10. Pingback: sildenafil rx

Leave a Comment