diff --git a/projects/ucap-webmessenger-protocol-room/src/lib/models/room-invite.ts b/projects/ucap-webmessenger-protocol-room/src/lib/models/room-invite.ts new file mode 100644 index 00000000..8be64b05 --- /dev/null +++ b/projects/ucap-webmessenger-protocol-room/src/lib/models/room-invite.ts @@ -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 = ( + 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 = ( + message: ProtocolMessage +) => { + return { + roomSeq: message.bodyList[0] + } as RoomInviteResponse; +}; + +export const decodeRoomInviteNotification: ProtocolDecoder< + RoomInviteResponse +> = (message: ProtocolMessage) => { + return { + roomSeq: message.bodyList[0] + } as RoomInviteResponse; +}; diff --git a/projects/ucap-webmessenger-protocol-room/src/lib/services/room-protocol.service.ts b/projects/ucap-webmessenger-protocol-room/src/lib/services/room-protocol.service.ts index af9438c3..a4e58029 100644 --- a/projects/ucap-webmessenger-protocol-room/src/lib/services/room-protocol.service.ts +++ b/projects/ucap-webmessenger-protocol-room/src/lib/services/room-protocol.service.ts @@ -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 { + return this.protocolService + .call(SVC_TYPE_ROOM, SSVC_TYPE_ROOM_INVITE_REQ, ...encodeRoomInvite(req)) + .pipe( + take(1), + map(res => decodeRoomInvite(res)) + ); + } }