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

$get return undefined #37

Open
ValentinCro opened this issue Feb 26, 2016 · 0 comments
Open

$get return undefined #37

ValentinCro opened this issue Feb 26, 2016 · 0 comments

Comments

@ValentinCro
Copy link

Hi,

When i try to communicate between two browser. I open a socket in one but i can't get it in the second one. $get method return to me undefined, the url is good. It's like the second browser doesn't see the first one socket.

My code :

var socketCtrl = this;
socketCtrl.socket = [];

            socketCtrl.newSocket = function (nameSocket) {
                var ws = $websocket.$new({
                    url: 'ws://localhost',
                    reconnect: true, // it will reconnect after 2 seconds
                    mock: true
                });
                ws.$on('message', function (message) {
                        console.log(message); // it prints 'a parrot response'
                    });
                ws.$on('$open', function () {
                    console.log('Connection open!');
                });
                ws.$on('$close', function () {
                    console.log('Connection closed!');
                });
                socketCtrl.socket.push(ws);
            };

            socketCtrl.getSocket = function (nameSocket) {
                var ws = $websocket.$get('ws://localhost');
                console.log(ws.$ready());
                socketCtrl.socket.push(ws);
            };

            socketCtrl.closeSocket = function (idSocket) {
                if (socketCtrl.socket.length > idSocket) {
                    socketCtrl.socket[idSocket].$close();
                }
            };

            socketCtrl.sendMessage = function (idSocket, message) {
                if (socketCtrl.socket.length > idSocket) {
                    socketCtrl.socket[idSocket].$emit('message', message);
                }
            };

Thanks

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

1 participant