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

how to io.emit? #20

Open
tmdgusya opened this issue Aug 16, 2021 · 0 comments
Open

how to io.emit? #20

tmdgusya opened this issue Aug 16, 2021 · 0 comments

Comments

@tmdgusya
Copy link

i want to use io.emit in my code

in using..

ChattingRouter.on("sendMessage", async (sock, args) => {
  const eventName = args.shift();
  const { name, chat, room_id, user_id } = args.shift();
  console.log(sock);
  const message = await model.Message.create({
    content: chat,
    user_id,
    room_id,
  });
  sock.emit(`receiveMessage${room_id}`, {
    id: message.id,
    name,
    chat,
    user_id,
  });
});

but i want to code write below

ChattingRouter.on("sendMessage", async (sock, args) => {
  const eventName = args.shift();
  const { name, chat, room_id, user_id } = args.shift();
  console.log(sock);
  const message = await model.Message.create({
    content: chat,
    user_id,
    room_id,
  });
  io.emit(`receiveMessage${room_id}`, {
    id: message.id,
    name,
    chat,
    user_id,
  });
});
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