openvidu-node-client: fix circular JSON stringify of Session objects

pull/375/head
pabloFuente 2019-05-31 14:38:20 +02:00
parent 5760f4e7ef
commit 3856cdded7
1 changed files with 13 additions and 2 deletions

View File

@ -200,7 +200,7 @@ export class Session {
*/
public fetch(): Promise<boolean> {
return new Promise<boolean>((resolve, reject) => {
const beforeJSON: string = JSON.stringify(this);
const beforeJSON: string = JSON.stringify(this, this.removeCircularOpenViduReference);
axios.get(
'https://' + this.ov.hostname + ':' + this.ov.port + OpenVidu.API_SESSIONS + '/' + this.sessionId,
{
@ -214,7 +214,7 @@ export class Session {
if (res.status === 200) {
// SUCCESS response from openvidu-server
this.resetSessionWithJson(res.data);
const afterJSON: string = JSON.stringify(this);
const afterJSON: string = JSON.stringify(this, this.removeCircularOpenViduReference);
const hasChanged: boolean = !(beforeJSON === afterJSON);
console.log("Session info fetched for session '" + this.sessionId + "'. Any change: " + hasChanged);
resolve(hasChanged);
@ -528,4 +528,15 @@ export class Session {
}
}
/**
* @hidden
*/
private removeCircularOpenViduReference(key: string, value: any) {
if (key === 'ov' && value instanceof OpenVidu) {
return;
} else {
return value;
}
}
}