aboutsummaryrefslogtreecommitdiff
path: root/src/proxyClient.js
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-09-08 22:14:04 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-09-08 22:14:04 -0700
commit70fbf7d8d5879c2349cb5c5d6ae2278dcf3d5a51 (patch)
tree7f03cc3e997e5cb64dd89bb6dfc10b92e152a69a /src/proxyClient.js
parent971e59fe7306042f90c85fe0dff04d666b1f01ab (diff)
proxy input events
Diffstat (limited to 'src/proxyClient.js')
-rw-r--r--src/proxyClient.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/proxyClient.js b/src/proxyClient.js
index bbf3e278..41f6a501 100644
--- a/src/proxyClient.js
+++ b/src/proxyClient.js
@@ -41,3 +41,31 @@ worker.onmessage = function(event) {
}
};
+function cloneEvent(event) {
+ var ret = {};
+ for (var x in event) {
+ if (x == x.toUpperCase()) continue;
+ var prop = event[x];
+ if (typeof prop === 'number' || typeof prop === 'string') ret[x] = prop;
+ }
+ return ret;
+};
+
+['keydown', 'keyup', 'keypress', 'blur', 'visibilitychange'].forEach(function(event) {
+ document.addEventListener(event, function(event) {
+ worker.postMessage({ target: 'document', event: cloneEvent(event) });
+ });
+});
+
+['unload'].forEach(function(event) {
+ window.addEventListener(event, function(event) {
+ worker.postMessage({ target: 'window', event: cloneEvent(event) });
+ });
+});
+
+['mousedown', 'mouseup', 'mousemove', 'DOMMouseScroll', 'mousewheel', 'mouseout'].forEach(function(event) {
+ Module.canvas.addEventListener(event, function(event) {
+ worker.postMessage({ target: 'canvas', event: cloneEvent(event) });
+ }, true);
+});
+