Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dublicate response on new then get #7

Open
baki250 opened this issue Nov 4, 2014 · 3 comments
Open

Dublicate response on new then get #7

baki250 opened this issue Nov 4, 2014 · 3 comments

Comments

@baki250
Copy link
Contributor

baki250 commented Nov 4, 2014

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
Copy link
Owner

wilk commented Nov 5, 2014

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

@baki250
Copy link
Contributor Author

baki250 commented Nov 5, 2014

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
Copy link
Owner

wilk commented Nov 9, 2014

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants