always log device removal in same way and prevent call id overwritten

This commit is contained in:
Bruno Windels 2022-05-06 16:59:26 +02:00
parent 0fdc6b1c3a
commit fc08fc3744
2 changed files with 45 additions and 24 deletions

View File

@ -239,8 +239,7 @@ export class GroupCall extends EventEmitter<{change: never}> {
/** @internal */
updateCallEvent(callContent: Record<string, any>, syncLog: ILogItem) {
syncLog.wrap({l: "update call", t: CALL_LOG_TYPE}, log => {
log.set("id", this.id);
syncLog.wrap({l: "update call", t: CALL_LOG_TYPE, id: this.id}, log => {
this.callContent = callContent;
if (this._state === GroupCallState.Creating) {
this._state = GroupCallState.Created;
@ -274,7 +273,10 @@ export class GroupCall extends EventEmitter<{change: never}> {
} else {
if (member && sessionIdChanged) {
log.set("removedSessionId", member.sessionId);
member.disconnect(false, log);
const disconnectLogItem = member.disconnect(false);
if (disconnectLogItem) {
log.refDetached(disconnectLogItem);
}
this._members.remove(memberKey);
member = undefined;
}
@ -299,9 +301,7 @@ export class GroupCall extends EventEmitter<{change: never}> {
// remove user as member of any calls not present anymore
for (const previousDeviceId of previousDeviceIds) {
if (!newDeviceIds.has(previousDeviceId)) {
log.wrap({l: "remove device member", id: getMemberKey(userId, previousDeviceId)}, log => {
this.removeMemberDevice(userId, previousDeviceId, log);
});
this.removeMemberDevice(userId, previousDeviceId, log);
}
}
if (userId === this.options.ownUserId && !newDeviceIds.has(this.options.ownDeviceId)) {
@ -316,7 +316,8 @@ export class GroupCall extends EventEmitter<{change: never}> {
syncLog.wrap({
l: "remove call member",
t: CALL_LOG_TYPE,
id: this.id
id: this.id,
userId
}, log => {
for (const deviceId of deviceIds) {
this.removeMemberDevice(userId, deviceId, log);
@ -363,7 +364,10 @@ export class GroupCall extends EventEmitter<{change: never}> {
disconnect(log: ILogItem) {
if (this._state === GroupCallState.Joined) {
for (const [,member] of this._members) {
member.disconnect(true, log);
const disconnectLogItem = member.disconnect(true);
if (disconnectLogItem) {
log.refDetached(disconnectLogItem);
}
}
this._state = GroupCallState.Created;
}
@ -375,14 +379,18 @@ export class GroupCall extends EventEmitter<{change: never}> {
/** @internal */
private removeMemberDevice(userId: string, deviceId: string, log: ILogItem) {
const memberKey = getMemberKey(userId, deviceId);
log.set("id", memberKey);
const member = this._members.get(memberKey);
if (member) {
log.set("leave", true);
this._members.remove(memberKey);
member.disconnect(false, log);
}
this.emitChange();
log.wrap({l: "remove device member", id: memberKey}, log => {
const member = this._members.get(memberKey);
if (member) {
log.set("leave", true);
this._members.remove(memberKey);
const disconnectLogItem = member.disconnect(false);
if (disconnectLogItem) {
log.refDetached(disconnectLogItem);
}
}
this.emitChange();
});
}
/** @internal */
@ -459,11 +467,16 @@ export class GroupCall extends EventEmitter<{change: never}> {
}
private connectToMember(member: Member, joinedData: JoinedData, log: ILogItem) {
const logItem = joinedData.membersLogItem.child({l: "member", id: getMemberKey(member.userId, member.deviceId)});
const memberKey = getMemberKey(member.userId, member.deviceId);
const logItem = joinedData.membersLogItem.child({l: "member", id: memberKey});
logItem.set("sessionId", member.sessionId);
log.refDetached(logItem);
// Safari can't send a MediaStream to multiple sources, so clone it
member.connect(joinedData.localMedia.clone(), joinedData.localMuteSettings, logItem);
log.wrap({l: "connect", id: memberKey}, log => {
// Safari can't send a MediaStream to multiple sources, so clone it
const connectItem = member.connect(joinedData.localMedia.clone(), joinedData.localMuteSettings, logItem);
if (connectItem) {
log.refDetached(connectItem);
}
})
}
protected emitChange() {

View File

@ -100,15 +100,18 @@ export class Member {
}
/** @internal */
connect(localMedia: LocalMedia, localMuteSettings: MuteSettings, memberLogItem: ILogItem) {
connect(localMedia: LocalMedia, localMuteSettings: MuteSettings, memberLogItem: ILogItem): ILogItem | undefined {
if (this.connection) {
return;
}
const connection = new MemberConnection(localMedia, localMuteSettings, memberLogItem);
this.connection = connection;
let connectLogItem;
connection.logItem.wrap("connect", async log => {
connectLogItem = log;
await this.callIfNeeded(log);
});
return connectLogItem;
}
private callIfNeeded(log: ILogItem): Promise<void> {
@ -136,13 +139,14 @@ export class Member {
}
/** @internal */
disconnect(hangup: boolean, causeItem: ILogItem) {
disconnect(hangup: boolean): ILogItem | undefined {
const {connection} = this;
if (!connection) {
return;
}
let disconnectLogItem;
connection.logItem.wrap("disconnect", async log => {
log.refDetached(causeItem);
disconnectLogItem = log;
if (hangup) {
connection.peerCall?.hangup(CallErrorCode.UserHangup, log);
} else {
@ -153,6 +157,7 @@ export class Member {
this.connection = undefined;
});
connection.logItem.finish();
return disconnectLogItem;
}
/** @internal */
@ -184,7 +189,10 @@ export class Member {
if (retryCount <= 3) {
await this.callIfNeeded(retryLog);
} else {
this.disconnect(false, retryLog);
const disconnectLogItem = this.disconnect(false);
if (disconnectLogItem) {
retryLog.refDetached(disconnectLogItem);
}
}
});
}