Skip to content

Instantly share code, notes, and snippets.

@Zemnmez
Created August 12, 2021 20:06
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zemnmez/03955e1423f043d1b7640bffade74c09 to your computer and use it in GitHub Desktop.
Save Zemnmez/03955e1423f043d1b7640bffade74c09 to your computer and use it in GitHub Desktop.
const prefix = "pmrpc."
if (!data.startsWith(prefix)) throw new Error(`got weird messsage ${JSON.stringify(data)}`);
// trim off 'pmrpc.'
const json = data.slice(prefix.length);
// extract the request JSON
const rq = JSON.parse(json);
const { method, jsonrpc, params, id } = rq;
// if we get a config, just return our pre-prepared response
if (method == "config") return frame.postMessage(`${prefix}${JSON.stringify({
...config_resp, jsonrpc, id
})}`, "*");
// for everything else just tell the child it went OK
frame.postMessage(`${prefix}${JSON.stringify({
jsonrpc, id, result: true
})}`, "*");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment