1 | /*
|
2 | Copyright 2019 The Matrix.org Foundation C.I.C.
|
3 |
|
4 | Licensed under the Apache License, Version 2.0 (the "License");
|
5 | you may not use this file except in compliance with the License.
|
6 | You may obtain a copy of the License at
|
7 |
|
8 | http://www.apache.org/licenses/LICENSE-2.0
|
9 |
|
10 | Unless required by applicable law or agreed to in writing, software
|
11 | distributed under the License is distributed on an "AS IS" BASIS,
|
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 | See the License for the specific language governing permissions and
|
14 | limitations under the License.
|
15 | */
|
16 |
|
17 | import * as matrixcs from "./matrix";
|
18 | import request from "browser-request";
|
19 | import queryString from "qs";
|
20 |
|
21 | matrixcs.request(function(opts, fn) {
|
22 | // We manually fix the query string for browser-request because
|
23 | // it doesn't correctly handle cases like ?via=one&via=two. Instead
|
24 | // we mimic `request`'s query string interface to make it all work
|
25 | // as expected.
|
26 | // browser-request will happily take the constructed string as the
|
27 | // query string without trying to modify it further.
|
28 | opts.qs = queryString.stringify(opts.qs || {}, opts.qsStringifyOptions);
|
29 | return request(opts, fn);
|
30 | });
|
31 |
|
32 | // just *accessing* indexedDB throws an exception in firefox with
|
33 | // indexeddb disabled.
|
34 | let indexedDB;
|
35 | try {
|
36 | indexedDB = global.indexedDB;
|
37 | } catch(e) {}
|
38 |
|
39 | // if our browser (appears to) support indexeddb, use an indexeddb crypto store.
|
40 | if (indexedDB) {
|
41 | matrixcs.setCryptoStoreFactory(
|
42 | function() {
|
43 | return new matrixcs.IndexedDBCryptoStore(
|
44 | indexedDB, "matrix-js-sdk:crypto",
|
45 | );
|
46 | },
|
47 | );
|
48 | }
|
49 |
|
50 | // We export 3 things to make browserify happy as well as downstream projects.
|
51 | // It's awkward, but required.
|
52 | export * from "./matrix";
|
53 | export default matrixcs; // keep export for browserify package deps
|
54 | global.matrixcs = matrixcs;
|