added protocol EVENT > SEND

This commit is contained in:
leejh 2019-09-23 18:09:04 +09:00
parent 0286b120f3
commit acf0721636
3 changed files with 134 additions and 2 deletions

View File

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

View File

@ -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<EventSendResponse> {
return this.protocolService
.call(SVC_TYPE_EVENT, SSVC_TYPE_EVENT_SEND_REQ, ...encodeEventSend(req))
.pipe(
take(1),
map(res => {
return decodeEventSend(res);
})
);
}
}

View File

@ -0,0 +1,7 @@
export enum PushStatus {
// PC 경우에만 관여됨
// N: 푸시를 보내지 않은 이벤트
NotSent = 'N',
// S: 푸시를 보낸 이벤트
Sent = 'S'
}