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

View file

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