You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-12-05 17:02:07 +03:00
Convert src to ES6
The bulk of this is just export/import changes, though there's a couple pieces to highlight: * We no longer use default exports. This is because it's discouraged by the JS community, though not in any official capacity. * We now use `polyfillSuper` for some prototype inheritance because the tests, and sometimes webpack, break on "cannot call EncryptionAlgorithm without 'new'". It's very much a workaround, and definitely not needed when we use real classes. There is some import shuffling to help keep the imports clean - this was done by my IDE.
This commit is contained in:
@@ -18,44 +18,39 @@ limitations under the License.
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const PushProcessor = require('./pushprocessor');
|
||||
import {sleep} from './utils';
|
||||
|
||||
/**
|
||||
* This is an internal module. See {@link MatrixClient} for the public class.
|
||||
* @module client
|
||||
*/
|
||||
const EventEmitter = require("events").EventEmitter;
|
||||
const url = require('url');
|
||||
|
||||
const httpApi = require("./http-api");
|
||||
const MatrixEvent = require("./models/event").MatrixEvent;
|
||||
const EventStatus = require("./models/event").EventStatus;
|
||||
const EventTimeline = require("./models/event-timeline");
|
||||
const SearchResult = require("./models/search-result");
|
||||
const StubStore = require("./store/stub");
|
||||
const webRtcCall = require("./webrtc/call");
|
||||
const utils = require("./utils");
|
||||
const contentRepo = require("./content-repo");
|
||||
const Filter = require("./filter");
|
||||
const SyncApi = require("./sync");
|
||||
const MatrixBaseApis = require("./base-apis");
|
||||
const MatrixError = httpApi.MatrixError;
|
||||
const ContentHelpers = require("./content-helpers");
|
||||
const olmlib = require("./crypto/olmlib");
|
||||
|
||||
import ReEmitter from './ReEmitter';
|
||||
import RoomList from './crypto/RoomList';
|
||||
import logger from './logger';
|
||||
|
||||
import Crypto from './crypto';
|
||||
import { isCryptoAvailable } from './crypto';
|
||||
import { decodeRecoveryKey } from './crypto/recoverykey';
|
||||
import { keyFromAuthData } from './crypto/key_passphrase';
|
||||
import { randomString } from './randomstring';
|
||||
import url from "url";
|
||||
import {EventEmitter} from "events";
|
||||
import {MatrixBaseApis} from "./base-apis";
|
||||
import {Filter} from "./filter";
|
||||
import {SyncApi} from "./sync";
|
||||
import {EventStatus, MatrixEvent} from "./models/event";
|
||||
import {EventTimeline} from "./models/event-timeline";
|
||||
import {SearchResult} from "./models/search-result";
|
||||
import {StubStore} from "./store/stub";
|
||||
import {createNewMatrixCall} from "./webrtc/call";
|
||||
import * as utils from './utils';
|
||||
import {sleep} from './utils';
|
||||
import {MatrixError, PREFIX_MEDIA_R0, PREFIX_UNSTABLE} from "./http-api";
|
||||
import * as contentRepo from "./content-repo";
|
||||
import * as ContentHelpers from "./content-helpers";
|
||||
import * as olmlib from "./crypto/olmlib";
|
||||
import {ReEmitter} from './ReEmitter';
|
||||
import {RoomList} from './crypto/RoomList';
|
||||
import {logger} from './logger';
|
||||
import {Crypto, isCryptoAvailable} from './crypto';
|
||||
import {decodeRecoveryKey} from './crypto/recoverykey';
|
||||
import {keyFromAuthData} from './crypto/key_passphrase';
|
||||
import {randomString} from './randomstring';
|
||||
import {PushProcessor} from "./pushprocessor";
|
||||
|
||||
const SCROLLBACK_DELAY_MS = 3000;
|
||||
const CRYPTO_ENABLED = isCryptoAvailable();
|
||||
export const CRYPTO_ENABLED = isCryptoAvailable();
|
||||
const CAPABILITIES_CACHE_MS = 21600000; // 6 hours - an arbitrary value
|
||||
|
||||
function keysFromRecoverySession(sessions, decryptionKey, roomId) {
|
||||
@@ -234,7 +229,7 @@ function keyFromRecoverySession(session, decryptionKey) {
|
||||
* {DeviceTrustLevel} device_trust: The trust status of the device requesting
|
||||
* the secret as returned by {@link module:client~MatrixClient#checkDeviceTrust}.
|
||||
*/
|
||||
function MatrixClient(opts) {
|
||||
export function MatrixClient(opts) {
|
||||
opts.baseUrl = utils.ensureNoTrailingSlash(opts.baseUrl);
|
||||
opts.idBaseUrl = utils.ensureNoTrailingSlash(opts.idBaseUrl);
|
||||
|
||||
@@ -273,7 +268,7 @@ function MatrixClient(opts) {
|
||||
|
||||
// try constructing a MatrixCall to see if we are running in an environment
|
||||
// which has WebRTC. If we are, listen for and handle m.call.* events.
|
||||
const call = webRtcCall.createNewMatrixCall(this);
|
||||
const call = createNewMatrixCall(this);
|
||||
this._supportsVoip = false;
|
||||
if (call) {
|
||||
setupCallEventHandler(this);
|
||||
@@ -1345,7 +1340,7 @@ MatrixClient.prototype.checkKeyBackup = function() {
|
||||
MatrixClient.prototype.getKeyBackupVersion = function() {
|
||||
return this._http.authedRequest(
|
||||
undefined, "GET", "/room_keys/version", undefined, undefined,
|
||||
{prefix: httpApi.PREFIX_UNSTABLE},
|
||||
{prefix: PREFIX_UNSTABLE},
|
||||
).then((res) => {
|
||||
if (res.algorithm !== olmlib.MEGOLM_BACKUP_ALGORITHM) {
|
||||
const err = "Unknown backup algorithm: " + res.algorithm;
|
||||
@@ -1506,7 +1501,7 @@ MatrixClient.prototype.createKeyBackupVersion = async function(info) {
|
||||
|
||||
const res = await this._http.authedRequest(
|
||||
undefined, "POST", "/room_keys/version", undefined, data,
|
||||
{prefix: httpApi.PREFIX_UNSTABLE},
|
||||
{prefix: PREFIX_UNSTABLE},
|
||||
);
|
||||
this.enableKeyBackup({
|
||||
algorithm: info.algorithm,
|
||||
@@ -1534,7 +1529,7 @@ MatrixClient.prototype.deleteKeyBackupVersion = function(version) {
|
||||
|
||||
return this._http.authedRequest(
|
||||
undefined, "DELETE", path, undefined, undefined,
|
||||
{prefix: httpApi.PREFIX_UNSTABLE},
|
||||
{prefix: PREFIX_UNSTABLE},
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1576,7 +1571,7 @@ MatrixClient.prototype.sendKeyBackup = function(roomId, sessionId, version, data
|
||||
const path = this._makeKeyBackupPath(roomId, sessionId, version);
|
||||
return this._http.authedRequest(
|
||||
undefined, "PUT", path.path, path.queryData, data,
|
||||
{prefix: httpApi.PREFIX_UNSTABLE},
|
||||
{prefix: PREFIX_UNSTABLE},
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1665,7 +1660,7 @@ MatrixClient.prototype._restoreKeyBackup = function(
|
||||
|
||||
return this._http.authedRequest(
|
||||
undefined, "GET", path.path, path.queryData, undefined,
|
||||
{prefix: httpApi.PREFIX_UNSTABLE},
|
||||
{prefix: PREFIX_UNSTABLE},
|
||||
).then((res) => {
|
||||
if (res.rooms) {
|
||||
for (const [roomId, roomData] of Object.entries(res.rooms)) {
|
||||
@@ -1673,7 +1668,7 @@ MatrixClient.prototype._restoreKeyBackup = function(
|
||||
|
||||
totalKeyCount += Object.keys(roomData.sessions).length;
|
||||
const roomKeys = keysFromRecoverySession(
|
||||
roomData.sessions, decryption, roomId, roomKeys,
|
||||
roomData.sessions, decryption, roomId,
|
||||
);
|
||||
for (const k of roomKeys) {
|
||||
k.room_id = roomId;
|
||||
@@ -1715,7 +1710,7 @@ MatrixClient.prototype.deleteKeysFromBackup = function(roomId, sessionId, versio
|
||||
const path = this._makeKeyBackupPath(roomId, sessionId, version);
|
||||
return this._http.authedRequest(
|
||||
undefined, "DELETE", path.path, path.queryData, undefined,
|
||||
{prefix: httpApi.PREFIX_UNSTABLE},
|
||||
{prefix: PREFIX_UNSTABLE},
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1751,7 +1746,7 @@ MatrixClient.prototype.getGroups = function() {
|
||||
MatrixClient.prototype.getMediaConfig = function(callback) {
|
||||
return this._http.authedRequest(
|
||||
callback, "GET", "/config", undefined, undefined, {
|
||||
prefix: httpApi.PREFIX_MEDIA_R0,
|
||||
prefix: PREFIX_MEDIA_R0,
|
||||
},
|
||||
);
|
||||
};
|
||||
@@ -2688,7 +2683,7 @@ MatrixClient.prototype.getUrlPreview = function(url, ts, callback) {
|
||||
url: url,
|
||||
ts: ts,
|
||||
}, undefined, {
|
||||
prefix: httpApi.PREFIX_MEDIA_R0,
|
||||
prefix: PREFIX_MEDIA_R0,
|
||||
},
|
||||
).then(function(response) {
|
||||
// TODO: expire cache occasionally
|
||||
@@ -4797,7 +4792,7 @@ function setupCallEventHandler(client) {
|
||||
);
|
||||
}
|
||||
|
||||
call = webRtcCall.createNewMatrixCall(client, event.getRoomId(), {
|
||||
call = createNewMatrixCall(client, event.getRoomId(), {
|
||||
forceTURN: client._forceTURN,
|
||||
});
|
||||
if (!call) {
|
||||
@@ -4897,7 +4892,7 @@ function setupCallEventHandler(client) {
|
||||
// if not live, store the fact that the call has ended because
|
||||
// we're probably getting events backwards so
|
||||
// the hangup will come before the invite
|
||||
call = webRtcCall.createNewMatrixCall(client, event.getRoomId());
|
||||
call = createNewMatrixCall(client, event.getRoomId());
|
||||
if (call) {
|
||||
call.callId = content.call_id;
|
||||
call._initWithHangup(event);
|
||||
@@ -4997,11 +4992,6 @@ MatrixClient.prototype.generateClientSecret = function() {
|
||||
return randomString(32);
|
||||
};
|
||||
|
||||
/** */
|
||||
module.exports.MatrixClient = MatrixClient;
|
||||
/** */
|
||||
module.exports.CRYPTO_ENABLED = CRYPTO_ENABLED;
|
||||
|
||||
// MatrixClient Event JSDocs
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user