UNPKG

1.18 kBJavaScriptView Raw
1var matrixcs = require("./lib/matrix");
2const request = require('browser-request');
3const queryString = require('qs');
4
5matrixcs.request(function(opts, fn) {
6 // We manually fix the query string for browser-request because
7 // it doesn't correctly handle cases like ?via=one&via=two. Instead
8 // we mimic `request`'s query string interface to make it all work
9 // as expected.
10 // browser-request will happily take the constructed string as the
11 // query string without trying to modify it further.
12 opts.qs = queryString.stringify(opts.qs || {}, opts.qsStringifyOptions);
13 return request(opts, fn);
14});
15
16// just *accessing* indexedDB throws an exception in firefox with
17// indexeddb disabled.
18var indexedDB;
19try {
20 indexedDB = global.indexedDB;
21} catch(e) {}
22
23// if our browser (appears to) support indexeddb, use an indexeddb crypto store.
24if (indexedDB) {
25 matrixcs.setCryptoStoreFactory(
26 function() {
27 return new matrixcs.IndexedDBCryptoStore(
28 indexedDB, "matrix-js-sdk:crypto"
29 );
30 }
31 );
32}
33
34module.exports = matrixcs; // keep export for browserify package deps
35global.matrixcs = matrixcs;