added protocol > FILE

This commit is contained in:
leejh 2019-09-27 12:05:55 +09:00
parent 5141de66c1
commit d26b4a694b
6 changed files with 276 additions and 1 deletions

View File

@ -0,0 +1,37 @@
import { LocaleCode } from '@ucap-webmessenger/core';
import {
ProtocolRequest,
ProtocolResponse,
ProtocolEncoder,
PacketBody,
PacketBodyValue,
ProtocolDecoder,
ProtocolMessage
} from '@ucap-webmessenger/protocol';
export interface DownCheckRequest extends ProtocolRequest {
// 파일SEQ
seq: number;
}
export interface DownCheckResponse extends ProtocolResponse {
// 파일SEQ
seq: number;
}
export const encodeDownCheck: ProtocolEncoder<DownCheckRequest> = (
req: DownCheckRequest
) => {
const bodyList: PacketBody[] = [];
bodyList.push({ type: PacketBodyValue.Integer, value: req.seq });
return bodyList;
};
export const decodeDownCheck: ProtocolDecoder<DownCheckResponse> = (
message: ProtocolMessage
) => {
return {
seq: message.bodyList[0]
} as DownCheckResponse;
};

View File

@ -0,0 +1,144 @@
import {
ProtocolRequest,
ProtocolResponse,
ProtocolEncoder,
PacketBody,
PacketBodyValue,
ProtocolDecoder,
ProtocolMessage,
BodyStringDivider,
ProtocolStream
} from '@ucap-webmessenger/protocol';
import { FileType } from '../types/file.type';
export interface InfoRequest extends ProtocolRequest {
// 대화방SEQ(s)
roomSeq: string;
// { 파일타입 } cf) I : 이미지 V: 동영상 F: 파일 "" 빈값이면 모든 타입을 내려줌
type: FileType;
}
export interface FileInfo {
// 대화방SEQ
roomSeq: string;
// 이벤트SEQ
eventSeq: number;
// 파일SEQ
seq: number;
// 송신자SEQ
senderSeq: number;
// 파일타입
type: FileType;
// 파일이름
name: string;
// 파일URL
url: string;
// 파일크기(byte)
size: number;
// 전송일시
sendDate: string;
// 수신완료자수
receivedUserCount: number;
// 수신자수
receiverCount: number;
}
export interface InfoData extends ProtocolStream {
// { 대화방파일정보 }...
fileInfos: FileInfo[];
}
export interface FileDownloadInfo {
// 대화방SEQ
roomSeq: string;
// 파일SEQ
seq: number;
// 사용자SEQ
userSeq: number;
// 사용자명
userName: string;
// 다운로드일시
downloadDate: string;
// DownYN
isDownload: boolean;
}
export interface InfoCheckData extends ProtocolStream {
// { 파일다운로드정보 }...
fileDownloadInfos: FileDownloadInfo[];
}
export interface InfoResponse extends ProtocolResponse {
// 대화방SEQ(s)
roomSeq: string;
// { 파일타입 } cf) I : 이미지 V: 동영상 F: 파일 "" 빈값이면 모든 타입을 내려줌
type: FileType;
}
export const encodeInfo: ProtocolEncoder<InfoRequest> = (req: InfoRequest) => {
const bodyList: PacketBody[] = [];
bodyList.push(
{ type: PacketBodyValue.String, value: req.roomSeq },
{ type: PacketBodyValue.String, value: req.type }
);
return bodyList;
};
export const decodeInfoData: ProtocolDecoder<InfoData> = (
message: ProtocolMessage
) => {
const fileInfos: FileInfo[] = [];
message.bodyList.forEach(fileInfo => {
const info = fileInfo.split(BodyStringDivider);
let i = 0;
fileInfos.push({
roomSeq: info[i],
eventSeq: Number(info[i++]),
seq: Number(info[i++]),
senderSeq: Number(info[i++]),
type: info[i++] as FileType,
name: info[i++],
url: info[i++],
size: info[i++],
sendDate: info[i++],
receivedUserCount: Number(info[i++]),
receiverCount: Number(info[i++])
});
});
return {
fileInfos
} as InfoData;
};
export const decodeInfoCheckData: ProtocolDecoder<InfoCheckData> = (
message: ProtocolMessage
) => {
const fileDownloadInfos: FileDownloadInfo[] = [];
message.bodyList.forEach(fileInfo => {
const info = fileInfo.split(BodyStringDivider);
let i = 0;
fileDownloadInfos.push({
roomSeq: info[i],
seq: Number(info[i++]),
userSeq: Number(info[i++]),
userName: info[i++],
downloadDate: info[i++],
isDownload: info[i++] === 'Y' ? true : false
});
});
return {
fileDownloadInfos
} as InfoCheckData;
};
export const decodeInfo: ProtocolDecoder<InfoResponse> = (
message: ProtocolMessage
) => {
return {
roomSeq: message.bodyList[0],
type: message.bodyList[1] as FileType
} as InfoResponse;
};

View File

@ -1,8 +1,79 @@
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { map, takeWhile, take } from 'rxjs/operators';
import { ProtocolService } from '@ucap-webmessenger/protocol';
import {
SSVC_TYPE_FILE_INFO_REQ,
SVC_TYPE_FILE,
SSVC_TYPE_FILE_INFO_RES,
SSVC_TYPE_FILE_INFO_DATA,
SSVC_TYPE_FILE_INFO_CHECK_DATA,
SSVC_TYPE_FILE_DOWN_CHECK_REQ
} from '../types/service';
import {
InfoRequest,
InfoResponse,
encodeInfo,
decodeInfo,
InfoData,
InfoCheckData,
decodeInfoData,
decodeInfoCheckData
} from '../models/info';
import {
DownCheckRequest,
DownCheckResponse,
encodeDownCheck,
decodeDownCheck
} from '../models/down-check';
@Injectable({
providedIn: 'root'
})
export class FileProtocolService {
constructor() {}
constructor(private protocolService: ProtocolService) {}
public info(
req: InfoRequest
): Observable<InfoResponse | InfoData | InfoCheckData> {
return this.protocolService
.call(SVC_TYPE_FILE, SSVC_TYPE_FILE_INFO_REQ, ...encodeInfo(req))
.pipe(
takeWhile(res => SSVC_TYPE_FILE_INFO_RES !== res.subServiceType, true),
map(res => {
if (SSVC_TYPE_FILE_INFO_DATA === res.subServiceType) {
return {
...decodeInfoData(res),
Type: SSVC_TYPE_FILE_INFO_DATA
};
} else if (SSVC_TYPE_FILE_INFO_CHECK_DATA === res.subServiceType) {
return {
...decodeInfoCheckData(res),
Type: SSVC_TYPE_FILE_INFO_CHECK_DATA
};
}
return {
...decodeInfo(res),
Type: SSVC_TYPE_FILE_INFO_RES
};
})
);
}
public downCheck(req: DownCheckRequest): Observable<DownCheckResponse> {
return this.protocolService
.call(
SVC_TYPE_FILE,
SSVC_TYPE_FILE_DOWN_CHECK_REQ,
...encodeDownCheck(req)
)
.pipe(
take(1),
map(res => {
return decodeDownCheck(res);
})
);
}
}

View File

@ -0,0 +1,10 @@
export enum FileType {
// I : 이미지
Image = 'I',
// V : 동영상
Video = 'V',
// F : 파일
File = 'F',
// "" 빈값이면 모든 타입을 내려줌
All = ''
}

View File

@ -0,0 +1,7 @@
export const SVC_TYPE_FILE = 53; // File
export const SSVC_TYPE_FILE_INFO_REQ = 1; // File 정보 전송 요청
export const SSVC_TYPE_FILE_INFO_DATA = 2; // File 정보 Data
export const SSVC_TYPE_FILE_INFO_CHECK_DATA = 3; // File 다운로드 체크 Data
export const SSVC_TYPE_FILE_INFO_RES = 4; // File 정보 전송 응답
export const SSVC_TYPE_FILE_DOWN_CHECK_REQ = 11; // File 다운로드 완료 요청
export const SSVC_TYPE_FILE_DOWN_CHECK_RES = 12; // File 다운로드 완료 응답

View File

@ -2,6 +2,12 @@
* Public API Surface of ucap-webmessenger-protocol-file
*/
export * from './lib/models/down-check';
export * from './lib/models/info';
export * from './lib/services/file-protocol.service';
export * from './lib/types/file.type';
export * from './lib/types/service';
export * from './lib/ucap-file-protocol.module';