1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-08-05 00:42:10 +03:00

Let leave requests outlive the window

This commit is contained in:
Robin Townsend
2022-10-26 17:50:20 -04:00
parent 13c751c060
commit dbdaa1540a
5 changed files with 35 additions and 5 deletions

View File

@@ -212,12 +212,32 @@ describe('Group Call', function() {
], ],
}), }),
FAKE_USER_ID_1, FAKE_USER_ID_1,
false,
); );
} finally { } finally {
groupCall.leave(); groupCall.leave();
} }
}); });
it("sends member state event to room on leave", async () => {
room.currentState.members[FAKE_USER_ID_1] = {
userId: FAKE_USER_ID_1,
} as unknown as RoomMember;
await groupCall.create();
await groupCall.enter();
mockSendState.mockClear();
groupCall.leave();
expect(mockSendState).toHaveBeenCalledWith(
FAKE_ROOM_ID,
EventType.GroupCallMemberPrefix,
expect.objectContaining({ "m.calls": [] }),
FAKE_USER_ID_1,
true, // Request should outlive the window
);
});
it("starts with mic unmuted in regular calls", async () => { it("starts with mic unmuted in regular calls", async () => {
try { try {
await groupCall.create(); await groupCall.create();

View File

@@ -7517,6 +7517,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* @param {string} eventType * @param {string} eventType
* @param {Object} content * @param {Object} content
* @param {string} stateKey * @param {string} stateKey
* @param {boolean} keepAlive Whether the request should outlive the window.
* @return {Promise} Resolves: TODO * @return {Promise} Resolves: TODO
* @return {module:http-api.MatrixError} Rejects: with an error response. * @return {module:http-api.MatrixError} Rejects: with an error response.
*/ */
@@ -7525,6 +7526,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
eventType: string, eventType: string,
content: any, content: any,
stateKey = "", stateKey = "",
keepAlive = false,
): Promise<ISendEventResponse> { ): Promise<ISendEventResponse> {
const pathParams = { const pathParams = {
$roomId: roomId, $roomId: roomId,
@@ -7535,7 +7537,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
if (stateKey !== undefined) { if (stateKey !== undefined) {
path = utils.encodeUri(path + "/$stateKey", pathParams); path = utils.encodeUri(path + "/$stateKey", pathParams);
} }
return this.http.authedRequest(Method.Put, path, undefined, content); return this.http.authedRequest(Method.Put, path, undefined, content, { keepAlive });
} }
/** /**

View File

@@ -234,7 +234,7 @@ export class FetchHttpApi<O extends IHttpOpts> {
method: Method, method: Method,
url: URL | string, url: URL | string,
body?: Body, body?: Body,
opts: Pick<IRequestOpts, "headers" | "json" | "localTimeoutMs" | "abortSignal"> = {}, opts: Pick<IRequestOpts, "headers" | "json" | "localTimeoutMs" | "keepAlive" | "abortSignal"> = {},
): Promise<ResponseType<T, O>> { ): Promise<ResponseType<T, O>> {
const headers = Object.assign({}, opts.headers || {}); const headers = Object.assign({}, opts.headers || {});
const json = opts.json ?? true; const json = opts.json ?? true;
@@ -252,6 +252,7 @@ export class FetchHttpApi<O extends IHttpOpts> {
} }
const timeout = opts.localTimeoutMs ?? this.opts.localTimeoutMs; const timeout = opts.localTimeoutMs ?? this.opts.localTimeoutMs;
const keepAlive = opts.keepAlive ?? false;
const signals = [ const signals = [
this.abortController.signal, this.abortController.signal,
]; ];
@@ -284,6 +285,7 @@ export class FetchHttpApi<O extends IHttpOpts> {
referrerPolicy: "no-referrer", referrerPolicy: "no-referrer",
cache: "no-cache", cache: "no-cache",
credentials: "omit", // we send credentials via headers credentials: "omit", // we send credentials via headers
keepalive: keepAlive,
}); });
} catch (e) { } catch (e) {
if ((<Error>e).name === "AbortError") { if ((<Error>e).name === "AbortError") {

View File

@@ -38,6 +38,7 @@ export interface IRequestOpts {
headers?: Record<string, string>; headers?: Record<string, string>;
abortSignal?: AbortSignal; abortSignal?: AbortSignal;
localTimeoutMs?: number; localTimeoutMs?: number;
keepAlive?: boolean; // defaults to false
json?: boolean; // defaults to true json?: boolean; // defaults to true
// Set to true to prevent the request function from emitting a Session.logged_out event. // Set to true to prevent the request function from emitting a Session.logged_out event.

View File

@@ -726,10 +726,13 @@ export class GroupCall extends TypedEventEmitter<
private async removeMemberStateEvent(): Promise<ISendEventResponse> { private async removeMemberStateEvent(): Promise<ISendEventResponse> {
if (this.resendMemberStateTimer !== null) clearInterval(this.resendMemberStateTimer); if (this.resendMemberStateTimer !== null) clearInterval(this.resendMemberStateTimer);
this.resendMemberStateTimer = null; this.resendMemberStateTimer = null;
return await this.updateMemberCallState(undefined); return await this.updateMemberCallState(undefined, true);
} }
private async updateMemberCallState(memberCallState?: IGroupCallRoomMemberCallState): Promise<ISendEventResponse> { private async updateMemberCallState(
memberCallState?: IGroupCallRoomMemberCallState,
keepAlive = false,
): Promise<ISendEventResponse> {
const localUserId = this.client.getUserId()!; const localUserId = this.client.getUserId()!;
const memberState = this.getMemberStateEvents(localUserId)?.getContent<IGroupCallRoomMemberState>(); const memberState = this.getMemberStateEvents(localUserId)?.getContent<IGroupCallRoomMemberState>();
@@ -758,7 +761,9 @@ export class GroupCall extends TypedEventEmitter<
"m.expires_ts": Date.now() + CALL_MEMBER_STATE_TIMEOUT, "m.expires_ts": Date.now() + CALL_MEMBER_STATE_TIMEOUT,
}; };
return this.client.sendStateEvent(this.room.roomId, EventType.GroupCallMemberPrefix, content, localUserId); return this.client.sendStateEvent(
this.room.roomId, EventType.GroupCallMemberPrefix, content, localUserId, keepAlive,
);
} }
public onMemberStateChanged = async (event: MatrixEvent) => { public onMemberStateChanged = async (event: MatrixEvent) => {