diff --git a/projects/ucap-webmessenger-protocol-info/src/lib/models/status.ts b/projects/ucap-webmessenger-protocol-info/src/lib/models/status.ts new file mode 100644 index 00000000..f3b8cb53 --- /dev/null +++ b/projects/ucap-webmessenger-protocol-info/src/lib/models/status.ts @@ -0,0 +1,58 @@ +import { DeviceType, LocaleCode, StatusCode } from '@ucap-webmessenger/core'; +import { + ProtocolRequest, + ProtocolResponse, + ProtocolEncoder, + PacketBody, + PacketBodyValue, + ProtocolDecoder, + ProtocolMessage, + ProtocolNotification, + BodyStringDivider +} from '@ucap-webmessenger/protocol'; +import { UserInfoUpdateType } from '../types/user-info-update.type'; +import { StatusInfo } from '@ucap-webmessenger/protocol-status'; + +export interface StatusRequest extends ProtocolRequest { + // 사용자SEQ(n)... + userSeqs: number[]; +} + +export interface StatusResponse extends ProtocolResponse { + // {상태정보}... + statusInfos: StatusInfo[]; +} + +export const encodeStatus: ProtocolEncoder = ( + req: StatusRequest +) => { + const bodyList: PacketBody[] = []; + + req.userSeqs.forEach(userSeq => { + bodyList.push({ type: PacketBodyValue.Integer, value: userSeq }); + }); + return bodyList; +}; + +export const decodeStatus: ProtocolDecoder = ( + 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 StatusResponse; +}; diff --git a/projects/ucap-webmessenger-protocol-info/src/lib/models/user-option.ts b/projects/ucap-webmessenger-protocol-info/src/lib/models/user-option.ts new file mode 100644 index 00000000..96f1d82e --- /dev/null +++ b/projects/ucap-webmessenger-protocol-info/src/lib/models/user-option.ts @@ -0,0 +1,50 @@ +import { DeviceType, LocaleCode, CallerType } from '@ucap-webmessenger/core'; +import { + ProtocolRequest, + ProtocolResponse, + ProtocolEncoder, + PacketBody, + PacketBodyValue, + ProtocolDecoder, + ProtocolMessage, + ProtocolNotification +} from '@ucap-webmessenger/protocol'; +import { UserInfoUpdateType } from '../types/user-info-update.type'; + +export interface UserOptionResponse extends ProtocolResponse { + // 타입(s) + type: CallerType; +} + +export const decodeUserOption: ProtocolDecoder = ( + message: ProtocolMessage +) => { + return { type: message.bodyList[0] as CallerType } as UserOptionResponse; +}; + +export interface UserOptionUpdateRequest extends ProtocolRequest { + // 타입(s) + type: CallerType; +} + +export interface UserOptionUpdateResponse extends ProtocolResponse { + // 타입(s) + type: CallerType; +} + +export const encodeUserOptionUpdate: ProtocolEncoder< + UserOptionUpdateRequest +> = (req: UserOptionUpdateRequest) => { + const bodyList: PacketBody[] = []; + + bodyList.push({ type: PacketBodyValue.String, value: req.type }); + return bodyList; +}; + +export const decodeUserOptionUpdate: ProtocolDecoder< + UserOptionUpdateResponse +> = (message: ProtocolMessage) => { + return { + type: message.bodyList[0] as CallerType + } as UserOptionUpdateResponse; +}; diff --git a/projects/ucap-webmessenger-protocol-info/src/lib/models/user.ts b/projects/ucap-webmessenger-protocol-info/src/lib/models/user.ts new file mode 100644 index 00000000..ac6e9974 --- /dev/null +++ b/projects/ucap-webmessenger-protocol-info/src/lib/models/user.ts @@ -0,0 +1,62 @@ +import { DeviceType, LocaleCode } from '@ucap-webmessenger/core'; +import { + ProtocolRequest, + ProtocolResponse, + ProtocolEncoder, + PacketBody, + PacketBodyValue, + ProtocolDecoder, + ProtocolMessage, + ProtocolNotification +} from '@ucap-webmessenger/protocol'; +import { UserInfoUpdateType } from '../types/user-info-update.type'; + +export interface UserRequest extends ProtocolRequest { + // 타입(s) + type: UserInfoUpdateType; + // 정보(s) + info: string; +} + +export interface UserResponse extends ProtocolResponse { + // 타입(s) + type: UserInfoUpdateType; + // 정보(s) + info: string; +} + +export interface UserNotification extends ProtocolNotification { + // 타입(s) + type: UserInfoUpdateType; + // 정보(s) + info: string; +} + +export const encodeUser: ProtocolEncoder = (req: UserRequest) => { + const bodyList: PacketBody[] = []; + + bodyList.push( + { type: PacketBodyValue.String, value: req.type }, + { type: PacketBodyValue.String, value: req.info } + ); + + return bodyList; +}; + +export const decodeUser: ProtocolDecoder = ( + message: ProtocolMessage +) => { + return { + type: message.bodyList[0] as UserInfoUpdateType, + info: message.bodyList[1] + } as UserResponse; +}; + +export const decodeUserNotification: ProtocolDecoder = ( + message: ProtocolMessage +) => { + return { + type: message.bodyList[0] as UserInfoUpdateType, + info: message.bodyList[1] + } as UserNotification; +}; diff --git a/projects/ucap-webmessenger-protocol-info/src/lib/services/info-protocol.service.ts b/projects/ucap-webmessenger-protocol-info/src/lib/services/info-protocol.service.ts index 60575e70..11ef17d9 100644 --- a/projects/ucap-webmessenger-protocol-info/src/lib/services/info-protocol.service.ts +++ b/projects/ucap-webmessenger-protocol-info/src/lib/services/info-protocol.service.ts @@ -1,8 +1,82 @@ import { Injectable } from '@angular/core'; +import { Observable } from 'rxjs'; +import { map, take } from 'rxjs/operators'; + +import { ProtocolService } from '@ucap-webmessenger/protocol'; +import { + SVC_TYPE_INFO, + SSVC_TYPE_INFO_USER_REQ, + SSVC_TYPE_INFO_STATE_REQ, + SSVC_TYPE_INFO_USER_OPTION_REQ, + SSVC_TYPE_INFO_USER_OPTION_UPD_REQ +} from '../types/service'; +import { + UserRequest, + encodeUser, + UserResponse, + decodeUser +} from '../models/user'; +import { + StatusRequest, + StatusResponse, + encodeStatus, + decodeStatus +} from '../models/status'; +import { + UserOptionResponse, + decodeUserOption, + UserOptionUpdateRequest, + encodeUserOptionUpdate, + UserOptionUpdateResponse, + decodeUserOptionUpdate +} from '../models/user-option'; + @Injectable({ providedIn: 'root' }) export class InfoProtocolService { - constructor() {} + constructor(private protocolService: ProtocolService) {} + + public user(req: UserRequest): Observable { + return this.protocolService + .call(SVC_TYPE_INFO, SSVC_TYPE_INFO_USER_REQ, ...encodeUser(req)) + .pipe( + take(1), + map(res => decodeUser(res)) + ); + } + + public status(req: StatusRequest): Observable { + return this.protocolService + .call(SVC_TYPE_INFO, SSVC_TYPE_INFO_STATE_REQ, ...encodeStatus(req)) + .pipe( + take(1), + map(res => decodeStatus(res)) + ); + } + + public userOption(): Observable { + return this.protocolService + .call(SVC_TYPE_INFO, SSVC_TYPE_INFO_USER_OPTION_REQ) + .pipe( + take(1), + map(res => decodeUserOption(res)) + ); + } + + public userOptionUpdate( + req: UserOptionUpdateRequest + ): Observable { + return this.protocolService + .call( + SVC_TYPE_INFO, + SSVC_TYPE_INFO_USER_OPTION_UPD_REQ, + ...encodeUserOptionUpdate(req) + ) + .pipe( + take(1), + map(res => decodeUserOptionUpdate(res)) + ); + } } diff --git a/projects/ucap-webmessenger-protocol-info/src/lib/types/service.ts b/projects/ucap-webmessenger-protocol-info/src/lib/types/service.ts new file mode 100644 index 00000000..1f0841ba --- /dev/null +++ b/projects/ucap-webmessenger-protocol-info/src/lib/types/service.ts @@ -0,0 +1,14 @@ +export const SVC_TYPE_INFO = 30; +export const SSVC_TYPE_INFO_USER_REQ = 1; // 사용자 정보 변경 요청 +export const SSVC_TYPE_INFO_USER_RES = 2; +export const SSVC_TYPE_INFO_USER_NOTI = 3; +export const SSVC_TYPE_INFO_STATE_REQ = 11; // 사용자 상태 정보 요청 +export const SSVC_TYPE_INFO_STATE_RES = 13; // 사용자 상태 정보 응답 +export const SSVC_TYPE_INFO_USER_OPTION_REQ = 21; // 사용자 환경 정보 요청 +export const SSVC_TYPE_INFO_USER_OPTION_RES = 22; // 사용자 환경 정보 응답 +export const SSVC_TYPE_INFO_USER_OPTION_UPD_REQ = 23; // 사용자 환경 정보 변경 요청 +export const SSVC_TYPE_INFO_USER_OPTION_UPD_RES = 24; // 사용자 환경 정보 변경 응답 +export const SSVC_TYPE_INFO_QUERY_SESSION_REQ = 41; // 세션 정보 요청 +export const SSVC_TYPE_INFO_QUERY_SESSION_RES = 42; // 세션 정보 응답 +export const SSVC_TYPE_INFO_BUDDY_NICKNAME_REQ = 51; // 동료 닉네임 변경 요청 +export const SSVC_TYPE_INFO_BUDDY_NICKNAME_RES = 52; // 동료 닉네임 변경 응답 diff --git a/projects/ucap-webmessenger-protocol-info/src/lib/types/user-info-update.type.ts b/projects/ucap-webmessenger-protocol-info/src/lib/types/user-info-update.type.ts new file mode 100644 index 00000000..a2496524 --- /dev/null +++ b/projects/ucap-webmessenger-protocol-info/src/lib/types/user-info-update.type.ts @@ -0,0 +1,13 @@ +export enum UserInfoUpdateType { + // I: 프로필 이미지 + Image = 'I', + // R: 인트로소개 + Intro = 'R', + // T: 전화보이기여부 + TelephoneVisible = 'T' +} + +export enum TelephoneVisibleType { + Show = 'Y', + Hide = 'N' +} diff --git a/projects/ucap-webmessenger-protocol-info/src/public-api.ts b/projects/ucap-webmessenger-protocol-info/src/public-api.ts index dbba1927..07f45e4c 100644 --- a/projects/ucap-webmessenger-protocol-info/src/public-api.ts +++ b/projects/ucap-webmessenger-protocol-info/src/public-api.ts @@ -2,6 +2,13 @@ * Public API Surface of ucap-webmessenger-protocol-info */ +export * from './lib/models/status'; +export * from './lib/models/user-option'; +export * from './lib/models/user'; + export * from './lib/services/info-protocol.service'; +export * from './lib/types/service'; +export * from './lib/types/user-info-update.type'; + export * from './lib/ucap-info-protocol.module';