Skip to content

Commit 2218ec4

Browse files
authored
Add _unstable_getRTCTransports to client. (#5104)
1 parent 319a830 commit 2218ec4

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

spec/unit/matrix-client.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ import { mockOpenIdConfiguration } from "../test-utils/oidc.ts";
8484
import { type CryptoBackend } from "../../src/common-crypto/CryptoBackend";
8585
import { SyncResponder } from "../test-utils/SyncResponder.ts";
8686
import { mockInitialApiRequests } from "../test-utils/mockEndpoints.ts";
87+
import { type Transport } from "src/matrixrtc/index.ts";
8788

8889
jest.useFakeTimers();
8990

@@ -3935,4 +3936,23 @@ describe("MatrixClient", function () {
39353936
expect(lookupResult[0]).toEqual({ address: "[email protected]", mxid: "@bob:homeserver.dummy" });
39363937
});
39373938
});
3939+
3940+
describe("_unstable_getRTCTransports", () => {
3941+
it("makes a well-formed request", async () => {
3942+
httpLookups = [
3943+
{
3944+
method: "GET",
3945+
path: `/rtc/transports`,
3946+
data: { rtc_transports: [{ type: "livekit", extra_field: "foobar" }] satisfies Transport[] },
3947+
prefix: "/_matrix/client/unstable/org.matrix.msc4143",
3948+
},
3949+
];
3950+
expect(await client._unstable_getRTCTransports()).toEqual([
3951+
{
3952+
type: "livekit",
3953+
extra_field: "foobar",
3954+
},
3955+
]);
3956+
});
3957+
});
39383958
});

src/client.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ import {
246246
} from "./oidc/index.ts";
247247
import { type EmptyObject } from "./@types/common.ts";
248248
import { UnsupportedDelayedEventsEndpointError, UnsupportedStickyEventsEndpointError } from "./errors.ts";
249+
import { type Transport } from "./matrixrtc/index.ts";
249250

250251
export type Store = IStore;
251252

@@ -6080,6 +6081,23 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
60806081
return rooms;
60816082
}
60826083

6084+
/**
6085+
* Returns a set of configured RTC transports supported by the homeserver.
6086+
* Requires homeserver support for MSC4143.
6087+
* @throws A M_NOT_FOUND error if not supported by the homeserver.
6088+
*/
6089+
// eslint-disable-next-line @typescript-eslint/naming-convention
6090+
public async _unstable_getRTCTransports(): Promise<Transport[]> {
6091+
// There is no /versions endpoint to check for support, so we just have to attempt a request.
6092+
return (
6093+
await this.http.authedRequest<{
6094+
rtc_transports: Transport[];
6095+
}>(Method.Get, "/rtc/transports", undefined, undefined, {
6096+
prefix: `${ClientPrefix.Unstable}/org.matrix.msc4143`,
6097+
})
6098+
).rtc_transports;
6099+
}
6100+
60836101
/**
60846102
* Get the API versions supported by the server, along with any
60856103
* unstable APIs it supports

0 commit comments

Comments
 (0)