Stitch in forwarded logging.

This commit is contained in:
Half-Shot
2026-01-22 09:20:33 +00:00
parent 3eb88ec4a8
commit 8a62882e4f
5 changed files with 50 additions and 12 deletions

View File

@@ -105,7 +105,7 @@
"lodash-es": "^4.17.21",
"loglevel": "^1.9.1",
"matrix-js-sdk": "matrix-org/matrix-js-sdk#4a75d2c92f1ac7476a6d398057b91c65054f1b80",
"matrix-widget-api": "^1.14.0",
"matrix-widget-api": "matrix-org/matrix-widget-api#c227453ab63d82176bb567dd6bb205334b3ce75c",
"node-stdlib-browser": "^1.3.1",
"normalize.css": "^8.0.1",
"observable-hooks": "^4.2.3",

View File

@@ -246,6 +246,11 @@ export interface UrlConfiguration {
noiseSuppression?: boolean;
callIntent?: RTCCallIntent;
/**
* Has the parent requested we log to it?
*/
widgetLogging?: boolean;
}
// If you need to add a new flag to this interface, prefer a name that describes
@@ -372,6 +377,8 @@ export const computeUrlParams = (search = "", hash = ""): UrlParams => {
const widgetId = parser.getParam("widgetId");
const parentUrl = parser.getParam("parentUrl");
const isWidget = !!widgetId && !!parentUrl;
const widgetLogging =
isWidget && parser.getFlagParam("org.matrix.mscXXXX.log_forwarding");
/**
* The user's intent with respect to the call.
@@ -403,6 +410,7 @@ export const computeUrlParams = (search = "", hash = ""): UrlParams => {
sendNotificationType: "notification",
autoLeaveWhenOthersLeft: false,
waitForCallPickup: false,
widgetLogging,
};
switch (intent) {
case UserIntent.StartNewCall:

View File

@@ -27,10 +27,10 @@ Please see LICENSE in the repository root for full details.
// actually timestamps. We then purge the remaining logs. We also do this
// purge on startup to prevent logs from accumulating.
import EventEmitter from "events";
import { throttle } from "lodash-es";
import { type Logger, logger } from "matrix-js-sdk/lib/logger";
import { secureRandomString } from "matrix-js-sdk/lib/randomstring";
import { TypedEventEmitter } from "matrix-js-sdk/lib/models/typed-event-emitter";
import { type LoggingMethod } from "loglevel";
import type loglevel from "loglevel";
@@ -46,7 +46,9 @@ const MAX_FLUSH_INTERVAL_MS = 2 * 1000;
// only descend this far into nested object trees
const DEPTH_LIMIT = 3;
enum ConsoleLoggerEvent {
type LogArg = Error | DOMException | object | string | undefined;
export enum ConsoleLoggerEvent {
Log = "log",
}
@@ -58,13 +60,17 @@ interface LogEntry {
index?: number;
}
class ConsoleLogger extends EventEmitter {
interface ConsoleLoggerEventsMap {
[ConsoleLoggerEvent.Log]: (level: string, args: LogArg[]) => void;
}
class ConsoleLogger extends TypedEventEmitter<
ConsoleLoggerEvent,
ConsoleLoggerEventsMap
> {
private logs = "";
public log = (
level: LogLevel,
...args: (Error | DOMException | object | string | undefined)[]
): void => {
public log = (level: LogLevel, ...args: LogArg[]): void => {
// We don't know what locale the user may be running so use ISO strings
const ts = new Date().toISOString();
@@ -94,7 +100,7 @@ class ConsoleLogger extends EventEmitter {
// http://jsperf.com/concat-vs-plus-vs-join
this.logs += line;
this.emit(ConsoleLoggerEvent.Log);
this.emit(ConsoleLoggerEvent.Log, level.toString(), args);
};
/**

View File

@@ -19,6 +19,7 @@ import { LazyEventEmitter } from "./LazyEventEmitter";
import { getUrlParams } from "./UrlParams";
import { Config } from "./config/Config";
import { ElementCallReactionEventType } from "./reactions";
import { ConsoleLoggerEvent } from "./settings/rageshake";
// Subset of the actions in element-web
export enum ElementWidgetActions {
@@ -62,8 +63,15 @@ export const widget = ((): WidgetHelpers | null => {
try {
const { widgetId, parentUrl } = getUrlParams();
const { roomId, userId, deviceId, baseUrl, e2eEnabled, allowIceFallback } =
getUrlParams();
const {
roomId,
userId,
deviceId,
baseUrl,
e2eEnabled,
allowIceFallback,
widgetLogging,
} = getUrlParams();
if (!roomId) throw new Error("Room ID must be supplied");
if (!userId) throw new Error("User ID must be supplied");
if (!deviceId) throw new Error("Device ID must be supplied");
@@ -72,6 +80,12 @@ export const widget = ((): WidgetHelpers | null => {
const parentOrigin = new URL(parentUrl).origin;
logger.info("Widget API is available");
const api = new WidgetApi(widgetId, parentOrigin);
if (widgetLogging) {
// eslint-disable-next-line camelcase
mx_rage_logger.on(ConsoleLoggerEvent.Log, (level, args) => {
api.forwardLogLine(level, args);
});
}
api.requestCapability(MatrixCapabilities.AlwaysOnScreen);
// Set up the lazy action emitter, but only for select actions that we

View File

@@ -8365,7 +8365,7 @@ __metadata:
lodash-es: "npm:^4.17.21"
loglevel: "npm:^1.9.1"
matrix-js-sdk: "matrix-org/matrix-js-sdk#4a75d2c92f1ac7476a6d398057b91c65054f1b80"
matrix-widget-api: "npm:^1.14.0"
matrix-widget-api: "matrix-org/matrix-widget-api#c227453ab63d82176bb567dd6bb205334b3ce75c"
node-stdlib-browser: "npm:^1.3.1"
normalize.css: "npm:^8.0.1"
observable-hooks: "npm:^4.2.3"
@@ -11474,6 +11474,16 @@ __metadata:
languageName: node
linkType: hard
"matrix-widget-api@matrix-org/matrix-widget-api#c227453ab63d82176bb567dd6bb205334b3ce75c":
version: 1.16.1
resolution: "matrix-widget-api@https://github.com/matrix-org/matrix-widget-api.git#commit=c227453ab63d82176bb567dd6bb205334b3ce75c"
dependencies:
"@types/events": "npm:^3.0.0"
events: "npm:^3.2.0"
checksum: 10c0/71fcd9b9527ab836e799f2ebc330fa1603e2fbbea5e6ff968d4b6300cfd0aac5cc03097c9f9b24c1e9286cfd170149c8aa0dff9bb78f0193357229057ac4b72e
languageName: node
linkType: hard
"matrix-widget-api@npm:^1.14.0":
version: 1.15.0
resolution: "matrix-widget-api@npm:1.15.0"