I'm trying to call an event, but an error occurs: UnhandledPromiseRejectionWar ning: TypeError: Cannot read property 'emit' of undefined How it is possible to bypass it? nodejs
import { io } from 'socket.io-client';
import { EventEmitter2, OnEvent } from '@nestjs/event-emitter';
import { SynchronizeService } from './synchronize.service';
import { UserService } from '../user/user.service';
const serverAddress = 'http://localhost:3050'
const socket = io(serverAddress, { reconnection: true })
export class SocketClient {
constructor(
private readonly synchronizeService: SynchronizeService,
private eventEmitter: EventEmitter2,
private readonly userService: UserService
) {}
@OnEvent('order.created')
async handler(req):Promise<void> {
try{
socket.on('synchronize', () => {
});
socket.on('send_from_server', async ({ msg }) => {
await this.eventEmitter.emitAsync('order.came')
});
socket.emit('synchronize', req);
} catch (e) {
console.log(e);
}
}
}