-
-
Save Zemnmez/03955e1423f043d1b7640bffade74c09 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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