UNPKG

1.88 kBJavaScriptView Raw
1/*
2Copyright 2019 The Matrix.org Foundation C.I.C.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17import * as matrixcs from "./matrix";
18import request from "browser-request";
19import queryString from "qs";
20
21matrixcs.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.
34let indexedDB;
35try {
36 indexedDB = global.indexedDB;
37} catch(e) {}
38
39// if our browser (appears to) support indexeddb, use an indexeddb crypto store.
40if (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.
52export * from "./matrix";
53export default matrixcs; // keep export for browserify package deps
54global.matrixcs = matrixcs;