You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-23 17:02:25 +03:00
Modernize http-api - move from browser-request to fetch (#2719)
This commit is contained in:
committed by
GitHub
parent
913660c818
commit
34c5598a3f
@@ -55,41 +55,6 @@ export {
|
||||
createNewMatrixCall,
|
||||
} from "./webrtc/call";
|
||||
|
||||
// expose the underlying request object so different environments can use
|
||||
// different request libs (e.g. request or browser-request)
|
||||
let requestInstance;
|
||||
|
||||
/**
|
||||
* The function used to perform HTTP requests. Only use this if you want to
|
||||
* use a different HTTP library, e.g. Angular's <code>$http</code>. This should
|
||||
* be set prior to calling {@link createClient}.
|
||||
* @param {requestFunction} r The request function to use.
|
||||
*/
|
||||
export function request(r) {
|
||||
requestInstance = r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the currently-set request function.
|
||||
* @return {requestFunction} The current request function.
|
||||
*/
|
||||
export function getRequest() {
|
||||
return requestInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply wrapping code around the request function. The wrapper function is
|
||||
* installed as the new request handler, and when invoked it is passed the
|
||||
* previous value, along with the options and callback arguments.
|
||||
* @param {requestWrapperFunction} wrapper The wrapping function.
|
||||
*/
|
||||
export function wrapRequest(wrapper) {
|
||||
const origRequest = requestInstance;
|
||||
requestInstance = function(options, callback) {
|
||||
return wrapper(origRequest, options, callback);
|
||||
};
|
||||
}
|
||||
|
||||
let cryptoStoreFactory = () => new MemoryCryptoStore;
|
||||
|
||||
/**
|
||||
@@ -128,15 +93,13 @@ export interface ICryptoCallbacks {
|
||||
/**
|
||||
* Construct a Matrix Client. Similar to {@link module:client.MatrixClient}
|
||||
* except that the 'request', 'store' and 'scheduler' dependencies are satisfied.
|
||||
* @param {(Object|string)} opts The configuration options for this client. If
|
||||
* @param {(Object)} opts The configuration options for this client. If
|
||||
* this is a string, it is assumed to be the base URL. These configuration
|
||||
* options will be passed directly to {@link module:client.MatrixClient}.
|
||||
* @param {Object} opts.store If not set, defaults to
|
||||
* {@link module:store/memory.MemoryStore}.
|
||||
* @param {Object} opts.scheduler If not set, defaults to
|
||||
* {@link module:scheduler~MatrixScheduler}.
|
||||
* @param {requestFunction} opts.request If not set, defaults to the function
|
||||
* supplied to {@link request} which defaults to the request module from NPM.
|
||||
*
|
||||
* @param {module:crypto.store.base~CryptoStore=} opts.cryptoStore
|
||||
* crypto store implementation. Calls the factory supplied to
|
||||
@@ -148,13 +111,7 @@ export interface ICryptoCallbacks {
|
||||
* @see {@link module:client.MatrixClient} for the full list of options for
|
||||
* <code>opts</code>.
|
||||
*/
|
||||
export function createClient(opts: ICreateClientOpts | string) {
|
||||
if (typeof opts === "string") {
|
||||
opts = {
|
||||
"baseUrl": opts,
|
||||
};
|
||||
}
|
||||
opts.request = opts.request || requestInstance;
|
||||
export function createClient(opts: ICreateClientOpts) {
|
||||
opts.store = opts.store || new MemoryStore({
|
||||
localStorage: global.localStorage,
|
||||
});
|
||||
@@ -163,23 +120,6 @@ export function createClient(opts: ICreateClientOpts | string) {
|
||||
return new MatrixClient(opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* The request function interface for performing HTTP requests. This matches the
|
||||
* API for the {@link https://github.com/request/request#requestoptions-callback|
|
||||
* request NPM module}. The SDK will attempt to call this function in order to
|
||||
* perform an HTTP request.
|
||||
* @callback requestFunction
|
||||
* @param {Object} opts The options for this HTTP request.
|
||||
* @param {string} opts.uri The complete URI.
|
||||
* @param {string} opts.method The HTTP method.
|
||||
* @param {Object} opts.qs The query parameters to append to the URI.
|
||||
* @param {Object} opts.body The JSON-serializable object.
|
||||
* @param {boolean} opts.json True if this is a JSON request.
|
||||
* @param {Object} opts._matrix_opts The underlying options set for
|
||||
* {@link MatrixHttpApi}.
|
||||
* @param {requestCallback} callback The request callback.
|
||||
*/
|
||||
|
||||
/**
|
||||
* A wrapper for the request function interface.
|
||||
* @callback requestWrapperFunction
|
||||
|
||||
Reference in New Issue
Block a user