mirror of https://github.com/OpenVidu/openvidu.git
openvidu-testapp: rollback event circular dependency
parent
af3ed0ed5e
commit
70de481fef
|
@ -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;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue