diff --git a/projects/ucap-webmessenger-protocol-group/src/lib/models/group-add.ts b/projects/ucap-webmessenger-protocol-group/src/lib/models/group-add.ts new file mode 100644 index 00000000..0a6a51e4 --- /dev/null +++ b/projects/ucap-webmessenger-protocol-group/src/lib/models/group-add.ts @@ -0,0 +1,41 @@ +import { DeviceType, LocaleCode } from '@ucap-webmessenger/core'; +import { + ProtocolRequest, + ProtocolResponse, + ProtocolEncoder, + PacketBody, + PacketBodyValue, + ProtocolDecoder, + ProtocolMessage +} from '@ucap-webmessenger/protocol'; + +export interface GroupAddRequest extends ProtocolRequest { + // 0. 동료그룹이름 + groupName: string; +} + +export interface GroupAddResponse extends ProtocolResponse { + // 0: 동료그룹SEQ(n) + groupSeq: number; + // 1: 동료그룹이름(s) + groupName: string; +} + +export const encodeGroupAdd: ProtocolEncoder = ( + req: GroupAddRequest +) => { + const bodyList: PacketBody[] = []; + + bodyList.push({ type: PacketBodyValue.String, value: req.groupName }); + + return bodyList; +}; + +export const decodeGroupAdd: ProtocolDecoder = ( + message: ProtocolMessage +) => { + return { + groupSeq: message.bodyList[0], + groupName: message.bodyList[1] + } as GroupAddResponse; +}; diff --git a/projects/ucap-webmessenger-protocol-group/src/lib/models/group-del.ts b/projects/ucap-webmessenger-protocol-group/src/lib/models/group-del.ts new file mode 100644 index 00000000..1612aa6b --- /dev/null +++ b/projects/ucap-webmessenger-protocol-group/src/lib/models/group-del.ts @@ -0,0 +1,38 @@ +import { DeviceType, LocaleCode } from '@ucap-webmessenger/core'; +import { + ProtocolRequest, + ProtocolResponse, + ProtocolEncoder, + PacketBody, + PacketBodyValue, + ProtocolDecoder, + ProtocolMessage +} from '@ucap-webmessenger/protocol'; + +export interface GroupDelRequest extends ProtocolRequest { + // 0: 동료그룹SEQ(n) + groupSeq: number; +} + +export interface GroupDelResponse extends ProtocolResponse { + // 0: 동료그룹SEQ(n) + groupSeq: number; +} + +export const encodeGroupDel: ProtocolEncoder = ( + req: GroupDelRequest +) => { + const bodyList: PacketBody[] = []; + + bodyList.push({ type: PacketBodyValue.Integer, value: req.groupSeq }); + + return bodyList; +}; + +export const decodeGroupDel: ProtocolDecoder = ( + message: ProtocolMessage +) => { + return { + groupSeq: message.bodyList[0] + } as GroupDelResponse; +}; diff --git a/projects/ucap-webmessenger-protocol-group/src/lib/models/group-update.ts b/projects/ucap-webmessenger-protocol-group/src/lib/models/group-update.ts new file mode 100644 index 00000000..ba28ad7e --- /dev/null +++ b/projects/ucap-webmessenger-protocol-group/src/lib/models/group-update.ts @@ -0,0 +1,91 @@ +import { DeviceType, LocaleCode } from '@ucap-webmessenger/core'; +import { + ProtocolRequest, + ProtocolResponse, + ProtocolEncoder, + PacketBody, + PacketBodyValue, + ProtocolDecoder, + ProtocolMessage +} from '@ucap-webmessenger/protocol'; + +export interface GroupUpdateRequest extends ProtocolRequest { + // 0: 동료그룹SEQ(n) + groupSeq: number; + // 1: 동료그룹이름(s) + groupName: string; + // 2n: 사용자SEQ(n)... + userSeqs: []; +} + +export interface GroupUpdateResponse extends ProtocolResponse { + // 0: 동료그룹SEQ(n) + groupSeq: number; + // 1: 동료그룹이름(s) + groupName: string; + // 2n: 사용자SEQ(n)... + userSeqs: []; +} + +export const encodeGroupUpdate: ProtocolEncoder = ( + req: GroupUpdateRequest +) => { + const bodyList: PacketBody[] = []; + + bodyList.push( + { type: PacketBodyValue.Integer, value: req.groupSeq }, + { type: PacketBodyValue.String, value: req.groupName }, + { type: PacketBodyValue.String, value: req.userSeqs.join() } + ); + + return bodyList; +}; + +export const decodeGroupUpdate: ProtocolDecoder = ( + message: ProtocolMessage +) => { + let userSeqArray: Array = []; + if (message.bodyList.length > 2 && !message.bodyList[2].empty()) { + userSeqArray = message.bodyList[2].split(',').map(v => Number(v)); + } + + return { + groupSeq: message.bodyList[0], + groupName: message.bodyList[1], + userSeqs: userSeqArray + } as GroupUpdateResponse; +}; + +export const encodeGroupUpdate2: ProtocolEncoder = ( + req: GroupUpdateRequest +) => { + const bodyList: PacketBody[] = []; + + bodyList.push( + { type: PacketBodyValue.Integer, value: req.groupSeq }, + { type: PacketBodyValue.String, value: req.groupName } + ); + + if (req.userSeqs.length > 0) { + req.userSeqs.forEach(userSeq => { + bodyList.push({ type: PacketBodyValue.Integer, value: userSeq }); + }); + } + + return bodyList; +}; + +export const decodeGroupUpdate2: ProtocolDecoder = ( + message: ProtocolMessage +) => { + let userSeqArray: Array = []; + if (message.bodyList.length > 2) { + userSeqArray = message.bodyList.slice(2); + } + + return { + groupSeq: message.bodyList[0], + groupName: message.bodyList[1], + userSeqs: userSeqArray + } as GroupUpdateResponse; +}; diff --git a/projects/ucap-webmessenger-protocol-group/src/lib/services/group-protocol.service.ts b/projects/ucap-webmessenger-protocol-group/src/lib/services/group-protocol.service.ts index 20714e3c..59667652 100644 --- a/projects/ucap-webmessenger-protocol-group/src/lib/services/group-protocol.service.ts +++ b/projects/ucap-webmessenger-protocol-group/src/lib/services/group-protocol.service.ts @@ -1,8 +1,64 @@ import { Injectable } from '@angular/core'; +import { Observable } from 'rxjs'; +import { map } from 'rxjs/operators'; + +import { ProtocolService } from '@ucap-webmessenger/protocol'; +import { + GroupAddRequest, + encodeGroupAdd, + decodeGroupAdd +} from '../models/group-add'; +import { + SVC_TYPE_GROUP, + SSVC_TYPE_GROUP_ADD_REQ, + SSVC_TYPE_GROUP_DEL_REQ, + SSVC_TYPE_GROUP_UPD_REQ, + SSVC_TYPE_GROUP_UPD_REQ2 +} from '../types/service'; +import { + GroupDelRequest, + encodeGroupDel, + decodeGroupDel +} from '../models/group-del'; +import { + GroupUpdateRequest, + encodeGroupUpdate, + decodeGroupUpdate, + encodeGroupUpdate2, + decodeGroupUpdate2 +} from '../models/group-update'; @Injectable({ providedIn: 'root' }) export class GroupProtocolService { - constructor() {} + constructor(private protocolService: ProtocolService) {} + + public groupAdd(req: GroupAddRequest): Observable { + return this.protocolService + .call(SVC_TYPE_GROUP, SSVC_TYPE_GROUP_ADD_REQ, ...encodeGroupAdd(req)) + .pipe(map(res => decodeGroupAdd(res))); + } + + public groupDel(req: GroupDelRequest): Observable { + return this.protocolService + .call(SVC_TYPE_GROUP, SSVC_TYPE_GROUP_DEL_REQ, ...encodeGroupDel(req)) + .pipe(map(res => decodeGroupDel(res))); + } + + public groupUpdate(req: GroupUpdateRequest): Observable { + return this.protocolService + .call(SVC_TYPE_GROUP, SSVC_TYPE_GROUP_UPD_REQ, ...encodeGroupUpdate(req)) + .pipe(map(res => decodeGroupUpdate(res))); + } + + public groupUpdate2(req: GroupUpdateRequest): Observable { + return this.protocolService + .call( + SVC_TYPE_GROUP, + SSVC_TYPE_GROUP_UPD_REQ2, + ...encodeGroupUpdate2(req) + ) + .pipe(map(res => decodeGroupUpdate2(res))); + } } diff --git a/projects/ucap-webmessenger-protocol-group/src/lib/types/service.ts b/projects/ucap-webmessenger-protocol-group/src/lib/types/service.ts new file mode 100644 index 00000000..f986c8b2 --- /dev/null +++ b/projects/ucap-webmessenger-protocol-group/src/lib/types/service.ts @@ -0,0 +1,9 @@ +export const SVC_TYPE_GROUP = 5; // 동료 그룹 관리 +export const SSVC_TYPE_GROUP_ADD_REQ = 1; // 동료 그룹 추가 +export const SSVC_TYPE_GROUP_ADD_RES = 2; +export const SSVC_TYPE_GROUP_DEL_REQ = 11; // 동료 그룹 삭제 +export const SSVC_TYPE_GROUP_DEL_RES = 12; +export const SSVC_TYPE_GROUP_UPD_REQ = 21; // 동료 그룹 변경 +export const SSVC_TYPE_GROUP_UPD_RES = 22; +export const SSVC_TYPE_GROUP_UPD_REQ2 = 23; +export const SSVC_TYPE_GROUP_UPD_RES2 = 24;