Commit 67c99f60 authored by JC Brand's avatar JC Brand

Don't put define in try/catch. Breaks optimizer.

Add check HAS_CSPRNG instead of the previous check
parent 518c0fca
......@@ -12,31 +12,6 @@
console = { log: function () {}, error: function () {} };
}
if (typeof define === 'function' && define.amd) {
var on_load = function(CryptoJS, otr) {
// Use Mustache style syntax for variable interpolation
_.templateSettings = {
evaluate : /\{\[([\s\S]+?)\]\}/g,
interpolate : /\{\{([\s\S]+?)\}\}/g
};
if (typeof otr !== "undefined") {
return factory(jQuery, _, CryptoJS, otr.OTR, otr.DSA, console);
} else {
return factory(jQuery, _, undefined, undefined, undefined, console);
}
};
var dependencies = [
"crypto",
"otr",
"locales",
"backbone.localStorage",
"jquery.tinysort",
"strophe",
"strophe.muc",
"strophe.roster",
"strophe.vcard",
"strophe.disco"
];
try {
define("converse", [
"crypto",
"otr",
......@@ -48,13 +23,14 @@
"strophe.roster",
"strophe.vcard",
"strophe.disco"
], on_load);
} catch (e) {
console.log(e);
// Don't load crypto stuff if the browser doesn't have a CSRNG
dependencies.splice(0, 2);
define("converse", dependencies, on_load);
}
], function(CryptoJS, otr) {
// Use Mustache style syntax for variable interpolation
_.templateSettings = {
evaluate : /\{\[([\s\S]+?)\]\}/g,
interpolate : /\{\{([\s\S]+?)\}\}/g
};
return factory(jQuery, _, CryptoJS, otr.OTR, otr.DSA, console);
});
} else {
// Browser globals
_.templateSettings = {
......@@ -77,11 +53,10 @@
var KEY = {
ENTER: 13
};
var HAS_CRYPTO = (
(typeof CryptoJS !== "undefined") &&
(typeof OTR !== "undefined") &&
(typeof DSA !== "undefined")
);
var HAS_CSPRNG = ((typeof crypto === 'undefined') || (
(typeof crypto.randomBytes !== 'function') &&
(typeof crypto.getRandomValues !== 'function')
));
// Default configuration values
// ----------------------------
......@@ -134,7 +109,7 @@
]));
// Only allow OTR if we have the capability
this.allow_otr = this.allow_otr && HAS_CRYPTO;
this.allow_otr = this.allow_otr && HAS_CSPRNG;
// Translation machinery
// ---------------------
......
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