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

Fix member dispose mutating global member options #1090

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
18 changes: 11 additions & 7 deletions src/matrix/calls/group/Member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import type {ILogItem} from "../../../logging/types";
import type {BaseObservableValue} from "../../../observable/value";
import type {Clock, Timeout} from "../../../platform/web/dom/Clock";

export type MemberUpdateEmitter = (participant: Member, params?: any) => void;

export type Options = Omit<PeerCallOptions, "emitUpdate" | "sendSignallingMessage" | "turnServer"> & {
confId: string,
ownUserId: string,
Expand All @@ -41,7 +43,7 @@ export type Options = Omit<PeerCallOptions, "emitUpdate" | "sendSignallingMessag
sessionId: string,
hsApi: HomeServerApi,
encryptDeviceMessage: (userId: string, deviceId: string, message: SignallingMessage<MGroupCallBase>, log: ILogItem) => Promise<EncryptedMessage | undefined>,
emitUpdate: (participant: Member, params?: any) => void,
emitUpdate: MemberUpdateEmitter,
clock: Clock
}

Expand Down Expand Up @@ -105,8 +107,9 @@ class MemberConnection {
export class Member {
private connection?: MemberConnection;
private expireTimeout?: Timeout;
private emitMemberUpdate: MemberUpdateEmitter;
private errorBoundary = new ErrorBoundary(err => {
this.options.emitUpdate(this, "error");
this.emitMemberUpdate(this, "error");
if (this.connection) {
// in case the error happens in code that does not log,
// log it here to make sure it isn't swallowed
Expand All @@ -120,6 +123,7 @@ export class Member {
private options: Options,
updateMemberLog: ILogItem
) {
this.emitMemberUpdate = this.options.emitUpdate;
this._renewExpireTimeout(updateMemberLog);
}

Expand All @@ -144,7 +148,7 @@ export class Member {
// add 10ms to make sure isExpired returns true
this.expireTimeout = this.options.clock.createTimeout(expiresFromNow + 10);
this.expireTimeout.elapsed().then(
() => { this.options.emitUpdate(this, "isExpired"); },
() => { this.emitMemberUpdate(this, "isExpired"); },
(err) => { /* ignore abort error */ },
);
}
Expand Down Expand Up @@ -285,7 +289,7 @@ export class Member {
updateRoomMember(roomMember: RoomMember) {
this.member = roomMember;
// TODO: this emits an update during the writeSync phase, which we usually try to avoid
this.options.emitUpdate(this);
this.emitMemberUpdate(this);
}

/** @internal */
Expand Down Expand Up @@ -317,7 +321,7 @@ export class Member {
});
}
}
this.options.emitUpdate(this, params);
this.emitMemberUpdate(this, params);
}

/** @internal */
Expand Down Expand Up @@ -466,8 +470,8 @@ export class Member {
this.connection = undefined;
this.expireTimeout?.dispose();
this.expireTimeout = undefined;
// ensure the emitUpdate callback can't be called anymore
this.options.emitUpdate = () => {};
// ensure the emitMemberUpdate callback can't be called anymore
this.emitMemberUpdate = () => {};
}
}

Expand Down