From 8572a5ea352f7f21e8c4b088e94374dff1125867 Mon Sep 17 00:00:00 2001 From: PARK BYUNG JUN Date: Mon, 1 Aug 2022 05:33:57 +0000 Subject: [PATCH] nats is added --- src/app/app.module.ts | 23 +++++++++++++++ src/app/core/nats/nats.module.ts | 7 +++++ src/app/core/nats/token.ts | 6 ++++ .../member/user/components/list.component.ts | 4 +++ .../modules/polyglot/member/member.module.ts | 16 +++++++++++ .../member/services/identity.service.ts | 28 +++++++++++++++++++ .../modules/polyglot/member/services/index.ts | 5 ++++ .../member/services/member.service.ts | 0 8 files changed, 89 insertions(+) create mode 100644 src/app/core/nats/nats.module.ts create mode 100644 src/app/core/nats/token.ts create mode 100644 src/app/modules/polyglot/member/member.module.ts create mode 100644 src/app/modules/polyglot/member/services/identity.service.ts create mode 100644 src/app/modules/polyglot/member/services/index.ts create mode 100644 src/app/modules/polyglot/member/services/member.service.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 60226d8..457cc77 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -5,6 +5,8 @@ import { ExtraOptions, PreloadAllModules, RouterModule } from '@angular/router'; import { MatIconRegistry, MatIconModule } from '@angular/material/icon'; import { DomSanitizer } from '@angular/platform-browser'; import { MarkdownModule } from 'ngx-markdown'; +import * as nats from 'nats.ws'; + import { FuseModule } from '@fuse'; import { FuseConfigModule } from '@fuse/services/config'; import { FuseMockApiModule } from '@fuse/lib/mock-api'; @@ -14,12 +16,30 @@ import { mockApiServices } from 'app/mock-api'; import { LayoutModule } from 'app/layout/layout.module'; import { AppComponent } from 'app/app.component'; import { appRoutes } from 'app/app.routing'; +import { NATS_CONNECTION } from 'app/core/nats/token'; +import { MemberModule } from 'app/modules/polyglot/member/member.module'; const routerConfig: ExtraOptions = { preloadingStrategy: PreloadAllModules, scrollPositionRestoration: 'enabled', }; +const natsConnection = () => { + return new Promise((resolve, reject) => { + nats + .connect({ + servers: ['ws://192.168.50.200:8088'], + }) + .then((conn) => { + console.log('NATS connected', conn.info); + resolve(conn); + }) + .catch((e) => { + reject(e); + }); + }); +}; + @NgModule({ declarations: [AppComponent], imports: [ @@ -41,7 +61,10 @@ const routerConfig: ExtraOptions = { // 3rd party modules that require global configuration via forRoot MarkdownModule.forRoot({}), MatIconModule, + + MemberModule.forRoot(), ], + providers: [{ provide: NATS_CONNECTION, useFactory: natsConnection }], bootstrap: [AppComponent], }) export class AppModule { diff --git a/src/app/core/nats/nats.module.ts b/src/app/core/nats/nats.module.ts new file mode 100644 index 0000000..25f9537 --- /dev/null +++ b/src/app/core/nats/nats.module.ts @@ -0,0 +1,7 @@ +import { NgModule } from '@angular/core'; + +@NgModule({ + exports: [], + providers: [], +}) +export class NatsCoreModule {} diff --git a/src/app/core/nats/token.ts b/src/app/core/nats/token.ts new file mode 100644 index 0000000..9a2abaa --- /dev/null +++ b/src/app/core/nats/token.ts @@ -0,0 +1,6 @@ +import { InjectionToken } from '@angular/core'; +import * as nats from 'nats.ws'; + +export const NATS_CONNECTION = new InjectionToken( + '@bet nats connection' +); diff --git a/src/app/modules/admin/member/user/components/list.component.ts b/src/app/modules/admin/member/user/components/list.component.ts index 87e98cd..ab6c8b1 100644 --- a/src/app/modules/admin/member/user/components/list.component.ts +++ b/src/app/modules/admin/member/user/components/list.component.ts @@ -33,6 +33,7 @@ import { User } from '../models/user'; import { UserPagination } from '../models/user-pagination'; import { UserService } from '../services/user.service'; import { Router } from '@angular/router'; +import { IdentityService } from 'app/modules/polyglot/member/services/identity.service'; @Component({ selector: 'user-list', @@ -87,6 +88,7 @@ export class ListComponent implements OnInit, AfterViewInit, OnDestroy { private _fuseConfirmationService: FuseConfirmationService, private _formBuilder: FormBuilder, private _userService: UserService, + private _identityService: IdentityService, private router: Router ) {} @@ -195,6 +197,8 @@ export class ListComponent implements OnInit, AfterViewInit, OnDestroy { */ __onClickSearch(): void { this.__isSearchOpened = !this.__isSearchOpened; + + console.log('kkkk', this._identityService.getClientIp()); } /** diff --git a/src/app/modules/polyglot/member/member.module.ts b/src/app/modules/polyglot/member/member.module.ts new file mode 100644 index 0000000..9409680 --- /dev/null +++ b/src/app/modules/polyglot/member/member.module.ts @@ -0,0 +1,16 @@ +import { ModuleWithProviders, NgModule } from '@angular/core'; + +import { SERVICES } from './services'; + +@NgModule({}) +export class MemberRootModule {} + +@NgModule({}) +export class MemberModule { + public static forRoot(): ModuleWithProviders { + return { + ngModule: MemberRootModule, + providers: [...SERVICES], + }; + } +} diff --git a/src/app/modules/polyglot/member/services/identity.service.ts b/src/app/modules/polyglot/member/services/identity.service.ts new file mode 100644 index 0000000..f09d532 --- /dev/null +++ b/src/app/modules/polyglot/member/services/identity.service.ts @@ -0,0 +1,28 @@ +import { Inject, Injectable } from '@angular/core'; +import { NATS_CONNECTION } from 'app/core/nats/token'; + +import * as nats from 'nats.ws'; + +@Injectable({ + providedIn: 'root', +}) +export class IdentityService { + /** + * Constructor + */ + constructor( + @Inject(NATS_CONNECTION) private __nats_connection: nats.NatsConnection + ) {} + + // ----------------------------------------------------------------------------------------------------- + // @ Accessors + // ----------------------------------------------------------------------------------------------------- + + // ----------------------------------------------------------------------------------------------------- + // @ Public methods + // ----------------------------------------------------------------------------------------------------- + + getClientIp(): number | undefined { + return this.__nats_connection.info?.client_id; + } +} diff --git a/src/app/modules/polyglot/member/services/index.ts b/src/app/modules/polyglot/member/services/index.ts new file mode 100644 index 0000000..ffc107a --- /dev/null +++ b/src/app/modules/polyglot/member/services/index.ts @@ -0,0 +1,5 @@ +import { Type } from '@angular/core'; + +import { IdentityService } from './identity.service'; + +export const SERVICES: Type[] = [IdentityService]; diff --git a/src/app/modules/polyglot/member/services/member.service.ts b/src/app/modules/polyglot/member/services/member.service.ts new file mode 100644 index 0000000..e69de29