Skip to main content
Version: 5.x.x

Emitting

Use the emit method to start the event emitting.

type ChatMessageType = {
message: string;
};

type AcknowledgementResponseType = boolean;

const sendChatMessage = socketInstance.createEmitter<ChatMessageType, AcknowledgementResponseType>()({
endpoint: "chat-message", // endpoint of the event
});

sendChatMessage.emit({ message: "new message" }, (error, data) => {
if (data === true) {
console.log("Correct!");
}
});

// or

sendChatMessage.setData({ message: "new message" }).emit({}, (error, data) => {
if (data === true) {
console.log("Correct!");
}
});