Skip to content

Commit

Permalink
Remove the JS-SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
Half-Shot committed May 18, 2022
1 parent 530de2a commit 5dd1c4f
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 356 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"js-yaml": "^4.0.0",
"matrix-appservice": "^0.10.0",
"matrix-bot-sdk": "^0.6.0-beta.2",
"matrix-js-sdk": "^12.4.1",
"nedb": "^1.8.0",
"nopt": "^5.0.0",
"p-queue": "^6.6.2",
Expand Down
66 changes: 2 additions & 64 deletions src/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,8 @@ import * as util from "util";
import yaml from "js-yaml";
import { Application, Request as ExRequest, Response as ExResponse, NextFunction } from "express";

// eslint-disable-next-line @typescript-eslint/no-var-requires
const MatrixScheduler = require("matrix-js-sdk").MatrixScheduler;

import { AppServiceRegistration, AppService, AppServiceOutput } from "matrix-appservice";
import { BridgeContext } from "./components/bridge-context"
import { ClientFactory } from "./components/client-factory"
import { AppServiceBot } from "./components/app-service-bot"
import { RequestFactory } from "./components/request-factory";
import { Request } from "./components/request";
Expand Down Expand Up @@ -56,7 +52,6 @@ import { EphemeralEvent, PresenceEvent, ReadReceiptEvent, TypingEvent, WeakEvent
import * as BotSDK from "matrix-bot-sdk";
import { ActivityTracker, ActivityTrackerOpts } from "./components/activity-tracker";
import { EncryptedIntent, EncryptedIntentOpts } from "./components/encrypted-intent";
import e = require("express");

const log = logging.get("bridge");

Expand Down Expand Up @@ -155,7 +150,7 @@ export interface BridgeOpts {
disableStores?: boolean;
/**
* The room store instance to use, or the path to the room .db file to load.
* A database will be ClientFactoryEncryptionStorecreated if this is not specified. If `disableStores` is set,
* A database will be created if this is not specified. If `disableStores` is set,
* no database will be created or used.
*/
roomStore?: RoomBridgeStore|string;
Expand Down Expand Up @@ -188,10 +183,6 @@ export interface BridgeOpts {
* for events which were sent by a bridge user. Default: true.
*/
suppressEcho?: boolean;
/**
* The client factory instance to use. If not supplied, one will be created.
*/
clientFactory?: ClientFactory;
/**
* True to enable SUCCESS/FAILED log lines to be sent to onLog. Default: true.
*/
Expand Down Expand Up @@ -344,10 +335,6 @@ interface VettedBridgeOpts {
* for events which were sent by a bridge user. Default: true.
*/
suppressEcho: boolean;
/**
* The client factory instance to use. If not supplied, one will be created.
*/
clientFactory?: ClientFactory;
/**
* True to enable SUCCESS/FAILED log lines to be sent to onLog. Default: true.
*/
Expand Down Expand Up @@ -448,7 +435,6 @@ export class Bridge {
private intentLastAccessedTimeout: NodeJS.Timeout|null = null;
private botIntent?: Intent;
private appServiceBot?: AppServiceBot;
private clientFactory?: ClientFactory;
private metrics?: PrometheusMetrics;
private roomLinkValidator?: RoomLinkValidator;
private roomUpgradeHandler?: RoomUpgradeHandler;
Expand Down Expand Up @@ -635,7 +621,7 @@ export class Bridge {

const asToken = this.registration.getAppServiceToken();
if (!asToken) {
throw Error('No AS token provided, cannot create ClientFactory');
throw Error('No AS token provided in registration config!');
}
const rawReg = this.registration.getOutput();
this.botSdkAS = new BotSDK.Appservice({
Expand Down Expand Up @@ -667,17 +653,6 @@ export class Bridge {
this.metrics.registerMatrixSdkMetrics(this.botSdkAS);
}

this.clientFactory = this.opts.clientFactory || new ClientFactory({
url: this.opts.homeserverUrl,
token: asToken,
appServiceUserId: this.botUserId,
clientSchedulerBuilder: function() {
return new MatrixScheduler(retryAlgorithm, queueAlgorithm);
},
});
this.clientFactory.setLogFunction((text, isErr) => {
this.onLog(text, isErr || false);
});
await this.checkHomeserverSupport();
this.appServiceBot = new AppServiceBot(
this.botSdkAS.botClient, this.botUserId, this.registration, this.membershipCache,
Expand Down Expand Up @@ -720,17 +695,6 @@ export class Bridge {
const botIntentOpts: IntentOpts = {
registered: true,
backingStore: this.intentBackingStore,
getJsSdkClient: () => {
if (!this.clientFactory) {
throw Error('clientFactory not ready yet');
}
return this.clientFactory.getClientAs(
undefined,
undefined,
this.opts.bridgeEncryption?.homeserverUrl,
!!this.opts.bridgeEncryption,
)
},
...this.opts.intentOptions?.bot, // copy across opts, if defined
};
this.botIntent = this.opts.onIntentCreate(this.botUserId, botIntentOpts);
Expand Down Expand Up @@ -1072,17 +1036,6 @@ export class Bridge {
return this.requestFactory;
}

/**
* Retrieve the matrix client factory used when sending matrix requests.
* @deprecated The client factory is deprecated.
*/
public getClientFactory(): ClientFactory {
if (!this.clientFactory) {
throw Error('Bridge is not ready');
}
return this.clientFactory;
}

/**
* Get the AS bot instance.
*/
Expand Down Expand Up @@ -1153,21 +1106,6 @@ export class Bridge {

const clientIntentOpts: IntentOpts = {
backingStore: this.intentBackingStore,
/**
* We still support creating a JS SDK client if the bridge really needs it,
* but for memory/performance reasons we only create them on demand.
*/
getJsSdkClient: () => {
if (!this.clientFactory) {
throw Error('clientFactory not ready yet');
}
return this.clientFactory.getClientAs(
userId,
request,
this.opts.bridgeEncryption?.homeserverUrl,
!!this.opts.bridgeEncryption,
)
},
...this.opts.intentOptions?.clients,
onEventSent: () => userId && this.opts.controller.userActivityTracker?.updateUserActivity(userId),
};
Expand Down
231 changes: 0 additions & 231 deletions src/components/client-factory.ts

This file was deleted.

Loading

0 comments on commit 5dd1c4f

Please sign in to comment.