I am working on Real Time chat app using https://www.npmjs.com/package/ng-socket-io and NodeJs Server, I am have successfully configured the Socket Modul and now able to connect and get live users. I have added SocketIoModule in app.module.ts without configuration and I am configuring that in a service like this
const config: SocketIoConfig = {
url: 'https://example.com:3000',
options: {
query: {
'platform': 'somePlatform',
'apiUrl': 'someURL',
'clientId': clientId,
'clientSecret': clientSecret,
'Content-Type': "application/json",
}
}
};
@Injectable()
export class ChatServiceProvider extends Socket {
token: any;
constructor() {
console.log('token', UserInfoProvider.token);
config['options']['query']['Authorization'] = 'Bearer ' + UserInfoProvider.token;
console.log('COnfig', config);
super(config);
}
}
and injected that service into my chat page constructor. now I am calling a function which connecting and getting live users successfully following is my code
constructor(public socket: ChatServiceProvider){}
this.socket.on('connect', () => {
console.log('connected..........................')
this.socket.emit('handshake', response);
this.socket.on('live', (data) => {
console.log('LIVE', data);
});
this.socket.on('operator', (data) => {
console.log('OPERATOR', data);
this.agents = data;
this.getAgents();
});
this.socket.on('error', (data) => {
console.log('ERROR', data);
});
this.socket.on('message', msg => {
console.log('NewMessage', msg);
debugger
});
});
}
in Above code I am able to connect and listen for live users but unable to receive new messages same is the case for emitting the message that is also not working
this.socket.emit("message", msgdata);
can someone please guide me what I am doing wrong any help appreciated.
Thanks!