From b3562ab2b3a109488bb6b6a6f992450845b43e3c Mon Sep 17 00:00:00 2001 From: leejh Date: Wed, 25 Sep 2019 17:41:23 +0900 Subject: [PATCH] added protocol > EVENT > push, read --- .../src/lib/models/push.ts | 43 ++++++++++++++ .../src/lib/models/read.ts | 58 +++++++++++++++++++ .../lib/services/event-protocol.service.ts | 30 +++++++++- .../src/lib/types/pushCl.type.ts | 9 +++ 4 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 projects/ucap-webmessenger-protocol-event/src/lib/models/push.ts create mode 100644 projects/ucap-webmessenger-protocol-event/src/lib/models/read.ts create mode 100644 projects/ucap-webmessenger-protocol-event/src/lib/types/pushCl.type.ts diff --git a/projects/ucap-webmessenger-protocol-event/src/lib/models/push.ts b/projects/ucap-webmessenger-protocol-event/src/lib/models/push.ts new file mode 100644 index 00000000..2dce461a --- /dev/null +++ b/projects/ucap-webmessenger-protocol-event/src/lib/models/push.ts @@ -0,0 +1,43 @@ +import { + ProtocolRequest, + ProtocolEncoder, + PacketBody, + ProtocolDecoder, + ProtocolMessage, + PacketBodyValue +} from '@ucap-webmessenger/protocol'; +import { EventType } from '../types/event.type'; +import { PushStatus } from '../types/pushStatus.type'; +import { PushClType } from '../types/pushCl.type'; + +export interface PushRequest extends ProtocolRequest { + // 대화방SEQ(s) + roomSeq: string; + // 수신자SEQ(n) + receiverSeq: number; + // 푸시타입(s) + type: PushClType; + // 발생일시(s) + sendDate: string; + // 메시지(s) + message: string; + // 제목(s) + title: string; + // 이벤트타입(s) + eventType: EventType; +} + +export const encodePush: ProtocolEncoder = (req: PushRequest) => { + const bodyList: PacketBody[] = []; + + bodyList.push( + { type: PacketBodyValue.String, value: req.roomSeq }, + { type: PacketBodyValue.Integer, value: req.receiverSeq }, + { type: PacketBodyValue.String, value: req.type }, + { type: PacketBodyValue.String, value: req.sendDate }, + { type: PacketBodyValue.String, value: req.message }, + { type: PacketBodyValue.String, value: req.title }, + { type: PacketBodyValue.String, value: req.eventType } + ); + return bodyList; +}; diff --git a/projects/ucap-webmessenger-protocol-event/src/lib/models/read.ts b/projects/ucap-webmessenger-protocol-event/src/lib/models/read.ts new file mode 100644 index 00000000..d9973ee1 --- /dev/null +++ b/projects/ucap-webmessenger-protocol-event/src/lib/models/read.ts @@ -0,0 +1,58 @@ +import { + ProtocolRequest, + ProtocolEncoder, + PacketBody, + ProtocolDecoder, + ProtocolMessage, + PacketBodyValue, + ProtocolResponse, + ProtocolNotification +} from '@ucap-webmessenger/protocol'; +import { EventType } from '../types/event.type'; +import { PushStatus } from '../types/pushStatus.type'; +import { PushClType } from '../types/pushCl.type'; + +export interface ReadRequest extends ProtocolRequest { + // 대화방SEQ(s) + roomSeq: string; + // LR이벤트SEQ(n) + lastReadSeq: number; +} +export interface ReadResponse extends ProtocolResponse { + // 대화방SEQ(s) + roomSeq: string; + // LR이벤트SEQ(n) + lastReadSeq: number; +} +export interface ReadNotification extends ProtocolNotification { + // 대화방SEQ(s) + roomSeq: string; + // LR이벤트SEQ(n) + lastReadSeq: number; +} + +export const encodeRead: ProtocolEncoder = (req: ReadRequest) => { + const bodyList: PacketBody[] = []; + + bodyList.push( + { type: PacketBodyValue.String, value: req.roomSeq }, + { type: PacketBodyValue.Integer, value: req.lastReadSeq } + ); + return bodyList; +}; +export const decodeRead: ProtocolDecoder = ( + message: ProtocolMessage +) => { + return { + roomSeq: message.bodyList[0], + lastReadSeq: message.bodyList[1] + } as ReadResponse; +}; +export const decodeReadNotification: ProtocolDecoder = ( + message: ProtocolMessage +) => { + return { + roomSeq: message.bodyList[0], + lastReadSeq: message.bodyList[1] + } as ReadNotification; +}; 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 2ebab844..e00ed4f3 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 @@ -18,7 +18,9 @@ import { SSVC_TYPE_EVENT_INFO_REQ, SSVC_TYPE_EVENT_INFO_RES, SSVC_TYPE_EVENT_INFO_DATA, - SSVC_TYPE_EVENT_SEND_REQ + SSVC_TYPE_EVENT_SEND_REQ, + SSVC_TYPE_EVENT_PUSH_CL_REQ, + SSVC_TYPE_EVENT_READ_REQ } from '../types/service'; import { SendRequest, @@ -26,6 +28,13 @@ import { decodeSend, encodeSend } from '../models/send'; +import { PushRequest, encodePush } from '../models/push'; +import { + ReadResponse, + ReadRequest, + encodeRead, + decodeRead +} from '../models/read'; @Injectable({ providedIn: 'root' @@ -63,4 +72,23 @@ export class EventProtocolService { }) ); } + + public push(req: PushRequest): void { + return this.protocolService.send( + SVC_TYPE_EVENT, + SSVC_TYPE_EVENT_PUSH_CL_REQ, + ...encodePush(req) + ); + } + + public read(req: ReadRequest): Observable { + return this.protocolService + .call(SVC_TYPE_EVENT, SSVC_TYPE_EVENT_READ_REQ, ...encodeRead(req)) + .pipe( + take(1), + map(res => { + return decodeRead(res); + }) + ); + } } diff --git a/projects/ucap-webmessenger-protocol-event/src/lib/types/pushCl.type.ts b/projects/ucap-webmessenger-protocol-event/src/lib/types/pushCl.type.ts new file mode 100644 index 00000000..836bf5e4 --- /dev/null +++ b/projects/ucap-webmessenger-protocol-event/src/lib/types/pushCl.type.ts @@ -0,0 +1,9 @@ +export enum PushClType { + Message = 'M', // Message + LoginAlarm = 'L', // LOG IN Alaram + FMC = 'F', // FMC Wake + Call = 'C', // FMC Call + BriefNote = 'B', // 쪽지(Brief note) + Announce = 'A', // 알림(Announce) + Gongji = 'G' // 공지(Gongji) +}