1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-08-09 10:22:46 +03:00

Load Olm from the global rather than requiring it.

This means that we can avoid confusing everybody in the world about how to
webpack js-sdk apps.
This commit is contained in:
Richard van der Hoff
2017-06-01 13:04:04 +01:00
parent 331859d383
commit 41864d46c3
4 changed files with 22 additions and 14 deletions

View File

@@ -236,6 +236,24 @@ host the API reference from the source files like this:
Then visit ``http://localhost:8005`` to see the API docs.
End-to-end encryption support
=============================
The SDK supports end-to-end encryption via the Olm and Megolm protocols, using
[libolm](http://matrix.org/git/olm). It is left up to the application to make
libolm available, via the ``Olm`` global.
To enable support in a browser application:
* download the transpiled libolm (either via ``npm install olm``, or from
https://matrix.org/packages/npm/olm/).
* load ``olm.js`` as a ``<script>`` *before* ``browser-matrix.js``.
To enable support in a node.js application:
* ``npm install olm``
* ``require('olm');`` *before* ``matrix-js-sdk``.
Contributing
============
*This section is for people who want to modify the SDK. If you just

View File

@@ -73,16 +73,9 @@
"uglify-js": "^2.8.26",
"watchify": "^3.2.1"
},
"optionalDependencies": {
"olm": "https://matrix.org/packages/npm/olm/olm-2.2.1.tgz"
},
"browserify": {
"transform": [
"sourceify",
"browserify-shim"
"sourceify"
]
},
"browserify-shim": {
"olm": "global:Olm"
}
}

View File

@@ -47,8 +47,7 @@ try {
var Crypto = require("./crypto");
CRYPTO_ENABLED = true;
} catch (e) {
console.error("olm load error", e);
// Olm not installed.
console.warn("Unable to load crypto module: crypto will be disabled: " + e);
}
/**

View File

@@ -20,11 +20,9 @@ limitations under the License.
*
* @module crypto/OlmDevice
*/
const Olm = require("olm");
const Olm = global.Olm;
if (!Olm) {
// this happens if we were loaded via browserify and the Olm module was not
// loaded.
throw new Error("Olm is not defined");
throw new Error("global.Olm is not defined");
}
const utils = require("../utils");