2023-09-22 18:05:13 -04:00
|
|
|
/*
|
2024-09-06 10:22:13 +02:00
|
|
|
Copyright 2023, 2024 New Vector Ltd.
|
2023-09-22 18:05:13 -04:00
|
|
|
|
2025-02-18 17:59:58 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
2024-09-06 10:22:13 +02:00
|
|
|
Please see LICENSE in the repository root for full details.
|
2023-09-22 18:05:13 -04:00
|
|
|
*/
|
|
|
|
|
|
2024-12-11 09:27:55 +00:00
|
|
|
import { type Span } from "@opentelemetry/api";
|
2023-06-07 16:40:47 +02:00
|
|
|
import {
|
2024-12-11 09:27:55 +00:00
|
|
|
type TrackStats,
|
|
|
|
|
type TransceiverStats,
|
2025-03-13 16:58:14 +01:00
|
|
|
} from "matrix-js-sdk/lib/webrtc/stats/statsReport";
|
2023-06-07 16:40:47 +02:00
|
|
|
|
2024-12-11 09:27:55 +00:00
|
|
|
import { type ElementCallOpenTelemetry } from "./otel";
|
2023-06-07 16:40:47 +02:00
|
|
|
import { OTelCallAbstractMediaStreamSpan } from "./OTelCallAbstractMediaStreamSpan";
|
|
|
|
|
|
|
|
|
|
export class OTelCallTransceiverMediaStreamSpan extends OTelCallAbstractMediaStreamSpan {
|
|
|
|
|
private readonly prev: {
|
|
|
|
|
direction: string;
|
|
|
|
|
currentDirection: string;
|
|
|
|
|
};
|
|
|
|
|
|
2023-09-22 18:05:13 -04:00
|
|
|
public constructor(
|
|
|
|
|
protected readonly oTel: ElementCallOpenTelemetry,
|
|
|
|
|
protected readonly callSpan: Span,
|
2023-10-11 10:42:04 -04:00
|
|
|
stats: TransceiverStats,
|
2023-06-07 16:40:47 +02:00
|
|
|
) {
|
|
|
|
|
super(oTel, callSpan, `matrix.call.transceiver.${stats.mid}`);
|
|
|
|
|
this.span.setAttribute("transceiver.mid", stats.mid);
|
|
|
|
|
|
|
|
|
|
this.prev = {
|
|
|
|
|
direction: stats.direction,
|
|
|
|
|
currentDirection: stats.currentDirection,
|
|
|
|
|
};
|
|
|
|
|
this.span.addEvent("matrix.call.transceiver.initState", this.prev);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public update(stats: TransceiverStats): void {
|
|
|
|
|
if (this.prev.currentDirection !== stats.currentDirection) {
|
|
|
|
|
this.span.addEvent("matrix.call.transceiver.currentDirection", {
|
|
|
|
|
currentDirection: stats.currentDirection,
|
|
|
|
|
});
|
|
|
|
|
this.prev.currentDirection = stats.currentDirection;
|
|
|
|
|
}
|
|
|
|
|
if (this.prev.direction !== stats.direction) {
|
|
|
|
|
this.span.addEvent("matrix.call.transceiver.direction", {
|
|
|
|
|
direction: stats.direction,
|
|
|
|
|
});
|
|
|
|
|
this.prev.direction = stats.direction;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const trackStats: TrackStats[] = [];
|
|
|
|
|
if (stats.sender) {
|
|
|
|
|
trackStats.push(stats.sender);
|
|
|
|
|
}
|
|
|
|
|
if (stats.receiver) {
|
|
|
|
|
trackStats.push(stats.receiver);
|
|
|
|
|
}
|
|
|
|
|
this.upsertTrackSpans(trackStats);
|
|
|
|
|
}
|
|
|
|
|
}
|