import { Injectable } from '@angular/core'; import { tap } from 'rxjs/operators'; import { Store } from '@ngrx/store'; import { SSVC_TYPE_LOGOUT_RES, SSVC_TYPE_LOGOUT_REMOTE_NOTI, AuthenticationProtocolService, LogoutResponse, LogoutRemoteNotification } from '@ucap-webmessenger/protocol-authentication'; import * as AuthenticationStore from '@app/store/account/authentication'; import * as EventStore from '@app/store/messenger/event'; import { NGXLogger } from 'ngx-logger'; import { EventProtocolService, SSVC_TYPE_EVENT_SEND_NOTI, SendNotification, SSVC_TYPE_EVENT_READ_NOTI, SSVC_TYPE_EVENT_CANCEL_NOTI, SSVC_TYPE_EVENT_DEL_RES, Info } from '@ucap-webmessenger/protocol-event'; import { InfoProtocolService, SSVC_TYPE_INFO_USER_NOTI, UserNotification } from '@ucap-webmessenger/protocol-info'; import { RoomProtocolService, SSVC_TYPE_ROOM_INVITE_NOTI, SSVC_TYPE_ROOM_EXIT_NOTI, SSVC_TYPE_ROOM_EXIT_FORCING_NOTI, SSVC_TYPE_ROOM_FONT_UPD_NOTI, InviteNotification } from '@ucap-webmessenger/protocol-room'; import { StatusProtocolService, SSVC_TYPE_STATUS_NOTI, StatusNotification } from '@ucap-webmessenger/protocol-status'; import { ReadNotification, CancelNotification, DelNotification } from '@ucap-webmessenger/protocol-event'; import { ExitNotification, ExitForcingNotification, UpdateFontNotification } from '@ucap-webmessenger/protocol-room'; @Injectable() export class AppNotificationService { constructor( private authenticationProtocolService: AuthenticationProtocolService, private eventProtocolService: EventProtocolService, private infoProtocolService: InfoProtocolService, private roomProtocolService: RoomProtocolService, private statusProtocolService: StatusProtocolService, private store: Store, private logger: NGXLogger ) {} public subscribe(): void { this.authenticationProtocolService.logoutNotification$ .pipe( tap(notiOrRes => { switch (notiOrRes.SSVC_TYPE) { case SSVC_TYPE_LOGOUT_RES: { const res = notiOrRes as LogoutResponse; this.logger.debug( 'Notification::authenticationProtocolService::LogoutResponse', res ); } break; case SSVC_TYPE_LOGOUT_REMOTE_NOTI: { const noti = notiOrRes as LogoutRemoteNotification; this.logger.debug( 'Notification::authenticationProtocolService::LogoutRemoteNotification', noti ); } break; default: break; } this.store.dispatch(AuthenticationStore.logout()); }) ) .subscribe(); this.eventProtocolService.notification$ .pipe( tap(notiOrRes => { switch (notiOrRes.SSVC_TYPE) { case SSVC_TYPE_EVENT_SEND_NOTI: { const noti = notiOrRes as SendNotification; this.logger.debug( 'Notification::eventProtocolService::SendNotification', noti ); this.store.dispatch( EventStore.sendNotification({ noti }) ); } break; case SSVC_TYPE_EVENT_READ_NOTI: { // 대화방 unread count 처리. const noti = notiOrRes as ReadNotification; this.logger.debug( 'Notification::eventProtocolService::ReadNotification', noti ); this.store.dispatch( EventStore.readNotification({ noti }) ); } break; case SSVC_TYPE_EVENT_CANCEL_NOTI: { const noti = notiOrRes as CancelNotification; this.logger.debug( 'Notification::eventProtocolService::CancelNotification', noti ); this.store.dispatch( EventStore.cancelNotification({ noti }) ); } break; case SSVC_TYPE_EVENT_DEL_RES: { const noti = notiOrRes as DelNotification; this.logger.debug( 'Notification::eventProtocolService::DelNotification', noti ); this.store.dispatch( EventStore.delNotification({ noti }) ); } break; default: break; } }) ) .subscribe(); this.infoProtocolService.notification$ .pipe( tap(notiOrRes => { switch (notiOrRes.SSVC_TYPE) { case SSVC_TYPE_INFO_USER_NOTI: { const noti = notiOrRes as UserNotification; this.logger.debug( 'Notification::infoProtocolService::UserNotification', noti ); } break; default: break; } }) ) .subscribe(); this.roomProtocolService.notification$ .pipe( tap(notiOrRes => { switch (notiOrRes.SSVC_TYPE) { case SSVC_TYPE_ROOM_INVITE_NOTI: { const noti = notiOrRes as InviteNotification; this.logger.debug( 'Notification::roomProtocolService::InviteNotification', noti ); } break; case SSVC_TYPE_ROOM_EXIT_NOTI: { const noti = notiOrRes as ExitNotification; this.logger.debug( 'Notification::roomProtocolService::ExitNotification', noti ); } break; case SSVC_TYPE_ROOM_EXIT_FORCING_NOTI: { const noti = notiOrRes as ExitForcingNotification; this.logger.debug( 'Notification::roomProtocolService::ExitForcingNotification', noti ); } break; case SSVC_TYPE_ROOM_FONT_UPD_NOTI: { const noti = notiOrRes as UpdateFontNotification; this.logger.debug( 'Notification::roomProtocolService::UpdateFontNotification', noti ); } break; default: break; } }) ) .subscribe(); this.statusProtocolService.notification$ .pipe( tap(notiOrRes => { switch (notiOrRes.SSVC_TYPE) { case SSVC_TYPE_STATUS_NOTI: { const noti = notiOrRes as StatusNotification; this.logger.debug( 'Notification::statusProtocolService::StatusNotification', noti ); } break; default: break; } }) ) .subscribe(); } }