WebSocket callback function multiple invocations

334 views Asked by At

I'm trying to create small web application which uses WebSocket protocol to exchange the data

Here is my angular service

define(function () {

    return function (module) {
        return module.service("socketService", function($q, $timeout) {

            var service = {},
                listener = $q.defer(),
                socket = {
                    client: null,
                    stomp: null
                };

            service.RECONNECT_TIMEOUT = 30000;
            service.SOCKET_URL = "/service/booking";
            service.CHAT_TOPIC = "/service/booking/updates";
            service.CHAT_BROKER = "/service/booking";

            service.receive = function() {
                return listener.promise;
            };

            ...
            return service;
       });
   };
});

and also controller code

define(function () {
    return function (module) {
            socketService.receive().then(null, null, function(message) { 
                $scope.list.countDownTimer = 0;
                if(message.resourceId === parseInt($routeParams.resourceId)) {
                    $scope.list.bookings = [];
                }   
                ...     
            });

My problem is that promise.then() callback function is invoked many times and the amount of this invocations is not repeatable: it might be 2 times, 27 or even 110.

One more thing that I should add is that I think that is somehow dependent with amount of users who tests and clicks on the application

Could anyone help? Thank you in advance...

0

There are 0 answers