wilk / ng-websocket

AngularJS HTML5 WebSocket powerful library
MIT License
267 stars 78 forks source link

Dublicate response on new then get #7

Open baki250 opened 10 years ago

baki250 commented 10 years ago

When initially creating .$new to open the WS, on another controller, if you do .$get, and listen to socket, it sends the messages twice to the socket, one from the new and one from the get instance.

I think this is a bug, im going to look into to see if i can fix it, any ideas will be helpful.

Thanks

wilk commented 10 years ago

I'm going to check out this bug. Do you already have an example?

baki250 commented 10 years ago

Ive got it on my local, there is a lot of change ive made, but if you just create 2 controllers, one to set new and then the other to get new, log the events and you will see that its dublicating.

Il setup my dev remotely so you can see later on, i'l PM you the link

wilk commented 9 years ago

I tried with two controllers and $new and $get methods but I didn't get your error. This is the code:

'use strict';

angular.module('MyApp', ['ngWebsocket'])
    .controller('TestCtrl', ['$websocket', function ($websocket) {
        var ws = $websocket.$new({
            url: 'ws://localhost:12345',
            mock: true
        });

        ws.$on('$open', function () {
            ws.$emit('hi', 'there');
        });

        ws.$on('hi', function (msg) {
            console.log('TestCtrl > hi: ' + msg);
        });
    }])
    .controller('LolCtrl', ['$websocket', function ($websocket) {
        var ws = $websocket.$get('ws://localhost:12345');

        ws.$on('hi', function (msg) {
            console.log('LolCtrl > hi: ' + msg);
        });
    }]);

The TestCtrl sends an event called 'hi' with 'hello' data: with a break point at $$send internal method, the debugger stops just once. Then the 'hi' event is handled by the same instance ($new and $get), as expected.

Is it the test right? Can you please post some testing code to reply the bug? Thanks.

Wilk