import { normalizeOptionalAccountId } from "openclaw/plugin-sdk/account-id"; import type { CoreConfig } from "../../types.js"; import type { MatrixClient } from "../sdk.js"; import { LogService } from "../sdk/logger.js"; import { awaitMatrixStartupWithAbort } from "../startup-abort.js"; import { resolveMatrixAuth, resolveMatrixAuthContext } from "./config.js"; import type { MatrixAuth } from "./types.js";
type MatrixCreateClientDeps = {
createMatrixClient: typeofimport("./create-client.js").createMatrixClient;
};
let matrixCreateClientDepsPromise: Promise<MatrixCreateClientDeps> | undefined;
function findSharedClientStateByInstance(client: MatrixClient): SharedMatrixClientState | null { for (const state of sharedClientStates.values()) { if (state.client === client) { return state;
}
} returnnull;
}
function deleteSharedClientState(state: SharedMatrixClientState): void {
sharedClientStates.delete(state.key);
sharedClientPromises.delete(state.key);
}
// Initialize crypto if enabled if (params.encryption && !params.state.cryptoReady) { try { const joinedRooms = await client.getJoinedRooms(); if (client.crypto) {
await client.crypto.prepare(joinedRooms);
params.state.cryptoReady = true;
}
} catch (err) {
LogService.warn("MatrixClientLite", "Failed to prepare crypto:", err);
}
}
await client.start({ abortSignal: params.abortSignal });
params.state.started = true;
})(); // Keep the shared startup lock until the underlying start fully settles, even // if one waiter aborts early while another caller still owns the startup. const guardedStart = startPromise.finally(() => { if (params.state.startPromise === guardedStart) {
params.state.startPromise = null;
}
});
params.state.startPromise = guardedStart;
export function stopSharedClient(): void { for (const state of sharedClientStates.values()) {
state.client.stop();
}
sharedClientStates.clear();
sharedClientPromises.clear();
}
export function stopSharedClientForAccount(auth: MatrixAuth): void { const key = buildSharedClientKey(auth); const state = sharedClientStates.get(key); if (!state) { return;
}
state.client.stop();
deleteSharedClientState(state);
}
export function removeSharedClientInstance(client: MatrixClient): boolean { const state = findSharedClientStateByInstance(client); if (!state) { returnfalse;
}
deleteSharedClientState(state); returntrue;
}
export function stopSharedClientInstance(client: MatrixClient): void { if (!removeSharedClientInstance(client)) { return;
}
client.stop();
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.