You've already forked matrix-js-sdk
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:
@@ -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", () => {
|
describe("support for ignoring invites", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
// Mockup `getAccountData`/`setAccountData`.
|
// Mockup `getAccountData`/`setAccountData`.
|
||||||
|
|||||||
@@ -443,6 +443,12 @@ export interface ICreateClientOpts {
|
|||||||
*/
|
*/
|
||||||
isVoipWithNoMediaAllowed?: boolean;
|
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,
|
* 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).
|
* 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 idBaseUrl?: string;
|
||||||
public baseUrl: string;
|
public baseUrl: string;
|
||||||
public readonly isVoipWithNoMediaAllowed;
|
public readonly isVoipWithNoMediaAllowed;
|
||||||
|
public disableVoip: boolean;
|
||||||
|
|
||||||
public useLivekitForGroupCalls: 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.callEventHandler = new CallEventHandler(this);
|
||||||
this.groupCallEventHandler = new GroupCallEventHandler(this);
|
this.groupCallEventHandler = new GroupCallEventHandler(this);
|
||||||
this.canSupportVoip = true;
|
this.canSupportVoip = true;
|
||||||
@@ -1433,7 +1442,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
|||||||
}
|
}
|
||||||
|
|
||||||
// periodically poll for turn servers if we support voip
|
// periodically poll for turn servers if we support voip
|
||||||
if (this.canSupportVoip) {
|
if (this.supportsVoip()) {
|
||||||
this.checkTurnServersIntervalID = setInterval(() => {
|
this.checkTurnServersIntervalID = setInterval(() => {
|
||||||
this.checkTurnServers();
|
this.checkTurnServers();
|
||||||
}, TURN_CHECK_INTERVAL);
|
}, TURN_CHECK_INTERVAL);
|
||||||
@@ -1670,7 +1679,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
|||||||
* @returns True if VoIP is supported.
|
* @returns True if VoIP is supported.
|
||||||
*/
|
*/
|
||||||
public supportsVoip(): boolean {
|
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.
|
// XXX: Intended private, used in code.
|
||||||
public async checkTurnServers(): Promise<boolean | undefined> {
|
public async checkTurnServers(): Promise<boolean | undefined> {
|
||||||
if (!this.canSupportVoip) {
|
if (!this.supportsVoip()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user