2019-09-26 15:31:19 +09:00
|
|
|
import {
|
|
|
|
ProtocolRequest,
|
|
|
|
ProtocolResponse,
|
|
|
|
ProtocolEncoder,
|
|
|
|
PacketBody,
|
|
|
|
PacketBodyValue,
|
|
|
|
ProtocolDecoder,
|
|
|
|
ProtocolMessage,
|
2019-10-10 12:14:01 +09:00
|
|
|
ProtocolNotification,
|
|
|
|
decodeProtocolMessage
|
2019-09-26 15:31:19 +09:00
|
|
|
} 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<UserRequest> = (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<UserResponse> = (
|
|
|
|
message: ProtocolMessage
|
|
|
|
) => {
|
2019-10-10 12:14:01 +09:00
|
|
|
return decodeProtocolMessage(message, {
|
2019-09-26 15:31:19 +09:00
|
|
|
type: message.bodyList[0] as UserInfoUpdateType,
|
|
|
|
info: message.bodyList[1]
|
2019-10-10 12:14:01 +09:00
|
|
|
} as UserResponse);
|
2019-09-26 15:31:19 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
export const decodeUserNotification: ProtocolDecoder<UserNotification> = (
|
|
|
|
message: ProtocolMessage
|
|
|
|
) => {
|
2019-10-10 12:14:01 +09:00
|
|
|
return decodeProtocolMessage(message, {
|
2019-09-26 15:31:19 +09:00
|
|
|
type: message.bodyList[0] as UserInfoUpdateType,
|
|
|
|
info: message.bodyList[1]
|
2019-10-10 12:14:01 +09:00
|
|
|
} as UserNotification);
|
2019-09-26 15:31:19 +09:00
|
|
|
};
|