106 lines
2.8 KiB
TypeScript
106 lines
2.8 KiB
TypeScript
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 SendRequest extends ProtocolRequest {
|
|
// 0. 대화방SEQ(s)
|
|
roomSeq: string;
|
|
// 1. 이벤트타입(s)
|
|
type: EventType;
|
|
// 2. 이벤트내용(s)
|
|
sentMessage: string;
|
|
}
|
|
|
|
export interface SendResponse extends ProtocolResponse {
|
|
// 대화방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 SendNotification extends SendResponse {
|
|
// 대화방SEQ(s)
|
|
// 이벤트SEQ(n)
|
|
// 이벤트타입(s)
|
|
// 발생일시(s)
|
|
// 이벤트내용(s)
|
|
// 수신자수
|
|
// 알림상태(s) PC 경우에만 관여됨 N: 푸시를 보내지 않은 이벤트 S: 푸시를 보낸 이벤트
|
|
// 강퇴 타입(s)
|
|
// 요청자 이름(s)
|
|
|
|
// 사용자아이디(s)
|
|
id?: string;
|
|
// 회사코드(s)
|
|
companyCode?: string;
|
|
}
|
|
|
|
export const encodeSend: ProtocolEncoder<SendRequest> = (req: SendRequest) => {
|
|
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 decodeSend: ProtocolDecoder<SendResponse> = (
|
|
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 SendResponse;
|
|
};
|
|
|
|
export const decodeSendNotification: ProtocolDecoder<SendNotification> = (
|
|
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 SendNotification;
|
|
};
|