io()
This function enables real-time, bidirectional communication between web clients and servers commonly used for features like real-time chat, live updates and collaborative editing in web applications.
Example:
import { createBackendFunction, io } from "@magicjs.dev/backend";
import moment from "moment";
export default createBackendFunction(async function () {
try {
io().to(`public/room`).emit(`refresh`);
} catch (error) {}
});
When the backend function is invoked, potentially in response to an API request, it emits a "refresh" event to all clients within the "public/room" using the io
module. This event can be intercepted on the client side, enabling real-time communication and supporting actions such as triggering a refresh or update on the client interface. This mechanism serves as a means to broadcast information to all connected clients in the specified room, fostering synchronized updates across multiple users in a real-time manner.
Last updated