openvidu-testapp: rollback event circular dependency

pull/553/head
pabloFuente 2020-11-05 23:50:55 +01:00
parent af3ed0ed5e
commit 70de481fef
1 changed files with 25 additions and 13 deletions

View File

@ -38,19 +38,7 @@ export class TestSessionsComponent implements OnInit, OnDestroy {
this.eventsInfoSubscription = this.testFeedService.newLastEvent$.subscribe(
newEvent => {
const getCircularReplacer = () => {
const seen = new WeakSet();
return (key, value) => {
if (typeof value === "object" && value !== null) {
if (seen.has(value)) {
return;
}
seen.add(value);
}
return value;
};
};
(window as any).myEvents += ('<br>' + JSON.stringify(newEvent, getCircularReplacer()));
(window as any).myEvents += ('<br>' + this.stringifyEventNoCircularDependencies(newEvent));
});
}
@ -112,4 +100,28 @@ export class TestSessionsComponent implements OnInit, OnDestroy {
this.loadSubs(subs);
}
stringifyEventNoCircularDependencies(event: Event): string {
const cache = [];
return JSON.stringify(event, function (key, value) {
if (key !== 'ee' && key !== 'openvidu') {
if (typeof value === 'object' && value !== null) {
if (cache.indexOf(value) !== -1) {
// Duplicate reference found
try {
// If this value does not reference a parent
return JSON.parse(JSON.stringify(value));
} catch (error) {
return;
}
}
// Store value in our collection
cache.push(value);
}
return value;
} else {
return;
}
});
}
}