Skip to content

how to io.emit? #20

@tmdgusya

Description

@tmdgusya

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,
  });
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions