Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let leave requests outlive the window #2815

Merged
merged 2 commits into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions spec/unit/webrtc/groupCall.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,32 @@ describe('Group Call', function() {
],
}),
FAKE_USER_ID_1,
{ keepAlive: false },
);
} finally {
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,
{ keepAlive: true }, // Request should outlive the window
);
});

it("starts with mic unmuted in regular calls", async () => {
try {
await groupCall.create();
Expand Down
5 changes: 4 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import {
FileType,
UploadResponse,
HTTPError,
IRequestOpts,
} from "./http-api";
import {
Crypto,
Expand Down Expand Up @@ -7517,6 +7518,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* @param {string} eventType
* @param {Object} content
* @param {string} stateKey
* @param {IRequestOpts} opts Options for the request function.
* @return {Promise} Resolves: TODO
* @return {module:http-api.MatrixError} Rejects: with an error response.
*/
Expand All @@ -7525,6 +7527,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
eventType: string,
content: any,
stateKey = "",
opts: IRequestOpts = {},
): Promise<ISendEventResponse> {
const pathParams = {
$roomId: roomId,
Expand All @@ -7535,7 +7538,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
if (stateKey !== undefined) {
path = utils.encodeUri(path + "/$stateKey", pathParams);
}
return this.http.authedRequest(Method.Put, path, undefined, content);
return this.http.authedRequest(Method.Put, path, undefined, content, opts);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/http-api/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export class FetchHttpApi<O extends IHttpOpts> {
method: Method,
url: URL | string,
body?: Body,
opts: Pick<IRequestOpts, "headers" | "json" | "localTimeoutMs" | "abortSignal"> = {},
opts: Pick<IRequestOpts, "headers" | "json" | "localTimeoutMs" | "keepAlive" | "abortSignal"> = {},
): Promise<ResponseType<T, O>> {
const headers = Object.assign({}, opts.headers || {});
const json = opts.json ?? true;
Expand All @@ -252,6 +252,7 @@ export class FetchHttpApi<O extends IHttpOpts> {
}

const timeout = opts.localTimeoutMs ?? this.opts.localTimeoutMs;
const keepAlive = opts.keepAlive ?? false;
const signals = [
this.abortController.signal,
];
Expand Down Expand Up @@ -284,6 +285,7 @@ export class FetchHttpApi<O extends IHttpOpts> {
referrerPolicy: "no-referrer",
cache: "no-cache",
credentials: "omit", // we send credentials via headers
keepalive: keepAlive,
});
} catch (e) {
if ((<Error>e).name === "AbortError") {
Expand Down
1 change: 1 addition & 0 deletions src/http-api/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface IRequestOpts {
headers?: Record<string, string>;
abortSignal?: AbortSignal;
localTimeoutMs?: number;
keepAlive?: boolean; // defaults to false
json?: boolean; // defaults to true

// Set to true to prevent the request function from emitting a Session.logged_out event.
Expand Down
11 changes: 8 additions & 3 deletions src/webrtc/groupCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -726,10 +726,13 @@ export class GroupCall extends TypedEventEmitter<
private async removeMemberStateEvent(): Promise<ISendEventResponse> {
if (this.resendMemberStateTimer !== null) clearInterval(this.resendMemberStateTimer);
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 memberState = this.getMemberStateEvents(localUserId)?.getContent<IGroupCallRoomMemberState>();
Expand Down Expand Up @@ -758,7 +761,9 @@ export class GroupCall extends TypedEventEmitter<
"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) => {
Expand Down