Skip to content

Commit

Permalink
fix(YJS|SDK): remove unnecessary validation from components initializ…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
carlossantos74 committed Jan 7, 2025
1 parent 9cbd700 commit a937e3a
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 36 deletions.
8 changes: 1 addition & 7 deletions packages/sdk/src/components/base/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,7 @@ export abstract class BaseComponent extends Observable {
}

const { config: globalConfig, eventBus, ioc } = params;
const { isDomainWhitelisted, hasJoinedRoom } = this.useStore(StoreType.GLOBAL);

if (!isDomainWhitelisted.value) {
const message = `Component ${this.name} can't be used because this website's domain is not whitelisted. Please add your domain in https://dashboard.superviz.com/developer`;
this.logger.log(message);
return;
}
const { hasJoinedRoom } = this.useStore(StoreType.GLOBAL);

config.setConfig(globalConfig);

Expand Down
2 changes: 0 additions & 2 deletions packages/sdk/src/core/launcher/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,10 @@ export class Launcher extends Observable implements DefaultLauncher {
const {
localParticipant: globalParticipant,
group,
isDomainWhitelisted,
} = this.useStore(StoreType.GLOBAL);
const { localParticipant, participants } = this.useStore(StoreType.CORE);

globalParticipant.publish({ ...participant });
isDomainWhitelisted.subscribe(this.onAuthentication);
globalParticipant.subscribe(this.onLocalParticipantUpdateOnStore);

localParticipant.subscribe(this.onLocalParticipantUpdateOnCore);
Expand Down
4 changes: 0 additions & 4 deletions packages/sdk/src/services/stores/global/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export class GlobalStore {
public localParticipant = subject<Participant>({} as Participant);
public participants = subject<Record<string, Participant>>({});
public group = subject<Group>(null);
public isDomainWhitelisted = subject<boolean>(true);
public hasJoinedRoom = subject<boolean>(false);

constructor() {
Expand All @@ -24,7 +23,6 @@ export class GlobalStore {
this.localParticipant.destroy();
this.participants.destroy();
this.group.destroy();
this.isDomainWhitelisted.destroy();
this.hasJoinedRoom.destroy();
}
}
Expand All @@ -35,15 +33,13 @@ const destroy = store.destroy.bind(store);
const group = store.group.expose();
const participants = store.participants.expose();
const localParticipant = store.localParticipant.expose();
const isDomainWhitelisted = store.isDomainWhitelisted.expose();
const hasJoinedRoom = store.hasJoinedRoom.expose();

export function useGlobalStore() {
return {
localParticipant,
participants,
group,
isDomainWhitelisted,
hasJoinedRoom,
destroy,
};
Expand Down
16 changes: 0 additions & 16 deletions packages/yjs/src/provider/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ describe('provider', () => {

provider.attach({
useStore: () => ({
isDomainWhitelisted: { value: true },
hasJoinedRoom: { value: true },
localParticipant: { value: { id: 'local-participant-id' } },
}),
Expand All @@ -83,27 +82,12 @@ describe('provider', () => {
expect(provider['connect']).toHaveBeenCalled();
});

test('should not connect if domain is not whitelisted', () => {
const provider = createProvider();
provider['connect'] = jest.fn();

provider.attach({
useStore: () => ({
isDomainWhitelisted: { value: false },
hasJoinedRoom: { value: true },
}),
} as any);

expect(provider['connect']).not.toHaveBeenCalled();
});

test('should not connect if user has not joined room', () => {
const provider = createProvider();
provider['connect'] = jest.fn();

provider.attach({
useStore: () => ({
isDomainWhitelisted: { value: true },
hasJoinedRoom: { value: false, subscribe: jest.fn() },
}),
} as any);
Expand Down
8 changes: 1 addition & 7 deletions packages/yjs/src/provider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,7 @@ export class SuperVizYjsProvider extends ObservableV2<Events> {
}

const { useStore, ioc, config } = params;
const { isDomainWhitelisted, hasJoinedRoom, localParticipant } = useStore(storeType.GLOBAL);

if (!isDomainWhitelisted.value) {
const message = `Component ${this.name} can't be used because this website's domain is not whitelisted. Please add your domain in https://dashboard.superviz.com/developer`;
this.logger.log(message);
return;
}
const { hasJoinedRoom, localParticipant } = useStore(storeType.GLOBAL);

if (!hasJoinedRoom.value) {
hasJoinedRoom.subscribe(() => this.attach(params));
Expand Down

0 comments on commit a937e3a

Please sign in to comment.