1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-23 17:02:25 +03:00

Merge branch 'develop' into robertlong/group-call

This commit is contained in:
Robin Townsend
2022-10-13 20:14:29 -04:00
104 changed files with 6514 additions and 4382 deletions

View File

@@ -64,41 +64,6 @@ export {
} from "./webrtc/groupCall";
export type { GroupCall } from "./webrtc/groupCall";
// 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;
/**
@@ -111,10 +76,7 @@ export function setCryptoStoreFactory(fac) {
cryptoStoreFactory = fac;
}
function amendClientOpts(opts: ICreateClientOpts | string): ICreateClientOpts {
if (typeof opts === "string") opts = { baseUrl: opts };
opts.request = opts.request ?? requestInstance;
function amendClientOpts(opts: ICreateClientOpts): ICreateClientOpts {
opts.store = opts.store ?? new MemoryStore({
localStorage: global.localStorage,
});
@@ -127,15 +89,12 @@ function amendClientOpts(opts: ICreateClientOpts | string): ICreateClientOpts {
/**
* 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
* this is a string, it is assumed to be the base URL. These configuration
* @param {Object} opts The configuration options for this client. 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
@@ -147,7 +106,7 @@ function amendClientOpts(opts: ICreateClientOpts | string): ICreateClientOpts {
* @see {@link module:client.MatrixClient} for the full list of options for
* <code>opts</code>.
*/
export function createClient(opts: ICreateClientOpts | string): MatrixClient {
export function createClient(opts: ICreateClientOpts): MatrixClient {
return new MatrixClient(amendClientOpts(opts));
}
@@ -155,46 +114,7 @@ export function createRoomWidgetClient(
widgetApi: WidgetApi,
capabilities: ICapabilities,
roomId: string,
opts: ICreateClientOpts | string,
opts: ICreateClientOpts,
): MatrixClient {
return new RoomWidgetClient(widgetApi, capabilities, roomId, amendClientOpts(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
* @param {requestFunction} origRequest The underlying request function being
* wrapped
* @param {Object} opts The options for this HTTP request, given in the same
* form as {@link requestFunction}.
* @param {requestCallback} callback The request callback.
*/
/**
* The request callback 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 implement a callback which meets this
* interface in order to handle the HTTP response.
* @callback requestCallback
* @param {Error} err The error if one occurred, else falsey.
* @param {Object} response The HTTP response which consists of
* <code>{statusCode: {Number}, headers: {Object}}</code>
* @param {Object} body The parsed HTTP response body.
*/