Licence
ISC
Version
0.13.1
Deps
1
Size
26 kB
Vulns
1
Weekly
0
ToDesktop IPC
Communicating between desktop app windows.
Installation
Install @todesktop/client-ipc in your client-side application using
npm install @todesktop/client-ipc
Installation of the plugin package is also necessary. Using ToDesktop Builder, navigate to Plugins. Click on the Explore button for "Selected Text" and install the package.
Usage
subscribe
Subscribes to a messaging channel and executes a callback when that message is triggered. The callback contains the data and context information from the sender.
You can also unsubscribe from a messaging channel by executing the function that is returned from the initial subscribe call.
import { subscribe } from "@todesktop/client-ipc";
const unsubscribe = subscribe("foo", (data, context) => {
console.log({ data, context });
/**
* {
* data: { msg: "bar" },
* context: { windowId: 2, viewId: 2 }
* }
*/
});
// ...later
unsubscribe();
publish
Publishes data to a messaging channel.
import { publish } from "@todesktop/client-ipc";
publish("foo", { msg: "bar" });
Logging
By default, the IPC plugin logs all events to the console. You can disable logging if needed:
import { logging } from "@todesktop/client-ipc";
// Disable all IPC logging
logging.disable();
// Re-enable logging
logging.enable();
// Or set it conditionally
logging.set(process.env.NODE_ENV === "development");
// Check current state
console.log(logging.enabled); // true or false
identify
Retrieves id information about the window and view.
import { identify } from "@todesktop/client-ipc";
async () => {
console.log(await identify());
/**
* {
* windowId: 1,
* viewId: 1
* }
*/
};