diff --git a/src/packages/commons/commons.module.ts b/src/packages/commons/commons.module.ts new file mode 100644 index 0000000..a61ff82 --- /dev/null +++ b/src/packages/commons/commons.module.ts @@ -0,0 +1,10 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; + +@NgModule({ + imports: [ + CommonModule + ], + declarations: [] +}) +export class CommonsModule { } diff --git a/src/packages/commons/rx/websocket/rx-websocket-subject.ts b/src/packages/commons/rx/websocket/rx-websocket-subject.ts new file mode 100644 index 0000000..0ee3bfb --- /dev/null +++ b/src/packages/commons/rx/websocket/rx-websocket-subject.ts @@ -0,0 +1,121 @@ +import { Observable } from 'rxjs/Observable'; +import { Observer } from 'rxjs/Observer'; +import { Subject } from 'rxjs/Subject'; +import { + WebSocketSubject, + WebSocketSubjectConfig +} from 'rxjs/observable/dom/WebSocketSubject'; + +import 'rxjs/add/operator/distinctUntilChanged'; +import 'rxjs/add/operator/share'; +import 'rxjs/add/operator/takeWhile'; +import 'rxjs/add/observable/interval'; + +export interface Codec { + decode(e: MessageEvent): any; + encode(data: any): string; +} + +export const defaultCodec: Codec = { + encode: (e: MessageEvent) => { + return JSON.parse(e.data); + }, + decode: (data: any): string => { + return JSON.stringify(data); + } +}; + +export class RxWebsocketSubject extends Subject { + private reconnectionObservable: Observable; + private wsSubjectConfig: WebSocketSubjectConfig; + private socket: WebSocketSubject; + private connectionObserver: Observer; + private _connectionStatus: Observable; + + private _reconnectInterval = 5000; + private _reconnectAttempts = 10; + + public constructor(private url: string, private codec?: Codec) { + super(); + + this._connectionStatus = new Observable((observer) => { + this.connectionObserver = observer; + }).share().distinctUntilChanged(); + + if (undefined === codec) { + this.codec = defaultCodec; + } + + this.wsSubjectConfig = { + url: url, + closeObserver: { + next: (e: CloseEvent) => { + this.socket = null; + this.connectionObserver.next(false); + } + }, + openObserver: { + next: (e: Event) => { + this.connectionObserver.next(true); + } + }, + resultSelector: this.codec.decode, + }; + + this._connectionStatus.subscribe((isConnected: boolean) => { + if (!this.reconnectionObservable && typeof(isConnected) === 'boolean' && !isConnected) { + this.reconnect(); + } + }); + } + + public set reconnectInterval(reconnectInterval: number) { + this._reconnectInterval = reconnectInterval; + } + + public set reconnectAttempts(reconnectAttempts: number) { + this._reconnectAttempts = reconnectAttempts; + } + + public get connectionStatus(): Observable { + return this._connectionStatus; + } + + public connect(): void { + this.socket = new WebSocketSubject(this.wsSubjectConfig); + this.socket.subscribe( + (m) => { + this.next(m); + }, + (error: Event) => { + if (!this.socket) { + this.reconnect(); + } + } + ); + } + + private reconnect(): void { + this.reconnectionObservable = Observable.interval(this._reconnectInterval) + .takeWhile((v, index) => { + return index < this._reconnectAttempts && !this.socket; + }); + this.reconnectionObservable.subscribe( + () => { + this.connect(); + }, + null, + () => { + this.reconnectionObservable = null; + if (!this.socket) { + this.complete(); + this.connectionObserver.complete(); + } + } + ); + } + + public send(data: any): void { + this.socket.next(this.codec.encode(data)); + } +} diff --git a/src/packages/discovery/component/index.ts b/src/packages/discovery/component/index.ts new file mode 100644 index 0000000..81ac9cc --- /dev/null +++ b/src/packages/discovery/component/index.ts @@ -0,0 +1,5 @@ +import { SettingComponent } from './setting/setting.component'; + +export const COMPONENTS = [ + SettingComponent, +]; diff --git a/src/packages/discovery/discovery.module.ts b/src/packages/discovery/discovery.module.ts index f578baa..b1d1219 100644 --- a/src/packages/discovery/discovery.module.ts +++ b/src/packages/discovery/discovery.module.ts @@ -1,19 +1,19 @@ import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; -import { SettingComponent } from './component/setting/setting.component'; +import { COMPONENTS } from './component'; import { MaterialModule } from 'app/commons/ui/material/material.module'; -export const COMPONENTS = [ - SettingComponent, -]; - @NgModule({ imports: [ CommonModule, MaterialModule ], - declarations: COMPONENTS, - exports: COMPONENTS, + declarations: [ + COMPONENTS + ], + exports: [ + COMPONENTS, + ], }) export class DiscoveryModule { } diff --git a/src/packages/infra/component/index.ts b/src/packages/infra/component/index.ts new file mode 100644 index 0000000..e6615aa --- /dev/null +++ b/src/packages/infra/component/index.ts @@ -0,0 +1,5 @@ +import { MapComponent } from './map/map.component'; + +export const COMPONENTS = [ + MapComponent, +]; diff --git a/src/packages/infra/infra.module.ts b/src/packages/infra/infra.module.ts index b6bf749..1f93276 100644 --- a/src/packages/infra/infra.module.ts +++ b/src/packages/infra/infra.module.ts @@ -3,18 +3,18 @@ import { CommonModule } from '@angular/common'; import { MaterialModule } from 'app/commons/ui/material/material.module'; -import { MapComponent } from './component/map/map.component'; - -export const COMPONENTS = [ - MapComponent, -]; +import { COMPONENTS } from './component'; @NgModule({ imports: [ CommonModule, MaterialModule ], - declarations: COMPONENTS, - exports: COMPONENTS, + declarations: [ + COMPONENTS, + ], + exports: [ + COMPONENTS, + ], }) export class InfraModule { } diff --git a/src/packages/member/component/index.ts b/src/packages/member/component/index.ts new file mode 100644 index 0000000..31dbb87 --- /dev/null +++ b/src/packages/member/component/index.ts @@ -0,0 +1,11 @@ +import { ModifyComponent } from './modify/modify.component'; +import { SigninComponent } from './signin/signin.component'; +import { SignupComponent } from './signup/signup.component'; +import { ResetPasswordComponent } from './reset-password/reset-password.component'; + +export const COMPONENTS = [ + ModifyComponent, + SigninComponent, + SignupComponent, + ResetPasswordComponent, +]; diff --git a/src/packages/member/member-store.module.ts b/src/packages/member/member-store.module.ts index 42c4311..3e26c48 100644 --- a/src/packages/member/member-store.module.ts +++ b/src/packages/member/member-store.module.ts @@ -8,15 +8,16 @@ import { import { EffectsModule } from '@ngrx/effects'; import { combineReducers, ActionReducer, ActionReducerMap, MetaReducer } from '@ngrx/store'; -import { State as MemberState } from './store/state'; -import { reducers as memberReducers } from './store/reducer'; -import { EFFECTS } from './store/effect'; +import { + REDUCERS, + EFFECTS, +} from './store'; import { MODULE } from './member.constant'; @NgModule({ imports: [ - StoreModule.forFeature(MODULE.name, memberReducers), + StoreModule.forFeature(MODULE.name, REDUCERS), EffectsModule.forFeature(EFFECTS), ], }) diff --git a/src/packages/member/member.module.ts b/src/packages/member/member.module.ts index d1d27df..4a43768 100644 --- a/src/packages/member/member.module.ts +++ b/src/packages/member/member.module.ts @@ -5,21 +5,12 @@ import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { MaterialModule } from 'app/commons/ui/material/material.module'; -import { ModifyComponent } from './component/modify/modify.component'; -import { SigninComponent } from './component/signin/signin.component'; -import { SignupComponent } from './component/signup/signup.component'; -import { ResetPasswordComponent } from './component/reset-password/reset-password.component'; -import { MemberService } from './service/member.service'; import { AuthGuard } from './guard/auth.guard'; import { MemberStoreModule } from './member-store.module'; -export const COMPONENTS = [ - ModifyComponent, - SigninComponent, - SignupComponent, - ResetPasswordComponent, -]; +import { COMPONENTS } from './component'; +import { SERVICES } from './service'; @NgModule({ imports: [ @@ -30,11 +21,14 @@ export const COMPONENTS = [ MaterialModule, MemberStoreModule, ], - declarations: COMPONENTS, - exports: COMPONENTS, + declarations: [ + COMPONENTS, + ], + exports: [ + COMPONENTS, + ], providers: [ - AuthGuard, - MemberService, + SERVICES, ], }) export class MemberModule { } diff --git a/src/packages/member/service/index.ts b/src/packages/member/service/index.ts new file mode 100644 index 0000000..6528855 --- /dev/null +++ b/src/packages/member/service/index.ts @@ -0,0 +1,5 @@ +import { MemberService } from './member.service'; + +export const SERVICES = [ + MemberService, +]; diff --git a/src/packages/member/store/effect.ts b/src/packages/member/store/effect.ts deleted file mode 100644 index a3c5b99..0000000 --- a/src/packages/member/store/effect.ts +++ /dev/null @@ -1,7 +0,0 @@ -import * as AuthStore from './auth'; -import * as SignupStore from './signup'; - -export const EFFECTS = [ - AuthStore.Effects, - SignupStore.Effects, -]; diff --git a/src/packages/member/store/state.ts b/src/packages/member/store/index.ts similarity index 50% rename from src/packages/member/store/state.ts rename to src/packages/member/store/index.ts index 86b4b95..150b35f 100644 --- a/src/packages/member/store/state.ts +++ b/src/packages/member/store/index.ts @@ -6,3 +6,12 @@ export interface State { signup: SignupStore.Signup; } +export const REDUCERS = { + auth: AuthStore.reducer, + signup: SignupStore.reducer, +}; + +export const EFFECTS = [ + AuthStore.Effects, + SignupStore.Effects, +]; diff --git a/src/packages/member/store/reducer.ts b/src/packages/member/store/reducer.ts deleted file mode 100644 index 46b7117..0000000 --- a/src/packages/member/store/reducer.ts +++ /dev/null @@ -1,7 +0,0 @@ -import * as AuthStore from './auth'; -import * as SignupStore from './signup'; - -export const reducers = { - auth: AuthStore.reducer, - signup: SignupStore.reducer, -}; diff --git a/src/packages/noauth/component/index.ts b/src/packages/noauth/component/index.ts new file mode 100644 index 0000000..3b76d4f --- /dev/null +++ b/src/packages/noauth/component/index.ts @@ -0,0 +1,5 @@ +import { ListComponent } from './list/list.component'; + +export const COMPONENTS = [ + ListComponent, +]; diff --git a/src/packages/noauth/noauth.module.ts b/src/packages/noauth/noauth.module.ts index 25fc428..54118c0 100644 --- a/src/packages/noauth/noauth.module.ts +++ b/src/packages/noauth/noauth.module.ts @@ -1,17 +1,17 @@ import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; -import { ListComponent } from './component/list/list.component'; - -export const COMPONENTS = [ - ListComponent, -]; +import { COMPONENTS } from './component'; @NgModule({ imports: [ CommonModule ], - declarations: COMPONENTS, - exports: COMPONENTS, + declarations: [ + COMPONENTS, + ], + exports: [ + COMPONENTS, + ], }) export class NoauthModule { } diff --git a/src/packages/notification/component/index.ts b/src/packages/notification/component/index.ts new file mode 100644 index 0000000..1cb0950 --- /dev/null +++ b/src/packages/notification/component/index.ts @@ -0,0 +1,5 @@ +import { NotificationComponent } from './notification/notification.component'; + +export const COMPONENTS = [ + NotificationComponent, +]; diff --git a/src/packages/notification/notification.module.ts b/src/packages/notification/notification.module.ts index 6e4319a..6185f3a 100644 --- a/src/packages/notification/notification.module.ts +++ b/src/packages/notification/notification.module.ts @@ -6,12 +6,7 @@ import { import { MaterialModule } from 'app/commons/ui/material/material.module'; -import { NotificationComponent } from './component/notification/notification.component'; - -export const COMPONENTS = [ - NotificationComponent, -]; - +import { COMPONENTS } from './component'; @NgModule({ imports: [ @@ -19,7 +14,11 @@ export const COMPONENTS = [ PerfectScrollbarModule, MaterialModule, ], - declarations: COMPONENTS, - exports: COMPONENTS, + declarations: [ + COMPONENTS, + ], + exports: [ + COMPONENTS, + ], }) export class NotificationModule { } diff --git a/src/packages/probe/component/index.ts b/src/packages/probe/component/index.ts new file mode 100644 index 0000000..4efee54 --- /dev/null +++ b/src/packages/probe/component/index.ts @@ -0,0 +1,9 @@ +import { DetailComponent } from './detail/detail.component'; +import { ListComponent } from './list/list.component'; +import { DownloadComponent } from './download/download.component'; + +export const COMPONENTS = [ + ListComponent, + DetailComponent, + DownloadComponent, +]; diff --git a/src/packages/probe/probe.module.ts b/src/packages/probe/probe.module.ts index 0466f63..c2b9b72 100644 --- a/src/packages/probe/probe.module.ts +++ b/src/packages/probe/probe.module.ts @@ -3,15 +3,7 @@ import { CommonModule } from '@angular/common'; import { MaterialModule } from 'app/commons/ui/material/material.module'; import { InfoTableModule } from 'app/commons/component/info-table/info-table.module'; -import { DetailComponent } from './component/detail/detail.component'; -import { ListComponent } from './component/list/list.component'; -import { DownloadComponent } from './component/download/download.component'; - -export const COMPONENTS = [ - ListComponent, - DetailComponent, - DownloadComponent, -]; +import { COMPONENTS } from './component'; @NgModule({ imports: [ @@ -19,7 +11,11 @@ export const COMPONENTS = [ MaterialModule, InfoTableModule, ], - declarations: COMPONENTS, - exports: COMPONENTS, + declarations: [ + COMPONENTS, + ], + exports: [ + COMPONENTS, + ], }) export class ProbeModule { } diff --git a/src/packages/sensor-item/component/index.ts b/src/packages/sensor-item/component/index.ts new file mode 100644 index 0000000..3b76d4f --- /dev/null +++ b/src/packages/sensor-item/component/index.ts @@ -0,0 +1,5 @@ +import { ListComponent } from './list/list.component'; + +export const COMPONENTS = [ + ListComponent, +]; diff --git a/src/packages/sensor-item/sensor-item.module.ts b/src/packages/sensor-item/sensor-item.module.ts index d235669..56d1024 100644 --- a/src/packages/sensor-item/sensor-item.module.ts +++ b/src/packages/sensor-item/sensor-item.module.ts @@ -1,11 +1,7 @@ import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { MaterialModule } from 'app/commons/ui/material/material.module'; -import { ListComponent } from './component/list/list.component'; - -export const COMPONENTS = [ - ListComponent, -]; +import { COMPONENTS } from './component'; @NgModule({ @@ -13,7 +9,11 @@ export const COMPONENTS = [ CommonModule, MaterialModule, ], - declarations: COMPONENTS, - exports: COMPONENTS, + declarations: [ + COMPONENTS, + ], + exports: [ + COMPONENTS, + ], }) export class SensorItemModule { } diff --git a/src/packages/sensor/component/index.ts b/src/packages/sensor/component/index.ts new file mode 100644 index 0000000..0743a7d --- /dev/null +++ b/src/packages/sensor/component/index.ts @@ -0,0 +1,7 @@ +import { DiscoverySettingComponent } from './setting/setting.component'; +import { SettingResultComponent } from './setting-result/setting-result.component'; + +export const COMPONENTS = [ + DiscoverySettingComponent, + SettingResultComponent, +]; diff --git a/src/packages/sensor/sensor.module.ts b/src/packages/sensor/sensor.module.ts index 80b9ca6..9afe9fa 100644 --- a/src/packages/sensor/sensor.module.ts +++ b/src/packages/sensor/sensor.module.ts @@ -4,13 +4,7 @@ import {FormsModule} from '@angular/forms'; import { MaterialModule } from 'app/commons/ui/material/material.module'; -import { DiscoverySettingComponent } from './component/setting/setting.component'; -import { SettingResultComponent } from './component/setting-result/setting-result.component'; - -export const COMPONENTS = [ - DiscoverySettingComponent, - SettingResultComponent, -]; +import { COMPONENTS } from './component'; @NgModule({ imports: [ @@ -18,7 +12,11 @@ export const COMPONENTS = [ MaterialModule, FormsModule ], - declarations: COMPONENTS, - exports: COMPONENTS, + declarations: [ + COMPONENTS, + ], + exports: [ + COMPONENTS, + ], }) export class SensorModule { } diff --git a/src/packages/target/component/index.ts b/src/packages/target/component/index.ts new file mode 100644 index 0000000..8898b9a --- /dev/null +++ b/src/packages/target/component/index.ts @@ -0,0 +1,7 @@ +import { DetailComponent } from './detail/detail.component'; +import { ListComponent } from './list/list.component'; + +export const COMPONENTS = [ + ListComponent, + DetailComponent, +]; diff --git a/src/packages/target/target.module.ts b/src/packages/target/target.module.ts index a32a102..a6617e2 100644 --- a/src/packages/target/target.module.ts +++ b/src/packages/target/target.module.ts @@ -3,13 +3,7 @@ import { CommonModule } from '@angular/common'; import { MaterialModule } from 'app/commons/ui/material/material.module'; import { InfoTableModule } from 'app/commons/component/info-table/info-table.module'; -import { DetailComponent } from './component/detail/detail.component'; -import { ListComponent } from './component/list/list.component'; - -export const COMPONENTS = [ - ListComponent, - DetailComponent, -]; +import { COMPONENTS } from './component'; @NgModule({ imports: [ @@ -17,7 +11,11 @@ export const COMPONENTS = [ MaterialModule, InfoTableModule ], - declarations: COMPONENTS, - exports: COMPONENTS, + declarations: [ + COMPONENTS, + ], + exports: [ + COMPONENTS, + ], }) export class TargetModule { }