22Copyright 2015, 2016 OpenMarket Ltd
33Copyright 2017 Vector Creations Ltd
44Copyright 2018, 2019 New Vector Ltd
5+ Copyright 2019 Michael Telatynski <7t3chguy@gmail.com>
56
67Licensed under the Apache License, Version 2.0 (the "License");
78you may not use this file except in compliance with the License.
@@ -43,7 +44,6 @@ import PlatformPeg from 'matrix-react-sdk/lib/PlatformPeg';
4344sdk . loadSkin ( require ( '../component-index' ) ) ;
4445import VectorConferenceHandler from 'matrix-react-sdk/lib/VectorConferenceHandler' ;
4546import Promise from 'bluebird' ;
46- import request from 'browser-request' ;
4747import * as languageHandler from 'matrix-react-sdk/lib/languageHandler' ;
4848import { _t , _td , newTranslatableError } from 'matrix-react-sdk/lib/languageHandler' ;
4949import AutoDiscoveryUtils from 'matrix-react-sdk/lib/utils/AutoDiscoveryUtils' ;
@@ -66,8 +66,6 @@ import Olm from 'olm';
6666
6767import CallHandler from 'matrix-react-sdk/lib/CallHandler' ;
6868
69- import { getVectorConfig } from './getconfig' ;
70-
7169let lastLocationHashSet = null ;
7270
7371// Disable warnings for now: we use deprecated bluebird functions
@@ -119,7 +117,7 @@ function routeUrl(location) {
119117}
120118
121119function onHashChange ( ev ) {
122- if ( decodeURIComponent ( window . location . hash ) == lastLocationHashSet ) {
120+ if ( decodeURIComponent ( window . location . hash ) === lastLocationHashSet ) {
123121 // we just set this: no need to route it!
124122 return ;
125123 }
@@ -159,7 +157,7 @@ function makeRegistrationUrl(params) {
159157
160158 const keys = Object . keys ( params ) ;
161159 for ( let i = 0 ; i < keys . length ; ++ i ) {
162- if ( i == 0 ) {
160+ if ( i === 0 ) {
163161 url += '?' ;
164162 } else {
165163 url += '&' ;
@@ -170,38 +168,6 @@ function makeRegistrationUrl(params) {
170168 return url ;
171169}
172170
173- export function getConfig ( configJsonFilename ) {
174- return new Promise ( function ( resolve , reject ) {
175- request (
176- { method : "GET" , url : configJsonFilename } ,
177- ( err , response , body ) => {
178- if ( err || response . status < 200 || response . status >= 300 ) {
179- // Lack of a config isn't an error, we should
180- // just use the defaults.
181- // Also treat a blank config as no config, assuming
182- // the status code is 0, because we don't get 404s
183- // from file: URIs so this is the only way we can
184- // not fail if the file doesn't exist when loading
185- // from a file:// URI.
186- if ( response ) {
187- if ( response . status == 404 || ( response . status == 0 && body == '' ) ) {
188- resolve ( { } ) ;
189- }
190- }
191- reject ( { err : err , response : response } ) ;
192- return ;
193- }
194-
195- // We parse the JSON ourselves rather than use the JSON
196- // parameter, since this throws a parse error on empty
197- // which breaks if there's no config.json and we're
198- // loading from the filesystem (see above).
199- resolve ( JSON . parse ( body ) ) ;
200- } ,
201- ) ;
202- } ) ;
203- }
204-
205171function onTokenLoginCompleted ( ) {
206172 // if we did a token login, we're now left with the token, hs and is
207173 // url as query params in the url; a little nasty but let's redirect to
@@ -252,12 +218,12 @@ async function loadApp() {
252218 PlatformPeg . set ( new WebPlatform ( ) ) ;
253219 }
254220
255- // Load the config file. First try to load up a domain-specific config of the
256- // form "config.$domain.json" and if that fails, fall back to config.json.
221+ const platform = PlatformPeg . get ( ) ;
222+
257223 let configJson ;
258224 let configError ;
259225 try {
260- configJson = await getVectorConfig ( ) ;
226+ configJson = await platform . getConfig ( ) ;
261227 } catch ( e ) {
262228 configError = e ;
263229 }
@@ -342,7 +308,6 @@ async function loadApp() {
342308 Unable to load config file: please refresh the page to try again.
343309 </ div > , document . getElementById ( 'matrixchat' ) ) ;
344310 } else if ( validBrowser || acceptInvalidBrowser ) {
345- const platform = PlatformPeg . get ( ) ;
346311 platform . startUpdater ( ) ;
347312
348313 // Don't bother loading the app until the config is verified
@@ -410,7 +375,7 @@ function loadOlm() {
410375 } ) . then ( ( ) => {
411376 console . log ( "Using WebAssembly Olm" ) ;
412377 } ) . catch ( ( e ) => {
413- console . log ( "Failed to load Olm: trying legacy version" ) ;
378+ console . log ( "Failed to load Olm: trying legacy version" , e ) ;
414379 return new Promise ( ( resolve , reject ) => {
415380 const s = document . createElement ( 'script' ) ;
416381 s . src = 'olm_legacy.js' ; // XXX: This should be cache-busted too
0 commit comments