From acf07216365e8879b2a512c2b5a3265ca2fb1fbd Mon Sep 17 00:00:00 2001 From: leejh Date: Mon, 23 Sep 2019 18:09:04 +0900 Subject: [PATCH] added protocol EVENT > SEND --- .../src/lib/models/event-send.ts | 107 ++++++++++++++++++ .../lib/services/event-protocol.service.ts | 22 +++- .../src/lib/types/pushStatus.type.ts | 7 ++ 3 files changed, 134 insertions(+), 2 deletions(-) create mode 100644 projects/ucap-webmessenger-protocol-event/src/lib/models/event-send.ts create mode 100644 projects/ucap-webmessenger-protocol-event/src/lib/types/pushStatus.type.ts diff --git a/projects/ucap-webmessenger-protocol-event/src/lib/models/event-send.ts b/projects/ucap-webmessenger-protocol-event/src/lib/models/event-send.ts new file mode 100644 index 00000000..f3bca19c --- /dev/null +++ b/projects/ucap-webmessenger-protocol-event/src/lib/models/event-send.ts @@ -0,0 +1,107 @@ +import { + ProtocolRequest, + ProtocolResponse, + ProtocolEncoder, + PacketBody, + ProtocolDecoder, + ProtocolMessage, + ProtocolStream, + PacketBodyValue +} from '@ucap-webmessenger/protocol'; +import { EventType } from '../types/event.type'; +import { PushStatus } from '../types/pushStatus.type'; + +export interface EventSendRequest extends ProtocolRequest { + // 0. 대화방SEQ(s) + roomSeq: string; + // 1. 이벤트타입(s) + type: EventType; + // 2. 이벤트내용(s) + sentMessage: string; +} + +export interface EventSendResponse { + // 대화방SEQ(s) + roomSeq: string; + // 이벤트SEQ(n) + seq: number; + // 이벤트타입(s) + type: EventType; + // 발생일시(s) + sendDate: string; + // 이벤트내용(s) + message: string; + // 수신자수 + receiverCount: number; + // 알림상태(s) PC 경우에만 관여됨 N: 푸시를 보내지 않은 이벤트 S: 푸시를 보낸 이벤트 + pushStatus: PushStatus; + // 강퇴 타입(s) + ForcedExitType: string; + // 요청자 이름(s) + senderName: string; +} + +export interface EventSendNotification extends EventSendResponse { + // 대화방SEQ(s) + // 이벤트SEQ(n) + // 이벤트타입(s) + // 발생일시(s) + // 이벤트내용(s) + // 수신자수 + // 알림상태(s) PC 경우에만 관여됨 N: 푸시를 보내지 않은 이벤트 S: 푸시를 보낸 이벤트 + // 강퇴 타입(s) + // 요청자 이름(s) + + // 사용자아이디(s) + id?: string; + // 회사코드(s) + companyCode?: string; +} + +export const encodeEventSend: ProtocolEncoder = ( + req: EventSendRequest +) => { + const bodyList: PacketBody[] = []; + + bodyList.push( + { type: PacketBodyValue.String, value: req.roomSeq }, + { type: PacketBodyValue.String, value: req.type }, + { type: PacketBodyValue.String, value: req.sentMessage } + ); + + return bodyList; +}; + +export const decodeEventSend: ProtocolDecoder = ( + message: ProtocolMessage +) => { + return { + roomSeq: message.bodyList[0], + seq: message.bodyList[1], + type: message.bodyList[2] as EventType, + sendDate: message.bodyList[3], + message: message.bodyList[4], + receiverCount: message.bodyList[5] || 0, + pushStatus: message.bodyList[6] as PushStatus, + ForcedExitType: message.bodyList[7], + senderName: message.bodyList[8] + } as EventSendResponse; +}; + +export const decodeEventSendNotification: ProtocolDecoder< + EventSendNotification +> = (message: ProtocolMessage) => { + return { + roomSeq: message.bodyList[0], + seq: message.bodyList[1], + type: message.bodyList[2] as EventType, + sendDate: message.bodyList[3], + message: message.bodyList[4], + receiverCount: message.bodyList[5] || 0, + pushStatus: message.bodyList[6] as PushStatus, + ForcedExitType: message.bodyList[7], + senderName: message.bodyList[8], + id: message.bodyList[9], + companyCode: message.bodyList[10] + } as EventSendNotification; +}; diff --git a/projects/ucap-webmessenger-protocol-event/src/lib/services/event-protocol.service.ts b/projects/ucap-webmessenger-protocol-event/src/lib/services/event-protocol.service.ts index 73f11c46..08e9e6fe 100644 --- a/projects/ucap-webmessenger-protocol-event/src/lib/services/event-protocol.service.ts +++ b/projects/ucap-webmessenger-protocol-event/src/lib/services/event-protocol.service.ts @@ -1,7 +1,7 @@ import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; -import { map, takeWhile, timeout } from 'rxjs/operators'; +import { map, takeWhile, timeout, take } from 'rxjs/operators'; import { ProtocolService } from '@ucap-webmessenger/protocol'; @@ -17,8 +17,15 @@ import { SVC_TYPE_EVENT, SSVC_TYPE_EVENT_INFO_REQ, SSVC_TYPE_EVENT_INFO_RES, - SSVC_TYPE_EVENT_INFO_DATA + SSVC_TYPE_EVENT_INFO_DATA, + SSVC_TYPE_EVENT_SEND_REQ } from '../types/service'; +import { + EventSendRequest, + EventSendResponse, + decodeEventSend, + encodeEventSend +} from '../models/event-send'; @Injectable({ providedIn: 'root' @@ -39,4 +46,15 @@ export class EventProtocolService { }) ); } + + public eventSend(req: EventSendRequest): Observable { + return this.protocolService + .call(SVC_TYPE_EVENT, SSVC_TYPE_EVENT_SEND_REQ, ...encodeEventSend(req)) + .pipe( + take(1), + map(res => { + return decodeEventSend(res); + }) + ); + } } diff --git a/projects/ucap-webmessenger-protocol-event/src/lib/types/pushStatus.type.ts b/projects/ucap-webmessenger-protocol-event/src/lib/types/pushStatus.type.ts new file mode 100644 index 00000000..81056b4a --- /dev/null +++ b/projects/ucap-webmessenger-protocol-event/src/lib/types/pushStatus.type.ts @@ -0,0 +1,7 @@ +export enum PushStatus { + // PC 경우에만 관여됨 + // N: 푸시를 보내지 않은 이벤트 + NotSent = 'N', + // S: 푸시를 보낸 이벤트 + Sent = 'S' +}