added protocol ROOM > INVITE

This commit is contained in:
leejh 2019-09-23 15:18:17 +09:00
parent 226af990b0
commit 8caf5bdc56
2 changed files with 67 additions and 1 deletions

View File

@ -0,0 +1,50 @@
import {
ProtocolRequest,
ProtocolResponse,
ProtocolEncoder,
PacketBody,
PacketBodyValue,
ProtocolDecoder,
ProtocolMessage
} from '@ucap-webmessenger/protocol';
export interface RoomInviteRequest extends ProtocolRequest {
// 0. 대화방SEQ(s)
roomSeq: string;
// 1n. 초대자 userSeq(n)...
inviteUserSeqs: number[];
}
export interface RoomInviteResponse extends ProtocolResponse {
// 0. 대화방SEQ(s)
roomSeq: string;
}
export const encodeRoomInvite: ProtocolEncoder<RoomInviteRequest> = (
req: RoomInviteRequest
) => {
const bodyList: PacketBody[] = [];
bodyList.push({ type: PacketBodyValue.String, value: req.roomSeq });
for (const userSeq of req.inviteUserSeqs) {
bodyList.push({ type: PacketBodyValue.Integer, value: userSeq });
}
return bodyList;
};
export const decodeRoomInvite: ProtocolDecoder<RoomInviteResponse> = (
message: ProtocolMessage
) => {
return {
roomSeq: message.bodyList[0]
} as RoomInviteResponse;
};
export const decodeRoomInviteNotification: ProtocolDecoder<
RoomInviteResponse
> = (message: ProtocolMessage) => {
return {
roomSeq: message.bodyList[0]
} as RoomInviteResponse;
};

View File

@ -9,7 +9,8 @@ import {
SSVC_TYPE_ROOM_OPEN_REQ,
SSVC_TYPE_ROOM_OPEN2_REQ,
SSVC_TYPE_ROOM_OPEN3_REQ,
SSVC_TYPE_ROOM_OPEN4_REQ
SSVC_TYPE_ROOM_OPEN4_REQ,
SSVC_TYPE_ROOM_INVITE_REQ
} from '../types/service';
import {
RoomOpenRequest,
@ -35,6 +36,12 @@ import {
encodeRoomOpen4,
decodeRoomOpen4
} from '../models/room-open4';
import {
RoomInviteRequest,
RoomInviteResponse,
encodeRoomInvite,
decodeRoomInvite
} from '../models/room-invite';
@Injectable({
providedIn: 'root'
@ -77,4 +84,13 @@ export class RoomProtocolService {
map(res => decodeRoomOpen4(res))
);
}
public roomInvite(req: RoomInviteRequest): Observable<RoomInviteResponse> {
return this.protocolService
.call(SVC_TYPE_ROOM, SSVC_TYPE_ROOM_INVITE_REQ, ...encodeRoomInvite(req))
.pipe(
take(1),
map(res => decodeRoomInvite(res))
);
}
}