-
-
Save Raynos/26c3c5d29452417c3a1e 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
function server() { | |
window.require = require | |
// emit a `client` event on the window with the given packet object | |
function send(packet) { | |
var event = document.createEvent("CustomEvent") | |
event.initCustomEvent("client", false, true, packet) | |
console.log("client!", event.detail) | |
window.dispatchEvent(event) | |
} | |
window.addEventListener("server", function(event) { | |
console.log("server?", event.detail) | |
var packet = event.detail | |
var result | |
try { | |
result = window.eval(packet.source) | |
} | |
catch (error) { | |
result = error | |
} | |
send({ from: packet.to, message: result }) | |
}, false); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment