1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-12-17 21:42:17 +03:00

feat(client): allow disabling VoIP support (#5021)

* feat(client): allow disabling VoIP support

* feat(client): allow disabling VoIP support

Signed-off-by: Bahaa Naamneh <b.naamneh@gmail.com>

* add a unit-test for disableVoip option

* fix lint issue

---------

Signed-off-by: Bahaa Naamneh <b.naamneh@gmail.com>
Co-authored-by: Bahaa Naamneh <glimm.no@gmail.com>
This commit is contained in:
pkuzco
2025-10-01 18:52:36 +02:00
committed by GitHub
parent 52bcc2c955
commit d1d9aba745
2 changed files with 68 additions and 4 deletions

View File

@@ -2366,6 +2366,61 @@ describe("MatrixClient", function () {
});
});
describe("disableVoip option", () => {
const baseUrl = "https://alice-server.com";
const userId = "@alice:bar";
const accessToken = "sometoken";
beforeEach(() => {
mocked(supportsMatrixCall).mockReturnValue(true);
});
afterAll(() => {
mocked(supportsMatrixCall).mockReset();
});
it("should not call /voip/turnServer when disableVoip = true", () => {
fetchMock.getOnce(`${baseUrl}/_matrix/client/unstable/voip/turnServer`, 200);
const client = createClient({
baseUrl,
accessToken,
userId,
disableVoip: true,
});
// Only check createCall / supportsVoip, avoid startClient
expect(client.createCall("!roomId:example.com")).toBeNull();
expect(client.supportsVoip?.()).toBe(false);
});
it("should call /voip/turnServer when disableVoip is not set", () => {
fetchMock.getOnce(`${baseUrl}/_matrix/client/unstable/voip/turnServer`, {
uris: ["turn:turn.example.org"],
});
createClient({
baseUrl,
accessToken,
userId,
});
// The call will trigger the request if VoIP is supported
expect(fetchMock.called(`${baseUrl}/_matrix/client/unstable/voip/turnServer`)).toBe(false);
});
it("should return null from createCall when disableVoip = true", () => {
const client = createClient({
baseUrl,
accessToken,
userId,
disableVoip: true,
});
expect(client.createCall("!roomId:example.com")).toBeNull();
});
});
describe("support for ignoring invites", () => {
beforeEach(() => {
// Mockup `getAccountData`/`setAccountData`.

View File

@@ -443,6 +443,12 @@ export interface ICreateClientOpts {
*/
isVoipWithNoMediaAllowed?: boolean;
/**
* Disable VoIP support (prevents fetching TURN servers, etc.)
* Default: false (VoIP enabled)
*/
disableVoip?: boolean;
/**
* If true, group calls will not establish media connectivity and only create the signaling events,
* so that livekit media can be used in the application layer (js-sdk contains no livekit code).
@@ -1220,6 +1226,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
public idBaseUrl?: string;
public baseUrl: string;
public readonly isVoipWithNoMediaAllowed;
public disableVoip: boolean;
public useLivekitForGroupCalls: boolean;
@@ -1346,7 +1353,9 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
});
}
if (supportsMatrixCall()) {
this.disableVoip = opts.disableVoip ?? false;
if (!this.disableVoip && supportsMatrixCall()) {
this.callEventHandler = new CallEventHandler(this);
this.groupCallEventHandler = new GroupCallEventHandler(this);
this.canSupportVoip = true;
@@ -1433,7 +1442,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
}
// periodically poll for turn servers if we support voip
if (this.canSupportVoip) {
if (this.supportsVoip()) {
this.checkTurnServersIntervalID = setInterval(() => {
this.checkTurnServers();
}, TURN_CHECK_INTERVAL);
@@ -1670,7 +1679,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* @returns True if VoIP is supported.
*/
public supportsVoip(): boolean {
return this.canSupportVoip;
return !this.disableVoip && this.canSupportVoip;
}
/**
@@ -5622,7 +5631,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
// XXX: Intended private, used in code.
public async checkTurnServers(): Promise<boolean | undefined> {
if (!this.canSupportVoip) {
if (!this.supportsVoip()) {
return;
}