Error:- Window is not defined angular universal 8.2

I am using angular 8.2 with server-side rendering,
I am getting the following error on importing the openvidu-browser on run time.

> ptm-ng@0.0.0 serve:ssr /Users/userName/myApplication/projects/my-app
> node dist/server

/Users/userName/myApplication/projects/my-app/dist/server/main.js:71890
        this.logger = window.console;
                      ^

ReferenceError: window is not defined
    at new OpenViduLogger (/Users/userName/myApplication/projects/my-app/dist/server/main.js:71890:23)
    at Function.9m68.OpenViduLogger.getInstance (/Users/userName/myApplication/projects/my-app/dist/server/main.js:71896:39)
    at Object.tInm (/Users/userName/myApplication/projects/my-app/dist/server/main.js:246209:46)
    at __webpack_require__ (/Users/userName/myApplication/projects/my-app/dist/server/main.js:26:30)
    at Object.PPcv (/Users/userName/myApplication/projects/my-app/dist/server/main.js:151642:23)
    at __webpack_require__ (/Users/userName/myApplication/projects/my-app/dist/server/main.js:26:30)
    at Object.PZzU (/Users/userName/myApplication/projects/my-app/dist/server/main.js:152804:18)

This is how I tried to fix the issue but to no relief.

  joinSession() {
    if(isPlatformBrowser(this.plateformId) && window && window !=null && window!=undefined){
 import('openvidu-browser').then((OpenViduModule)=>{
    this.OV = new OpenViduModule.OpenVidu();
    this.session = this.OV.initSession();
    /*------ other code required for joining the session-------*/
)};
}

}

Iā€™m sorry but I think OpenVidu Angular lib is not SSR friendly.

Thanks for your reply, Although I have found a workaround for that.
which is (might help someone.)

import('openvidu-browser').then((OpenViduModule) => {
  this.OV = new OpenVidModule.OpenVidu();
});
2 Likes

Thank you for sharing