davinkevin / AngularStompDK

Angular service to communicate to Stomp-Websocket
http://davinkevin.github.io/AngularStompDK/
Apache License 2.0
36 stars 12 forks source link

Re-connect doesn't work when using SockJS #10

Closed michael-wirth closed 8 years ago

michael-wirth commented 9 years ago

Disconnect and Re-connect using SockJS doesn't work. It seems to re-open a SockJS connection it is required to create a new SockJS object. As this object is created once in the constructor it will fail.

If the SockJS object is already closed a new instance should be created.

    angular.module('app', [ 'AngularStompDK' ])
    .config(function(ngstompProvider) {
        ngstompProvider.url('/ws').class(SockJS).debug(true);
    })
    .controller(
            'MainCtrl',
            function($scope, ngstomp) {     
                    ngstomp.subscribe("/topic/1", function(){}, $scope);        
                    ngstomp.disconnect();
                    ngstomp.connect();
            }
    );

Log:

Opening Web Socket... angular.js:12416 Web Socket Opened... angular.js:12416 >>> CONNECT login:undefined passcode:undefined host:undefined accept-version:1.1,1.0 heart-beat:10000,10000

<<< CONNECTED version:1.1 heart-beat:0,0

connected to server undefined angular.js:12416 >>> SUBSCRIBE id:sub-0 destination:/topic/display/8483

DISCONNECT

Opening Web Socket...

davinkevin commented 9 years ago

Because of the abstraction of stomp, I don't think checking the state of SockJs is à good idea... It could be better to reset the stompClient on disconnect() or at the beggining of connect().

What do you think of this solution ? II will try to do the modification this weekend, but if you want to do a PR, you're welcome

davinkevin commented 8 years ago

Fix in https://github.com/davinkevin/AngularStompDK/commit/f4b29473778055459ad715fcdf6c8351fc2d5b1c --> v0.3.1

Tell me if it's ok for you (if I forget something maybe...)

michael-wirth commented 8 years ago

Thanks, the fix works fine!!

As an improvement: The subscribe() function should do an implicit connect() if the connection was closed or throw an error 'connection closed' to indicate the subscription failed.