1
0
Fork 0
mutter-performance-source/examples/emscripten-example-js-library.js
Robert Bragg 9ef37423fc emscripten-hello: improve mainloop integration
Instead of simply relying on the emscripten mainloop api to wake us up
periodically so that we can poll for SDL events we now pause the
emscripten mainloop whenever no redraw is queued and instead hook an
input event listener into the real browser mainloop to resume the
emscripten mainloop whenever input is received. This way the example
can go to sleep while there's no input to handle.

This provides a simple example of binding custom javascript into native
code.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit a8b1e2eda491dc7c44c84cd47e160c7b8ba0f792)
2013-05-29 19:30:44 +01:00

19 lines
514 B
JavaScript

//"use strict";
var LibraryEXAMPLE = {
$EXAMPLE__deps: ['$Browser'],
$EXAMPLE: {
receiveEvent: function(event) {
Browser.mainLoop.resume();
},
},
example_js_add_input_listener: function() {
['mousedown', 'mouseup', 'mousemove', 'DOMMouseScroll',
'mousewheel', 'mouseout'].forEach(function(event) {
Module['canvas'].addEventListener(event, EXAMPLE.receiveEvent, true);
});
}
};
autoAddDeps(LibraryEXAMPLE, '$EXAMPLE');
mergeInto(LibraryManager.library, LibraryEXAMPLE);