Skip to content
This repository was archived by the owner on Feb 24, 2026. It is now read-only.

Commit ffff250

Browse files
authored
feat: replace socket connection (#88)
1 parent 9188ede commit ffff250

3 files changed

Lines changed: 15 additions & 10 deletions

File tree

apps/gauzy/src/app/app.component.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import {
2424
NavigationService,
2525
SelectorBuilderService,
2626
SeoService,
27-
SocketConnectionService,
2827
Store
2928
} from '@gauzy/ui-core/core';
3029
import { I18nService } from '@gauzy/ui-core/i18n';
@@ -51,8 +50,7 @@ export class AppComponent implements OnInit, AfterViewInit {
5150
private readonly _activatedRoute: ActivatedRoute,
5251
private readonly _selectorBuilderService: SelectorBuilderService,
5352
private readonly _dateRangePickerBuilderService: DateRangePickerBuilderService,
54-
private readonly _navigationService: NavigationService,
55-
private readonly _socketConnectionService: SocketConnectionService
53+
private readonly _navigationService: NavigationService
5654
) {
5755
this.getActivateRouterDataEvent();
5856
this.getPreferredLanguage();
@@ -115,8 +113,6 @@ export class AppComponent implements OnInit, AfterViewInit {
115113
if (Number(this._store.serverConnection) === 0) {
116114
this.loading = false;
117115
}
118-
119-
if (this._store.token) this._socketConnectionService.connect();
120116
}
121117

122118
/**

apps/gauzy/src/app/pages/pages.component.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
NavMenuBuilderService,
1515
NavMenuSectionItem,
1616
PermissionsService,
17+
SocketConnectionService,
1718
Store,
1819
UsersService
1920
} from '@gauzy/ui-core/core';
@@ -23,15 +24,15 @@ import { ReportService } from './reports/all-report/report.service';
2324

2425
@UntilDestroy({ checkProperties: true })
2526
@Component({
26-
selector: 'ngx-pages',
27-
styleUrls: ['pages.component.scss'],
28-
template: `
27+
selector: 'ngx-pages',
28+
styleUrls: ['pages.component.scss'],
29+
template: `
2930
<ngx-one-column-layout *ngIf="!!menu && user">
3031
<ga-main-nav-menu></ga-main-nav-menu>
3132
<router-outlet></router-outlet>
3233
</ngx-one-column-layout>
3334
`,
34-
standalone: false
35+
standalone: false
3536
})
3637
export class PagesComponent extends TranslationBaseComponent implements AfterViewInit, OnInit, OnDestroy {
3738
public organization: IOrganization;
@@ -51,7 +52,8 @@ export class PagesComponent extends TranslationBaseComponent implements AfterVie
5152
private readonly _integrationsService: IntegrationsService,
5253
private readonly _integrationEntitySettingServiceStoreService: IntegrationEntitySettingServiceStoreService,
5354
private readonly _navMenuBuilderService: NavMenuBuilderService,
54-
private readonly _permissionsService: PermissionsService
55+
private readonly _permissionsService: PermissionsService,
56+
private readonly _socketConnectionService: SocketConnectionService
5557
) {
5658
super(translate);
5759
}
@@ -127,6 +129,8 @@ export class PagesComponent extends TranslationBaseComponent implements AfterVie
127129
// Add the report menu items to the navigation menu
128130
this.addOrRemoveOrganizationReportsMenuItems();
129131
});
132+
133+
if (this.store.token) this._socketConnectionService.connect();
130134
}
131135

132136
/**

packages/ui-core/core/src/lib/services/socket-connection/socket-connection.service.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ export class SocketConnectionService {
2121
const token = this.store.token;
2222
const baseUrl = environment.API_BASE_URL;
2323

24+
if (this.socket && this.socket.connected) {
25+
console.log('⚠️ Socket already connected, skipping...');
26+
return;
27+
}
28+
2429
// If no token is available, redirect to the login page
2530
if (!token) {
2631
console.warn('No token found, redirecting to login...');

0 commit comments

Comments
 (0)