2019-09-26 14:43:31 +09:00
|
|
|
import {
|
|
|
|
ProtocolRequest,
|
|
|
|
ProtocolResponse,
|
|
|
|
ProtocolEncoder,
|
|
|
|
PacketBody,
|
|
|
|
PacketBodyValue,
|
|
|
|
ProtocolDecoder,
|
|
|
|
ProtocolMessage,
|
|
|
|
BodyStringDivider,
|
|
|
|
ProtocolNotification
|
|
|
|
} from '@ucap-webmessenger/protocol';
|
|
|
|
import { StatusType, StatusCode } from '@ucap-webmessenger/core';
|
2019-10-07 10:08:14 +09:00
|
|
|
import { StatusInfo } from '../models/status-info';
|
2019-09-26 14:43:31 +09:00
|
|
|
|
|
|
|
export interface StatusRequest extends ProtocolRequest {
|
|
|
|
// 상태타입(s)
|
|
|
|
statusDivisionType: StatusType;
|
|
|
|
// 상태코드(s)
|
|
|
|
statusType: StatusCode;
|
|
|
|
// 상태메시지(s) (상태타입 : M, 상태코드: B 일때, 사용함)
|
|
|
|
statusMessage?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface StatusResponse extends ProtocolResponse {
|
|
|
|
// 상태타입(s)
|
|
|
|
statusDivisionType: StatusType;
|
|
|
|
// 상태코드(s)
|
|
|
|
statusType: StatusCode;
|
|
|
|
// 상태메시지(s) (상태타입 : M, 상태코드: B 일때, 사용함)
|
|
|
|
statusMessage: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface StatusNotification extends StatusInfo, ProtocolNotification {}
|
|
|
|
|
|
|
|
export const encodeStatus: ProtocolEncoder<StatusRequest> = (
|
|
|
|
req: StatusRequest
|
|
|
|
) => {
|
|
|
|
const bodyList: PacketBody[] = [];
|
|
|
|
|
|
|
|
bodyList.push(
|
|
|
|
{
|
|
|
|
type: PacketBodyValue.String,
|
|
|
|
value: req.statusDivisionType
|
|
|
|
},
|
|
|
|
{ type: PacketBodyValue.String, value: req.statusType },
|
|
|
|
{
|
|
|
|
type: PacketBodyValue.String,
|
|
|
|
value: req.statusMessage || ''
|
|
|
|
}
|
|
|
|
);
|
|
|
|
return bodyList;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const decodeStatus: ProtocolDecoder<StatusResponse> = (
|
|
|
|
message: ProtocolMessage
|
|
|
|
) => {
|
|
|
|
return {
|
|
|
|
statusDivisionType: message.bodyList[0] as StatusType,
|
|
|
|
statusType: message.bodyList[1] as StatusCode,
|
|
|
|
statusMessage: message.bodyList[2]
|
|
|
|
} as StatusResponse;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const decodeStatusNotification: ProtocolDecoder<StatusNotification> = (
|
|
|
|
message: ProtocolMessage
|
|
|
|
) => {
|
|
|
|
const info = message.bodyList[0].split(BodyStringDivider);
|
|
|
|
return {
|
2019-09-27 15:11:53 +09:00
|
|
|
userSeq: Number(info[0]),
|
|
|
|
pcStatus: info[1] as StatusCode,
|
|
|
|
phoneStatus: info[2] as StatusCode,
|
|
|
|
mobileStatus: info[3] as StatusCode,
|
|
|
|
conferenceStatus: info[4] as StatusCode,
|
|
|
|
statusMessage: info[5],
|
|
|
|
mobileConferenceStatus: info[6] as StatusCode,
|
|
|
|
imessengerStatus: info[7] as StatusCode
|
2019-09-26 14:43:31 +09:00
|
|
|
} as StatusNotification;
|
|
|
|
};
|