Commit f0bb8e03 authored by Mark Haines's avatar Mark Haines
Browse files

More fixes to the javascript bindings to get them to behave with browserify

parent 970fc60f
var olm_exports = {}; var olm_exports = {};
var get_random_values; var get_random_values;
if (typeof(window) !== 'undefined') { var process; // Shadow the process object so that emscripten won't get
// We've been imported directly into a browser. // confused by browserify
window["Olm"] = olm_exports; if (global && global.window) {
// We're running with browserify
module["exports"] = olm_exports;
global.window["Olm"] = olm_exports;
get_random_values = function(buf) { get_random_values = function(buf) {
window.crypto.getRandomValues(buf); window.crypto.getRandomValues(buf);
}; };
} else if (global.window) { } else if (typeof(window) !== 'undefined') {
// We're running with browserify // We've been imported directly into a browser.
global.window["Olm"] = olm_exports; window["Olm"] = olm_exports;
get_random_values = function(buf) { get_random_values = function(buf) {
window.crypto.getRandomValues(buf); window.crypto.getRandomValues(buf);
}; };
...@@ -20,6 +23,7 @@ if (typeof(window) !== 'undefined') { ...@@ -20,6 +23,7 @@ if (typeof(window) !== 'undefined') {
var bytes = nodeCrypto.randomBytes(buf.length); var bytes = nodeCrypto.randomBytes(buf.length);
buf.set(bytes); buf.set(bytes);
} }
process = global.process;
} else { } else {
throw new Error("Cannot find global to attach library to"); throw new Error("Cannot find global to attach library to");
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment