Skip to content

Instantly share code, notes, and snippets.

@Raynos
Created March 12, 2013 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Raynos/26c3c5d29452417c3a1e to your computer and use it in GitHub Desktop.
Save Raynos/26c3c5d29452417c3a1e to your computer and use it in GitHub Desktop.
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