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 daae9ca
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/matrixrtc/MatrixRTCSession.ts
Original file line number Diff line number Diff line change
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

0 comments on commit daae9ca

Please sign in to comment.