From 70de481fef6a6b700d2fbd14251d8f73a74f59ea Mon Sep 17 00:00:00 2001 From: pabloFuente Date: Thu, 5 Nov 2020 23:50:55 +0100 Subject: [PATCH] openvidu-testapp: rollback event circular dependency --- .../test-sessions/test-sessions.component.ts | 38 ++++++++++++------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/openvidu-testapp/src/app/components/test-sessions/test-sessions.component.ts b/openvidu-testapp/src/app/components/test-sessions/test-sessions.component.ts index 4bff8df3..bdb486ed 100644 --- a/openvidu-testapp/src/app/components/test-sessions/test-sessions.component.ts +++ b/openvidu-testapp/src/app/components/test-sessions/test-sessions.component.ts @@ -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 += ('
' + JSON.stringify(newEvent, getCircularReplacer())); + (window as any).myEvents += ('
' + 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; + } + }); + } + }