← All Exercises
Route Desktop IPC Messages to Handlers
basicjavascript
Background
Desktop apps fail when a renderer sends a channel the main process never registered. Explicit dispatch reporting turns a silent no-op into a visible error.
Problem
Match IPC messages to the handlers registered by the target process window and report anything that cannot be dispatched.
Input
JSON object: { handlers: { [channel]: string[] }, messages: [{ id, channel, window }] }Output
JSON object: { dispatched: string[], undelivered: [{ id, reason }] }Sample tests
Sample 1
Input: {"handlers":{"menu":["window"],"job":["worker"]},"messages":[{"id":"m1","channel":"menu","window":"window"},{"id":"m2","channel":"job","window":"window"}]}Expected: {"dispatched":["m1"],"undelivered":[{"id":"m2","reason":"no-handler-in-window"}]}Sample 2
Input: {"handlers":{},"messages":[{"id":"m3","channel":"menu","window":"window"}]}Expected: {"dispatched":[],"undelivered":[{"id":"m3","reason":"unknown-channel"}]}Your solution
Learning objective
Diagnose IPC failures from routing tables instead of runtime logs.