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

Commit

Permalink
feat: merge feat/comments-review into lab
Browse files Browse the repository at this point in the history
  • Loading branch information
Raspincel committed Jan 2, 2024
2 parents 0c054a8 + 1e19ecd commit d4ed1e2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/components/comments/canvas-pin-adapter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export class CanvasPin implements PinAdapter {
}

this.canvasSides = this.canvas.getBoundingClientRect();

document.body.style.position = 'relative';
this.onPinFixedObserver = new Observer({ logger: this.logger });
this.divWrapper = this.renderDivWrapper();
Expand Down
21 changes: 16 additions & 5 deletions src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,24 @@ const init = async (apiKey: string, options: SuperVizSdkOptions): Promise<Launch
throw new Error('Failed to validate API key');
}

const environment = await ApiService.fetchConfig(apiUrl, apiKey);
const limits = await ApiService.fetchLimits(apiUrl, apiKey);
const waterMark = await ApiService.fetchWaterMark(apiUrl, apiKey);
const [environment, limits, waterMark] = await Promise.all([
ApiService.fetchConfig(apiUrl, apiKey),
ApiService.fetchLimits(apiUrl, apiKey),
ApiService.fetchWaterMark(apiUrl, apiKey),
]).catch(() => {
throw new Error('Failed to load configuration from server');
});

if (!environment || !environment.ablyKey) {
throw new Error('Failed to load configuration from server');
}

const { ablyKey } = environment;
const { participant, roomId } = options;

const isEnteringTwice = await ApiService.validadeParticipantIsEnteringTwice(
options.participant,
options.roomId,
participant,
roomId,
apiKey,
ablyKey,
);
Expand All @@ -126,6 +131,12 @@ const init = async (apiKey: string, options: SuperVizSdkOptions): Promise<Launch
colors: options.customColors,
});

ApiService.createOrUpdateParticipant({
name: participant.name,
participantId: participant.id,
avatar: participant.avatar?.imageUrl,
});

return LauncherFacade(options);
};

Expand Down
15 changes: 5 additions & 10 deletions src/core/launcher/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class Launcher extends Observable implements DefaultLauncher {

private isDestroyed = false;
private activeComponents: ComponentNames[] = [];
private activeComponentsInstances: BaseComponent[] = [];
private activeComponentsInstances: Partial<BaseComponent>[] = [];
private participant: Participant;
private group: Group;

Expand Down Expand Up @@ -59,7 +59,7 @@ export class Launcher extends Observable implements DefaultLauncher {
* @param component - component to add
* @returns {void}
*/
public addComponent = (component: BaseComponent): void => {
public addComponent = (component: Partial<BaseComponent>): void => {
if (!this.canAddComponent(component)) return;

component.attach({
Expand All @@ -75,11 +75,6 @@ export class Launcher extends Observable implements DefaultLauncher {
this.realtime.updateMyProperties({ activeComponents: this.activeComponents });

ApiService.sendActivity(this.participant.id, this.group.id, this.group.name, component.name);
ApiService.createOrUpdateParticipant({
name: this.participant?.name,
participantId: this.participant?.id,
avatar: this.participant?.avatar?.imageUrl,
});
};

/**
Expand All @@ -88,7 +83,7 @@ export class Launcher extends Observable implements DefaultLauncher {
* @param component - component to remove
* @returns {void}
*/
public removeComponent = (component: BaseComponent): void => {
public removeComponent = (component: Partial<BaseComponent>): void => {
if (!this.activeComponents.includes(component.name)) {
const message = `Component ${component.name} is not initialized yet.`;
this.logger.log(message);
Expand Down Expand Up @@ -141,7 +136,7 @@ export class Launcher extends Observable implements DefaultLauncher {
* @param component - component to be added
* @returns {boolean}
*/
private canAddComponent = (component: BaseComponent): boolean => {
private canAddComponent = (component: Partial<BaseComponent>): boolean => {
const isWhitelisted = this.realtime?.isDomainWhitelisted;
const hasComponentLimit = LimitsService.checkComponentLimit(component.name);
const isComponentActive = this.activeComponents.includes(component.name);
Expand Down Expand Up @@ -223,7 +218,7 @@ export class Launcher extends Observable implements DefaultLauncher {
private onParticipantListUpdate = (participants: Record<string, AblyParticipant>): void => {
this.logger.log('launcher service @ onParticipantListUpdate', participants);

const participantList = Object.values(participants).map((participant) => ({
const participantList: Participant[] = Object.values(participants).map((participant) => ({
id: participant.data.id,
name: participant.data?.name,
type: participant.data?.type,
Expand Down
2 changes: 2 additions & 0 deletions src/services/realtime/ably/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1464,6 +1464,8 @@ export default class AblyRealtimeService extends RealtimeService implements Ably
};

public updatePresence3D = throttle((data: ParticipantInfo): void => {
if (!data || !data.id) return;

const participant = Object.assign({}, this.participantsOn3d[data.id]?.data ?? {}, data);

this.participantsOn3d[data.id] = {
Expand Down

0 comments on commit d4ed1e2

Please sign in to comment.