I have to use simple socket client for angular 4 frontend. When I receive data to socket.on can't assign that data to global variables & can't call any function inside socket.on.
public sessionId;
constructor(){
var socket = io.connect('http://**.***.***.***:****');
socket.on('connect', function (data) {
console.log('user connected');
socket.emit('add user', { userId: uid });
});
socket.on('create channel', function (data) {
console.log(data);
this.sessionId = data.sessionId; //error
this.function(); //error
socket.emit('feedback', { received: true });
});
}
function(){}