added protocol > EVENT > push, read

This commit is contained in:
leejh 2019-09-25 17:41:23 +09:00
parent f9cf9cbcf7
commit b3562ab2b3
4 changed files with 139 additions and 1 deletions

View File

@ -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<PushRequest> = (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;
};

View File

@ -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<ReadRequest> = (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<ReadResponse> = (
message: ProtocolMessage
) => {
return {
roomSeq: message.bodyList[0],
lastReadSeq: message.bodyList[1]
} as ReadResponse;
};
export const decodeReadNotification: ProtocolDecoder<ReadNotification> = (
message: ProtocolMessage
) => {
return {
roomSeq: message.bodyList[0],
lastReadSeq: message.bodyList[1]
} as ReadNotification;
};

View File

@ -18,7 +18,9 @@ import {
SSVC_TYPE_EVENT_INFO_REQ, SSVC_TYPE_EVENT_INFO_REQ,
SSVC_TYPE_EVENT_INFO_RES, SSVC_TYPE_EVENT_INFO_RES,
SSVC_TYPE_EVENT_INFO_DATA, 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'; } from '../types/service';
import { import {
SendRequest, SendRequest,
@ -26,6 +28,13 @@ import {
decodeSend, decodeSend,
encodeSend encodeSend
} from '../models/send'; } from '../models/send';
import { PushRequest, encodePush } from '../models/push';
import {
ReadResponse,
ReadRequest,
encodeRead,
decodeRead
} from '../models/read';
@Injectable({ @Injectable({
providedIn: 'root' 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<ReadResponse> {
return this.protocolService
.call(SVC_TYPE_EVENT, SSVC_TYPE_EVENT_READ_REQ, ...encodeRead(req))
.pipe(
take(1),
map(res => {
return decodeRead(res);
})
);
}
} }

View File

@ -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)
}