nats is added
This commit is contained in:
parent
7c6da7b882
commit
8572a5ea35
|
@ -5,6 +5,8 @@ import { ExtraOptions, PreloadAllModules, RouterModule } from '@angular/router';
|
||||||
import { MatIconRegistry, MatIconModule } from '@angular/material/icon';
|
import { MatIconRegistry, MatIconModule } from '@angular/material/icon';
|
||||||
import { DomSanitizer } from '@angular/platform-browser';
|
import { DomSanitizer } from '@angular/platform-browser';
|
||||||
import { MarkdownModule } from 'ngx-markdown';
|
import { MarkdownModule } from 'ngx-markdown';
|
||||||
|
import * as nats from 'nats.ws';
|
||||||
|
|
||||||
import { FuseModule } from '@fuse';
|
import { FuseModule } from '@fuse';
|
||||||
import { FuseConfigModule } from '@fuse/services/config';
|
import { FuseConfigModule } from '@fuse/services/config';
|
||||||
import { FuseMockApiModule } from '@fuse/lib/mock-api';
|
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 { LayoutModule } from 'app/layout/layout.module';
|
||||||
import { AppComponent } from 'app/app.component';
|
import { AppComponent } from 'app/app.component';
|
||||||
import { appRoutes } from 'app/app.routing';
|
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 = {
|
const routerConfig: ExtraOptions = {
|
||||||
preloadingStrategy: PreloadAllModules,
|
preloadingStrategy: PreloadAllModules,
|
||||||
scrollPositionRestoration: 'enabled',
|
scrollPositionRestoration: 'enabled',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const natsConnection = () => {
|
||||||
|
return new Promise<nats.NatsConnection>((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({
|
@NgModule({
|
||||||
declarations: [AppComponent],
|
declarations: [AppComponent],
|
||||||
imports: [
|
imports: [
|
||||||
|
@ -41,7 +61,10 @@ const routerConfig: ExtraOptions = {
|
||||||
// 3rd party modules that require global configuration via forRoot
|
// 3rd party modules that require global configuration via forRoot
|
||||||
MarkdownModule.forRoot({}),
|
MarkdownModule.forRoot({}),
|
||||||
MatIconModule,
|
MatIconModule,
|
||||||
|
|
||||||
|
MemberModule.forRoot(),
|
||||||
],
|
],
|
||||||
|
providers: [{ provide: NATS_CONNECTION, useFactory: natsConnection }],
|
||||||
bootstrap: [AppComponent],
|
bootstrap: [AppComponent],
|
||||||
})
|
})
|
||||||
export class AppModule {
|
export class AppModule {
|
||||||
|
|
7
src/app/core/nats/nats.module.ts
Normal file
7
src/app/core/nats/nats.module.ts
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
import { NgModule } from '@angular/core';
|
||||||
|
|
||||||
|
@NgModule({
|
||||||
|
exports: [],
|
||||||
|
providers: [],
|
||||||
|
})
|
||||||
|
export class NatsCoreModule {}
|
6
src/app/core/nats/token.ts
Normal file
6
src/app/core/nats/token.ts
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
import { InjectionToken } from '@angular/core';
|
||||||
|
import * as nats from 'nats.ws';
|
||||||
|
|
||||||
|
export const NATS_CONNECTION = new InjectionToken<nats.NatsConnection>(
|
||||||
|
'@bet nats connection'
|
||||||
|
);
|
|
@ -33,6 +33,7 @@ import { User } from '../models/user';
|
||||||
import { UserPagination } from '../models/user-pagination';
|
import { UserPagination } from '../models/user-pagination';
|
||||||
import { UserService } from '../services/user.service';
|
import { UserService } from '../services/user.service';
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
|
import { IdentityService } from 'app/modules/polyglot/member/services/identity.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'user-list',
|
selector: 'user-list',
|
||||||
|
@ -87,6 +88,7 @@ export class ListComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||||
private _fuseConfirmationService: FuseConfirmationService,
|
private _fuseConfirmationService: FuseConfirmationService,
|
||||||
private _formBuilder: FormBuilder,
|
private _formBuilder: FormBuilder,
|
||||||
private _userService: UserService,
|
private _userService: UserService,
|
||||||
|
private _identityService: IdentityService,
|
||||||
private router: Router
|
private router: Router
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
@ -195,6 +197,8 @@ export class ListComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||||
*/
|
*/
|
||||||
__onClickSearch(): void {
|
__onClickSearch(): void {
|
||||||
this.__isSearchOpened = !this.__isSearchOpened;
|
this.__isSearchOpened = !this.__isSearchOpened;
|
||||||
|
|
||||||
|
console.log('kkkk', this._identityService.getClientIp());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
16
src/app/modules/polyglot/member/member.module.ts
Normal file
16
src/app/modules/polyglot/member/member.module.ts
Normal file
|
@ -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<MemberRootModule> {
|
||||||
|
return {
|
||||||
|
ngModule: MemberRootModule,
|
||||||
|
providers: [...SERVICES],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
28
src/app/modules/polyglot/member/services/identity.service.ts
Normal file
28
src/app/modules/polyglot/member/services/identity.service.ts
Normal file
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
5
src/app/modules/polyglot/member/services/index.ts
Normal file
5
src/app/modules/polyglot/member/services/index.ts
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
import { Type } from '@angular/core';
|
||||||
|
|
||||||
|
import { IdentityService } from './identity.service';
|
||||||
|
|
||||||
|
export const SERVICES: Type<any>[] = [IdentityService];
|
Loading…
Reference in New Issue
Block a user