rednode API - v0.80.1
    Preparing search index...

    Variable channelConst

    channel: {
        on<T = any>(handler: (data: T) => void): () => void;
        post(data: unknown): void;
    } = ...

    Messages between a package's overlay pages and its own Node mod: a web UI with a Node backend. What one side posts, the other side's handlers get. Data must be plain JSON-like values.

    Type Declaration

    • on: function
      • Calls the handler for every message from the other side. Returns a function that stops it.

        Type Parameters

        • T = any

        Parameters

        • handler: (data: T) => void

        Returns () => void

    • post: function
      • post(data: unknown): void

        Sends data to the other side: from a mod to its pages, from a page to its mod.

        Parameters

        • data: unknown

        Returns void

    // In the Node mod
    import { channel } from "rednode";
    channel.on((msg) => {
    if (msg.type === "ping") channel.post({ type: "pong" });
    });

    // In the package's page
    import { channel } from "rednode";
    channel.on((msg) => console.log(msg.type)); // "pong"
    channel.post({ type: "ping" });