voryx/angular-wamp

Error: [$rootScope:inprog] when subscribing to two Topics

Closed this issue · 2 comments

Hello,

At the moment I'm trying to connect to two topics on the same WAMP-Server but get this error on start:

Error: [$rootScope:inprog] http://errors.angularjs.org/1.5.5/$rootScope/inprog?p0=%24digest[...]

The shortest code with which I managed to reproduce the error would be:

var app = angular.module("app", ['vxWamp']);
app.config(function ($wampProvider) {
        $wampProvider.init({
            //url: 'ws://127.0.0.1:8080/ws',
            url: 'ws://192.168.0.101:8080/ws',
            realm: 'realm1'
            //Any other AutobahnJS options
        });
    })
    .run(function($wamp){
        $wamp.open();
    });

app.controller('ctrl', function ($scope, $wamp) {   

   function onFirstData(args) {
       console.log('called');     
   }

   function onSecondData(args) {
       console.log('called2');

   }

   $wamp.subscribe('topic1', onFirstData);
   $wamp.subscribe('topic2', onSecondData);
});

I managed to avoid the issue by just subscribing to the second topic a second after the first (with a JS timeout), but wnated to report this nonetheless.

Thanks for finding this issue. I tried to reproduce it with the code you provide, but wasn't able to. Do those topics publish immediately?

Can you try changing https://github.com/voryx/angular-wamp/blob/master/release/angular-wamp.js#L238 to $rootScope.$applyAsync(); and see if that fixes it?

Yes, I publish to these two topics constantly (2s intervall).

Your solution worked perfectly, even if I change the publish intervall to 100ms it now works without errors, while before it throw hundreds of them before crashing.

Thanks for the quick answer.