aboutsummaryrefslogtreecommitdiff
path: root/javascript
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2015-07-20 16:33:45 +0100
committerMark Haines <mark.haines@matrix.org>2015-07-20 16:33:45 +0100
commitf0bb8e03b315356a105975df83200cd87f24efb3 (patch)
tree85d3686c8b78380d388d2bdc1d89136a183f2293 /javascript
parent970fc60f8bea21ea91baaaed2555a11df41a947d (diff)
More fixes to the javascript bindings to get them to behave with browserify
Diffstat (limited to 'javascript')
-rw-r--r--javascript/olm_pre.js16
1 files changed, 10 insertions, 6 deletions
diff --git a/javascript/olm_pre.js b/javascript/olm_pre.js
index 5a348af..cab59f0 100644
--- a/javascript/olm_pre.js
+++ b/javascript/olm_pre.js
@@ -1,14 +1,17 @@
var olm_exports = {};
var get_random_values;
-if (typeof(window) !== 'undefined') {
- // We've been imported directly into a browser.
- window["Olm"] = olm_exports;
+var process; // Shadow the process object so that emscripten won't get
+ // confused by browserify
+if (global && global.window) {
+ // We're running with browserify
+ module["exports"] = olm_exports;
+ global.window["Olm"] = olm_exports;
get_random_values = function(buf) {
window.crypto.getRandomValues(buf);
};
-} else if (global.window) {
- // We're running with browserify
- global.window["Olm"] = olm_exports;
+} else if (typeof(window) !== 'undefined') {
+ // We've been imported directly into a browser.
+ window["Olm"] = olm_exports;
get_random_values = function(buf) {
window.crypto.getRandomValues(buf);
};
@@ -20,6 +23,7 @@ if (typeof(window) !== 'undefined') {
var bytes = nodeCrypto.randomBytes(buf.length);
buf.set(bytes);
}
+ process = global.process;
} else {
throw new Error("Cannot find global to attach library to");
}