Skip to content
This repository was archived by the owner on Oct 18, 2024. It is now read-only.

Commit 1ff1b5a

Browse files
Merge pull request #764 from SuperViz/ssr-support
2 parents 02da3a3 + 51b3476 commit 1ff1b5a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+466
-463
lines changed

src/components/comments/index.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import ApiService from '../../services/api';
1111
import { IOC } from '../../services/io';
1212
import { Presence3DManager } from '../../services/presence-3d-manager';
1313
import { useGlobalStore } from '../../services/stores';
14-
import { CommentsFloatButton } from '../../web-components';
14+
import type { CommentsFloatButton } from '../../web-components/comments/components/float-button';
1515
import { ComponentNames } from '../types';
1616

1717
import { PinAdapter, CommentsSide, Annotation, PinCoordinates } from './types';

src/components/comments/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Logger } from '../../common/utils';
55
import ApiService from '../../services/api';
66
import config from '../../services/config';
77
import subject from '../../services/stores/subject';
8-
import type { Comments as CommentElement } from '../../web-components';
8+
import type { Comments as CommentElement } from '../../web-components/comments';
99
import { CommentsFloatButton } from '../../web-components/comments/components/float-button';
1010
import { BaseComponent } from '../base';
1111
import { ComponentNames } from '../types';
@@ -152,6 +152,7 @@ export class Comments extends BaseComponent {
152152
* @returns {void}
153153
*/
154154
protected start(): void {
155+
if (typeof window === 'undefined') return;
155156
this.clientUrl = window.location.href;
156157

157158
this.positionComments();

src/components/presence-mouse/html/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ export class PointersHTML extends BaseComponent {
205205
* @returns {void}
206206
*/
207207
private onMyParticipantMouseLeave = (event: MouseEvent): void => {
208+
if (typeof window === 'undefined') return;
209+
208210
const { left, top, right, bottom } = this.container.getBoundingClientRect();
209211
const isInsideContainer =
210212
event.x > left && event.y > top && event.x < right && event.y < bottom;

src/components/who-is-online/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Participant, Avatar } from '../../common/types/participant.types';
55
import { StoreType } from '../../common/types/stores.types';
66
import { Logger } from '../../common/utils';
77
import { Following } from '../../services/stores/who-is-online/types';
8-
import { WhoIsOnline as WhoIsOnlineElement } from '../../web-components';
8+
import type { WhoIsOnline as WhoIsOnlineElement } from '../../web-components/who-is-online';
99
import { DropdownOption } from '../../web-components/dropdown/types';
1010
import { BaseComponent } from '../base';
1111
import { ComponentNames } from '../types';

src/core/launcher/index.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,9 @@ export class Launcher extends Observable implements DefaultLauncher {
207207
this.isDestroyed = true;
208208

209209
// clean window object
210-
window.SUPERVIZ = undefined;
210+
if (typeof window !== 'undefined') {
211+
window.SUPERVIZ = undefined;
212+
}
211213
};
212214

213215
/**
@@ -455,7 +457,7 @@ export class Launcher extends Observable implements DefaultLauncher {
455457
* @returns {LauncherFacade}
456458
*/
457459
export default (options: LauncherOptions): LauncherFacade => {
458-
if (window.SUPERVIZ) {
460+
if (typeof window !== 'undefined' && window.SUPERVIZ) {
459461
console.warn('[SUPERVIZ] Room already initialized');
460462

461463
return {
@@ -469,7 +471,9 @@ export default (options: LauncherOptions): LauncherFacade => {
469471

470472
const launcher = new Launcher(options);
471473

472-
window.SUPERVIZ = launcher;
474+
if (typeof window !== 'undefined') {
475+
window.SUPERVIZ = launcher;
476+
}
473477

474478
return {
475479
destroy: launcher.destroy,

src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ import type {
5858
} from './components/comments/types';
5959
import type { Transform } from './components/presence-mouse/types';
6060

61-
if (window) {
61+
if (typeof window !== 'undefined') {
6262
window.SuperVizRoom = {
6363
init,
6464
CommentEvent,

src/services/connection-status/index.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ export class ConnectionService implements DefaultConnectionService {
2323
* @returns {void}
2424
*/
2525
public addListeners(): void {
26-
window.addEventListener('online', this.onUpdateBrowserOnlineStatus);
27-
window.addEventListener('offline', this.onUpdateBrowserOnlineStatus);
26+
if (typeof window !== 'undefined') {
27+
window.addEventListener('online', this.onUpdateBrowserOnlineStatus);
28+
window.addEventListener('offline', this.onUpdateBrowserOnlineStatus);
29+
}
2830
}
2931

3032
/**
@@ -33,8 +35,10 @@ export class ConnectionService implements DefaultConnectionService {
3335
* @returns {void}
3436
*/
3537
public removeListeners(): void {
36-
window.removeEventListener('online', this.onUpdateBrowserOnlineStatus);
37-
window.removeEventListener('offline', this.onUpdateBrowserOnlineStatus);
38+
if (typeof window !== 'undefined') {
39+
window.removeEventListener('online', this.onUpdateBrowserOnlineStatus);
40+
window.removeEventListener('offline', this.onUpdateBrowserOnlineStatus);
41+
}
3842
}
3943

4044
/**

src/services/message-bridge/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ export class MessageBridge {
6262
delete this.observers[type];
6363
});
6464

65-
window.removeEventListener('message', this.onReceiveMessage);
65+
if (typeof window !== 'undefined') {
66+
window.removeEventListener('message', this.onReceiveMessage);
67+
}
6668

6769
delete this.logger;
6870
delete this.allowedOrigins;

src/services/video-conference-manager/index.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,11 @@ export default class VideoConfereceManager {
161161
locales,
162162
};
163163
this.meetingAvatars = avatars;
164-
window.addEventListener('resize', this.onWindowResize);
165-
window.addEventListener('orientationchange', this.onWindowResize);
164+
165+
if (typeof window !== 'undefined') {
166+
window.addEventListener('resize', this.onWindowResize);
167+
window.addEventListener('orientationchange', this.onWindowResize);
168+
}
166169
}
167170

168171
get isWaterMarkEnabled(): boolean {
@@ -372,6 +375,8 @@ export default class VideoConfereceManager {
372375
* @returns {void}
373376
*/
374377
private onFrameDimensionsUpdate = ({ width, height }: Dimensions): void => {
378+
if (typeof window === 'undefined') return;
379+
375380
const frame = document.getElementById(FRAME_ID);
376381
const {
377382
bottom: offsetBottom,
@@ -661,8 +666,10 @@ export default class VideoConfereceManager {
661666
this.bricklayer = null;
662667
this.frameState = null;
663668

664-
window.removeEventListener('resize', this.onWindowResize);
665-
window.removeEventListener('orientationchange', this.onWindowResize);
669+
if (typeof window !== 'undefined') {
670+
window.removeEventListener('resize', this.onWindowResize);
671+
window.removeEventListener('orientationchange', this.onWindowResize);
672+
}
666673
}
667674

668675
/**

src/web-components/comments/comments.test.ts

-114
This file was deleted.

0 commit comments

Comments
 (0)