Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

hub connection .client callback get added again everytime after stop and start the connetion #925

Closed
Xiaohongt opened this Issue · 1 comment

2 participants

@Xiaohongt
Collaborator

e.g. for below repro, myHub.client.foo2 is the callback for server.getMessage.
Click button to stop connection, then click button to start the connection, then click broadcast button, you can see myHub.client.foo2 get called 2 times, then click stop and start the connection again, you can see myHub.client.foo2 get called 3 times, it get added again everytime after stop and start the connetion.

     <script type="text/javascript">
        $(function () {
            "use strict";
            var myHub = $.connection.myHub;

            myHub.client.foo2 = function (value) {
                $("<li/>").html("called foo2: " + value).appendTo($("#messages"));
            };

            $.connection.hub.disconnected(function () {
                $("#stopStart").val("Start").prop("disabled", false);
            });

            var start = function () {
                $.connection.hub.start({ transport: activeTransport, jsonp: isJsonp })
                    .done(function () {
                        $("#stopStart").val("Stop").prop("disabled", false);
                    });
            };
            start();

            $("#broadcast").click(function () {
                myHub.server.getMessage($.connection.hub.id, window.JSON.stringify($("#msg").val() ));
            });


            $("#stopStart").click(function () {
                var $el = $(this);
                $el.prop("disabled", true);
                if ($el.val() === "Stop") {
                    $.connection.hub.stop();
                } else {
                    start();
                }
            });
        });
</script>








@NTaylorMullen NTaylorMullen was assigned
@NTaylorMullen NTaylorMullen referenced this issue from a commit
@NTaylorMullen NTaylorMullen Added logic to unsubscribe methods on connection "disconnect"
- What was happening is that once a connection was stopped and then
re-started it was re-registering all of the .client hub methods.  This
only occured when using /signalr/hubs because we try to handle all of
the subscriptions for devs.

#925
05a8d59
@NTaylorMullen NTaylorMullen referenced this issue from a commit
@NTaylorMullen NTaylorMullen Added Stop and Start functionality to Connection Status sample to tes…
…t the fix for #925

- We don't currently have integration tests for JavaScript so the next
best method for ensuring no regression was to modify the sample.
0abd75a
@NTaylorMullen NTaylorMullen referenced this issue from a commit
@NTaylorMullen NTaylorMullen Added Stop and Start functionality to Connection Status sample to tes…
…t the fix for #925

- We don't currently have integration tests for JavaScript so the next
best method for ensuring no regression was to modify the sample.
e8615f6
@Xiaohongt
Collaborator

verified

@Xiaohongt Xiaohongt closed this
@NTaylorMullen NTaylorMullen referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.