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
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 = [];
Thanks