Skip to content

Commit

Permalink
comments + make logic simpler to follow.
Browse files Browse the repository at this point in the history
  • Loading branch information
toger5 committed Jun 13, 2024
1 parent 57a8f32 commit 035f222
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/matrixrtc/MatrixRTCSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export enum MatrixRTCSessionEvent {
MembershipsChanged = "memberships_changed",
// We joined or left the session: our own local idea of whether we are joined,
// separate from MembershipsChanged, ie. independent of whether our member event
// has succesfully gone through.
// has successfully gone through.
JoinStateChanged = "join_state_changed",
// The key used to encrypt media has changed
EncryptionKeyChanged = "encryption_key_changed",
Expand Down Expand Up @@ -569,6 +569,7 @@ export class MatrixRTCSession extends TypedEventEmitter<MatrixRTCSessionEvent, M
};

public onMembershipUpdate = (): void => {
// This also gets called from the session manager on every relevant call.member event.
const oldMemberships = this.memberships;
this.memberships = MatrixRTCSession.callMembershipsForRoom(this.room);

Expand Down
14 changes: 10 additions & 4 deletions src/matrixrtc/MatrixRTCSessionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class MatrixRTCSessionManager extends TypedEventEmitter<MatrixRTCSessionM

public start(): void {
// We shouldn't need to null-check here, but matrix-client.spec.ts mocks getRooms
// returing nothing, and breaks tests if you change it to return an empty array :'(
// returning nothing, and breaks tests if you change it to return an empty array :'(
for (const room of this.client.getRooms() ?? []) {
const session = MatrixRTCSession.roomSessionForRoom(this.client, room);
if (session.memberships.length > 0) {
Expand Down Expand Up @@ -134,15 +134,21 @@ export class MatrixRTCSessionManager extends TypedEventEmitter<MatrixRTCSessionM
const isNewSession = !this.roomSessions.has(room.roomId);
const sess = this.getRoomSession(room);

const wasActiveAndKnown = sess.memberships.length > 0 && !isNewSession;
const wasActive = sess.memberships.length > 0;

sess.onMembershipUpdate();

const nowActive = sess.memberships.length > 0;

if (wasActiveAndKnown && !nowActive) {
const sessionStarted = !wasActive && nowActive;
// We do not call session Ended if the client just discovered it.
const sessionEnded = wasActive && !nowActive && !isNewSession;

if (sessionEnded) {
this.emit(MatrixRTCSessionManagerEvents.SessionEnded, room.roomId, this.roomSessions.get(room.roomId)!);
} else if (!wasActiveAndKnown && nowActive) {
}

if (sessionStarted) {
this.emit(MatrixRTCSessionManagerEvents.SessionStarted, room.roomId, this.roomSessions.get(room.roomId)!);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/models/event-timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export class EventTimeline {
/**
* Get a pagination token
*
* @param direction - EventTimeline.BACKWARDS to get the pagination
* @param direction - EventTimeline.BACKWARDS to get the pagination
* token for going backwards in time; EventTimeline.FORWARDS to get the
* pagination token for going forwards in time.
*
Expand Down
2 changes: 1 addition & 1 deletion src/models/room-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ export class RoomState extends TypedEventEmitter<EmittedEvents, EventHandlerMap>
}

const lastStateEvent = this.getStateEventMatching(event);
// Safety measurs to not update the room (and emit the update) with older state.
// Safety measure to not update the room (and emit the update) with older state.
// The sync loop really should not send old events but it does very regularly.
// Logging on return in those two conditions results in a large amount of logging. (on startup and when running element)
if ((lastStateEvent?.event.origin_server_ts ?? 0) > (event.event.origin_server_ts ?? 1)) return;
Expand Down

0 comments on commit 035f222

Please sign in to comment.