added protocol > status

This commit is contained in:
leejh 2019-09-26 14:43:31 +09:00
parent 8d8b1e5c47
commit 84aaa4e901
11 changed files with 614 additions and 1 deletions

View File

@ -0,0 +1,36 @@
import {
ProtocolResponse,
ProtocolDecoder,
ProtocolMessage,
BodyStringDivider
} from '@ucap-webmessenger/protocol';
import { StatusCode } from '@ucap-webmessenger/core';
import { StatusInfo } from './status';
export interface BuddyResponse extends ProtocolResponse {
// {상태정보}...
statusInfos: StatusInfo[];
}
export const decodeBuddy: ProtocolDecoder<BuddyResponse> = (
message: ProtocolMessage
) => {
const statusInfos: StatusInfo[] = [];
message.bodyList.forEach(statusInfo => {
const info = statusInfo.split(BodyStringDivider);
let idx = 0;
statusInfos.push({
userSeq: info[idx],
pcStatus: info[idx++] as StatusCode,
phoneStatus: info[idx++] as StatusCode,
mobileStatus: info[idx++] as StatusCode,
conferenceStatus: info[idx++] as StatusCode,
statusMessage: info[idx++],
mobileConferenceStatus: info[idx++] as StatusCode,
imessengerStatus: info[idx++] as StatusCode
});
});
return {
statusInfos
} as BuddyResponse;
};

View File

@ -0,0 +1,112 @@
import {
ProtocolRequest,
ProtocolResponse,
ProtocolEncoder,
PacketBody,
PacketBodyValue,
ProtocolDecoder,
ProtocolMessage,
BodyStringDivider,
ProtocolStream
} from '@ucap-webmessenger/protocol';
import { StatusType, StatusCode } from '@ucap-webmessenger/core';
import { StatusInfo } from './status';
import {
TerminalStatusInfo,
TerminalStatusNumber
} from '../types/terminal-status.type';
export interface BulkInfoRequest extends ProtocolRequest {
// DivCD(s)
divCd: string;
// 사용자SEQ(n)...
userSeqs: number[];
}
export interface StatusBulkInfo extends StatusInfo {
// 사용자SEQ
// 상태코드(PC)
// 상태코드(통화)
// 상태코드(모바일)
// 상태코드(PC화상)
// 상태메시지
// 상태코드(Mobile화상)
// 상태코드(iMessenger)
// 단말상태정보(s)
terminalStatus: TerminalStatusInfo;
// 단말상태번호(n)
terminalStatusNumber: TerminalStatusNumber;
}
export interface BulkInfoData extends ProtocolStream {
// DivCD(s)
divCd: string;
// {상태정보Bulk}...
statusBulkInfos: StatusBulkInfo[];
}
export interface BulkInfoResponse extends ProtocolResponse {
// DivCD(s)
divCd: string;
}
export const encodeBulkInfo: ProtocolEncoder<BulkInfoRequest> = (
req: BulkInfoRequest
) => {
const bodyList: PacketBody[] = [];
bodyList.push({ type: PacketBodyValue.String, value: req.divCd });
req.userSeqs.forEach(userSeq => {
bodyList.push({ type: PacketBodyValue.Integer, value: userSeq });
});
return bodyList;
};
export const decodeBulkInfo: ProtocolDecoder<BulkInfoResponse> = (
message: ProtocolMessage
) => {
return {
divCd: message.bodyList[0]
} as BulkInfoResponse;
};
export const decodeBulkInfoData: ProtocolDecoder<BulkInfoData> = (
message: ProtocolMessage
) => {
const statusBulkInfos: StatusBulkInfo[] = [];
message.bodyList.slice(1).forEach(statusBulkInfo => {
const info = statusBulkInfo.split(BodyStringDivider);
let idx = 0;
statusBulkInfos.push({
userSeq: info[idx],
pcStatus: info[idx++] as StatusCode,
phoneStatus: info[idx++] as StatusCode,
mobileStatus: info[idx++] as StatusCode,
conferenceStatus: info[idx++] as StatusCode,
statusMessage: info[idx++],
mobileConferenceStatus: info[idx++] as StatusCode,
imessengerStatus: info[idx++] as StatusCode,
terminalStatus: info[idx++] as TerminalStatusInfo,
terminalStatusNumber: info[idx++] as TerminalStatusNumber
});
});
return {
divCd: message.bodyList[0],
statusBulkInfos
} as BulkInfoData;
};
// export const decodeStatusNotification: ProtocolDecoder<StatusNotification> = (
// message: ProtocolMessage
// ) => {
// const info = message.bodyList[0].split(BodyStringDivider);
// let idx = 0;
// return {
// userSeq: info[idx],
// pcStatus: info[idx++] as StatusCode,
// phoneStatus: info[idx++] as StatusCode,
// mobileStatus: info[idx++] as StatusCode,
// conferenceStatus: info[idx++] as StatusCode,
// statusMessage: info[idx++],
// mobileConferenceStatus: info[idx++] as StatusCode,
// imessengerStatus: info[idx++] as StatusCode
// } as StatusNotification;
// };

View File

@ -0,0 +1,45 @@
import {
ProtocolRequest,
ProtocolResponse,
ProtocolEncoder,
PacketBody,
PacketBodyValue,
ProtocolDecoder,
ProtocolMessage
} from '@ucap-webmessenger/protocol';
import { MessageIndexType } from '../types/message-index.type';
export interface MessageUpdateRequest extends ProtocolRequest {
// 상태타입(s)
index: MessageIndexType;
// 상태메시지(s)
statusMessage: string;
}
export interface MessageUpdateResponse extends ProtocolResponse {
// 상태타입(s)
index: MessageIndexType;
// 상태메시지(s)
statusMessage: string;
}
export const encodeMessageUpdate: ProtocolEncoder<MessageUpdateRequest> = (
req: MessageUpdateRequest
) => {
const bodyList: PacketBody[] = [];
bodyList.push(
{ type: PacketBodyValue.Integer, value: req.index },
{ type: PacketBodyValue.String, value: req.statusMessage }
);
return bodyList;
};
export const decodeMessageUpdate: ProtocolDecoder<MessageUpdateResponse> = (
message: ProtocolMessage
) => {
return {
index: message.bodyList[0] as MessageIndexType,
statusMessage: message.bodyList[1]
} as MessageUpdateResponse;
};

View File

@ -0,0 +1,96 @@
import {
ProtocolRequest,
ProtocolResponse,
ProtocolEncoder,
PacketBody,
PacketBodyValue,
ProtocolDecoder,
ProtocolMessage,
BodyStringDivider,
ProtocolNotification
} from '@ucap-webmessenger/protocol';
import { StatusType, StatusCode } from '@ucap-webmessenger/core';
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 StatusInfo {
// 사용자SEQ
userSeq: number;
// 상태코드(PC)
pcStatus: StatusCode;
// 상태코드(통화)
phoneStatus: StatusCode;
// 상태코드(모바일)
mobileStatus: StatusCode;
// 상태코드(PC화상)
conferenceStatus: StatusCode;
// 상태메시지
statusMessage: string;
// 상태코드(Mobile화상)
mobileConferenceStatus: StatusCode;
// 상태코드(iMessenger)
imessengerStatus: StatusCode;
}
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);
let idx = 0;
return {
userSeq: info[idx],
pcStatus: info[idx++] as StatusCode,
phoneStatus: info[idx++] as StatusCode,
mobileStatus: info[idx++] as StatusCode,
conferenceStatus: info[idx++] as StatusCode,
statusMessage: info[idx++],
mobileConferenceStatus: info[idx++] as StatusCode,
imessengerStatus: info[idx++] as StatusCode
} as StatusNotification;
};

View File

@ -0,0 +1,93 @@
import {
ProtocolRequest,
ProtocolResponse,
ProtocolEncoder,
PacketBody,
PacketBodyValue,
ProtocolDecoder,
ProtocolMessage,
BodyStringDivider,
ProtocolStream
} from '@ucap-webmessenger/protocol';
import { StatusCode } from '@ucap-webmessenger/core';
import { StatusInfo } from './status';
export interface SubscribeRequest extends ProtocolRequest {
// 사용자SEQ(n)...
userSeqs: number[];
}
export interface SubscribeResponse extends ProtocolResponse {
// {상태정보}...
statusInfos: StatusInfo[];
}
/**
* @deprecated not support server
*/
export interface SubscribeData extends ProtocolStream {
// {상태정보}...
statusInfos: StatusInfo[];
}
export const encodeSubscribe: ProtocolEncoder<SubscribeRequest> = (
req: SubscribeRequest
) => {
const bodyList: PacketBody[] = [];
req.userSeqs.forEach(userSeq => {
bodyList.push({ type: PacketBodyValue.Integer, value: userSeq });
});
return bodyList;
};
export const decodeSubscribe: ProtocolDecoder<SubscribeResponse> = (
message: ProtocolMessage
) => {
const statusInfos: StatusInfo[] = [];
message.bodyList.forEach(statusInfo => {
const info = statusInfo.split(BodyStringDivider);
let idx = 0;
statusInfos.push({
userSeq: info[idx],
pcStatus: info[idx++] as StatusCode,
phoneStatus: info[idx++] as StatusCode,
mobileStatus: info[idx++] as StatusCode,
conferenceStatus: info[idx++] as StatusCode,
statusMessage: info[idx++],
mobileConferenceStatus: info[idx++] as StatusCode,
imessengerStatus: info[idx++] as StatusCode
});
});
return {
statusInfos
} as SubscribeResponse;
};
/**
* @deprecated not support server
*/
// tslint:disable-next-line: deprecation
export const decodeSubscribeData: ProtocolDecoder<SubscribeData> = (
message: ProtocolMessage
) => {
const statusInfos: StatusInfo[] = [];
message.bodyList.forEach(statusInfo => {
const info = statusInfo.split(BodyStringDivider);
let idx = 0;
statusInfos.push({
userSeq: info[idx],
pcStatus: info[idx++] as StatusCode,
phoneStatus: info[idx++] as StatusCode,
mobileStatus: info[idx++] as StatusCode,
conferenceStatus: info[idx++] as StatusCode,
statusMessage: info[idx++],
mobileConferenceStatus: info[idx++] as StatusCode,
imessengerStatus: info[idx++] as StatusCode
});
});
return {
statusInfos
// tslint:disable-next-line: deprecation
} as SubscribeData;
};

View File

@ -0,0 +1,29 @@
import {
ProtocolRequest,
ProtocolResponse,
ProtocolEncoder,
PacketBody,
PacketBodyValue
} from '@ucap-webmessenger/protocol';
import { StatusInfo } from './status';
export interface UnSubscribeRequest extends ProtocolRequest {
// 사용자SEQ(n)...
userSeqs: number[];
}
export interface UnSubscribeResponse extends ProtocolResponse {
// {상태정보}...
statusInfos: StatusInfo[];
}
export const encodeUnSubscribe: ProtocolEncoder<UnSubscribeRequest> = (
req: UnSubscribeRequest
) => {
const bodyList: PacketBody[] = [];
req.userSeqs.forEach(userSeq => {
bodyList.push({ type: PacketBodyValue.Integer, value: userSeq });
});
return bodyList;
};

View File

@ -1,8 +1,151 @@
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { map, take, takeWhile } from 'rxjs/operators';
import { ProtocolService } from '@ucap-webmessenger/protocol';
import {
StatusRequest,
encodeStatus,
decodeStatus,
StatusResponse
} from '../models/status';
import {
SVC_TYPE_STATUS,
SSVC_TYPE_STATUS_REQ,
SSVC_TYPE_STATUS_BULK_INFO_REQ,
SSVC_TYPE_STATUS_BULK_INFO_RES,
SSVC_TYPE_STATUS_BULK_INFO_DATA,
SSVC_TYPE_STATUS_BUDDY_REQ,
SSVC_TYPE_STATUS_MSG_UPD_REQ,
SSVC_TYPE_STATUS_SUBSCRIPT_REQ,
SSVC_TYPE_STATUS_UNSUBSCRIPT_REQ
} from '../types/service';
import {
BulkInfoRequest,
BulkInfoResponse,
BulkInfoData,
encodeBulkInfo,
decodeBulkInfo,
decodeBulkInfoData
} from '../models/bulk';
import { BuddyResponse, decodeBuddy } from '../models/buddy';
import {
MessageUpdateRequest,
MessageUpdateResponse,
encodeMessageUpdate,
decodeMessageUpdate
} from '../models/message-update';
import {
SubscribeRequest,
SubscribeResponse,
decodeSubscribe,
encodeSubscribe
} from '../models/subscribe';
import { UnSubscribeRequest, encodeUnSubscribe } from '../models/unsubscribe';
@Injectable({
providedIn: 'root'
})
export class StatusProtocolService {
constructor() {}
constructor(private protocolService: ProtocolService) {}
public status(req: StatusRequest): Observable<StatusResponse> {
return this.protocolService
.call(SVC_TYPE_STATUS, SSVC_TYPE_STATUS_REQ, ...encodeStatus(req))
.pipe(
take(1),
map(res => {
return decodeStatus(res);
})
);
}
public buddy(): Observable<BuddyResponse> {
return this.protocolService
.call(SVC_TYPE_STATUS, SSVC_TYPE_STATUS_BUDDY_REQ)
.pipe(
take(1),
map(res => {
return decodeBuddy(res);
})
);
}
public bulkInfo(
req: BulkInfoRequest
): Observable<BulkInfoResponse | BulkInfoData> {
return this.protocolService
.call(
SVC_TYPE_STATUS,
SSVC_TYPE_STATUS_BULK_INFO_REQ,
...encodeBulkInfo(req)
)
.pipe(
takeWhile(
res => SSVC_TYPE_STATUS_BULK_INFO_RES !== res.subServiceType,
true
),
map(res => {
if (SSVC_TYPE_STATUS_BULK_INFO_DATA === res.subServiceType) {
return {
...decodeBulkInfoData(res),
Type: SSVC_TYPE_STATUS_BULK_INFO_DATA
};
}
return {
...decodeBulkInfo(res),
Type: SSVC_TYPE_STATUS_BULK_INFO_RES
};
})
);
}
public messageUpdate(
req: MessageUpdateRequest
): Observable<MessageUpdateResponse> {
return this.protocolService
.call(
SVC_TYPE_STATUS,
SSVC_TYPE_STATUS_MSG_UPD_REQ,
...encodeMessageUpdate(req)
)
.pipe(
take(1),
map(res => {
return decodeMessageUpdate(res);
})
);
}
/**
* Only Use 1:1 Chat Room and must be using unsubscribe method.
* @param req SubscribeRequest
*/
public subscribe(req: SubscribeRequest): Observable<SubscribeResponse> {
return this.protocolService
.call(
SVC_TYPE_STATUS,
SSVC_TYPE_STATUS_SUBSCRIPT_REQ,
...encodeSubscribe(req)
)
.pipe(
take(1),
map(res => {
return decodeSubscribe(res);
})
);
}
/**
* Only Use 1:1 Chat Room and must be using subscribe method.
* @param req UnSubscribeRequest
*/
public unSubscribe(req: UnSubscribeRequest): void {
return this.protocolService.send(
SVC_TYPE_STATUS,
SSVC_TYPE_STATUS_UNSUBSCRIPT_REQ,
...encodeUnSubscribe(req)
);
}
}

View File

@ -0,0 +1,5 @@
export enum MessageIndexType {
First = 1,
Second = 2,
Third = 3
}

View File

@ -0,0 +1,18 @@
export const SVC_TYPE_STATUS = 3; // 상태
export const SSVC_TYPE_STATUS_REQ = 1; // 상태변경 요청
export const SSVC_TYPE_STATUS_RES = 2; // 상태변경 응답
export const SSVC_TYPE_STATUS_NOTI = 3; // 상태변경 알림
export const SSVC_TYPE_STATUS_BUDDY_REQ = 11; // 친구상태정보요청
export const SSVC_TYPE_STATUS_BUDDY_RES = 12; // 친구상태정보응답
export const SSVC_TYPE_STATUS_SUBSCRIPT_REQ = 31; // 구독 요청
export const SSVC_TYPE_STATUS_SUBSCRIPT_DATA = 32; // 구독 요청한 사용자상태
export const SSVC_TYPE_STATUS_SUBSCRIPT_RES = 33; // 구독 응답
export const SSVC_TYPE_STATUS_UNSUBSCRIPT_REQ = 34; // 구독 해지 요청
export const SSVC_TYPE_STATUS_UNSUBSCRIPT_RES = 35; // 구독 해지 응답
export const SSVC_TYPE_STATUS_MSG_UPD_REQ = 41; // 상태 메시지 요청
export const SSVC_TYPE_STATUS_MSG_UPD_RES = 42; // 상태 메시지 응답
export const SSVC_TYPE_STATUS_BULK_REQ = 51; // 상태변경 Bulk 요청
export const SSVC_TYPE_STATUS_BULK_RES = 53; // 상태변경 Bulk 응답
export const SSVC_TYPE_STATUS_BULK_INFO_REQ = 54; // 상태정보요청 Bulk 요청
export const SSVC_TYPE_STATUS_BULK_INFO_DATA = 55; // 상태정보요청 Bulk 정보
export const SSVC_TYPE_STATUS_BULK_INFO_RES = 56; // 상태정보요청 Bulk 응답

View File

@ -0,0 +1,25 @@
export enum TerminalStatusInfo {
// TERMINAL_STATE_UNKNOWN 0
Unknown = 'TERMINAL_STATE_UNKNOWN',
// TERMINAL_STATE_IDLE 1
Idle = 'TERMINAL_STATE_IDLE',
// TERMINAL_STATE_BUSY 2
Busy = 'TERMINAL_STATE_BUSY',
// TERMINAL_STATE_HELD 3
Held = 'TERMINAL_STATE_HELD',
// TERMINAL_STATE_ALERTING 4
Alerting = 'TERMINAL_STATE_ALERTING'
}
export enum TerminalStatusNumber {
// TERMINAL_STATE_UNKNOWN 0
Unknown = 0,
// TERMINAL_STATE_IDLE 1
Idle = 1,
// TERMINAL_STATE_BUSY 2
Busy = 2,
// TERMINAL_STATE_HELD 3
Held = 3,
// TERMINAL_STATE_ALERTING 4
Alerting = 4
}

View File

@ -2,6 +2,17 @@
* Public API Surface of ucap-webmessenger-protocol-status
*/
export * from './lib/models/buddy';
export * from './lib/models/bulk';
export * from './lib/models/message-update';
export * from './lib/models/status';
export * from './lib/models/subscribe';
export * from './lib/models/unsubscribe';
export * from './lib/services/status-protocol.service';
export * from './lib/types/message-index.type';
export * from './lib/types/service';
export * from './lib/types/terminal-status.type';
export * from './lib/ucap-status-protocol.module';