diff --git a/Makefile b/Makefile index a1ea744c2557ca9500464fd97d71e4b96cc08bb6..44020b83aa3a9d6bc128a3b0aa196f5e8c306670 100644 --- a/Makefile +++ b/Makefile @@ -94,7 +94,7 @@ LDFLAGS += -Wall -Werror CFLAGS_NATIVE = -fPIC CXXFLAGS_NATIVE = -fPIC -EMCCFLAGS = --closure 1 --memory-init-file 0 -s NO_FILESYSTEM=1 -s INVOKE_RUN=0 -s MODULARIZE=1 +EMCCFLAGS = --closure 1 --memory-init-file 0 -s NO_FILESYSTEM=1 -s INVOKE_RUN=0 -s MODULARIZE=1 -s ENVIRONMENT=web # Olm generally doesn't need a lot of memory to encrypt / decrypt its usual # payloads (ie. Matrix messages), but we do need about 128K of heap to encrypt diff --git a/javascript/olm_pre.js b/javascript/olm_pre.js index 314d7da7e5cda3ebbf328fd92e1453328de2c2cd..e3a07311aac0db24ecb57b283d8f9e90f2944ce3 100644 --- a/javascript/olm_pre.js +++ b/javascript/olm_pre.js @@ -1,23 +1,6 @@ -var get_random_values; - -if (typeof(window) !== 'undefined') { - // We're in a browser (directly, via browserify, or via webpack). - get_random_values = function(buf) { +var get_random_values = function(buf) { window.crypto.getRandomValues(buf); }; -} else if (module["exports"]) { - // We're running in node. - var nodeCrypto = require("crypto"); - get_random_values = function(buf) { - // [''] syntax needed here rather than '.' to prevent - // closure compiler from mangling the import(!) - var bytes = nodeCrypto['randomBytes'](buf.length); - buf.set(bytes); - }; - process = global["process"]; -} else { - throw new Error("Cannot find global to attach library to"); -} /* applications should define OLM_OPTIONS in the environment to override * emscripten module settings