2019-09-18 15:02:21 +09:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
|
2019-10-10 10:43:06 +09:00
|
|
|
import { Observable, Subject } from 'rxjs';
|
|
|
|
import { map, take, takeWhile, share, tap, filter } from 'rxjs/operators';
|
2019-09-23 14:38:22 +09:00
|
|
|
|
|
|
|
import { ProtocolService } from '@ucap-webmessenger/protocol';
|
|
|
|
import {
|
|
|
|
SVC_TYPE_ROOM,
|
|
|
|
SSVC_TYPE_ROOM_OPEN_REQ,
|
|
|
|
SSVC_TYPE_ROOM_OPEN2_REQ,
|
|
|
|
SSVC_TYPE_ROOM_OPEN3_REQ,
|
2019-09-23 15:18:17 +09:00
|
|
|
SSVC_TYPE_ROOM_OPEN4_REQ,
|
2019-09-23 17:00:05 +09:00
|
|
|
SSVC_TYPE_ROOM_INVITE_REQ,
|
|
|
|
SSVC_TYPE_ROOM_INFO_ROOM,
|
|
|
|
SSVC_TYPE_ROOM_INFO_RES,
|
|
|
|
SSVC_TYPE_ROOM_INFO_REQ,
|
|
|
|
SSVC_TYPE_ROOM_INFO_USER,
|
2019-09-25 13:21:07 +09:00
|
|
|
SSVC_TYPE_ROOM_INFO_USER2,
|
|
|
|
SSVC_TYPE_ROOM_EXIT_REQ,
|
|
|
|
SSVC_TYPE_ROOM_EXIT_ALL_REQ,
|
|
|
|
SSVC_TYPE_ROOM_EXIT_FORCING_REQ,
|
|
|
|
SSVC_TYPE_ROOM_USER_STATUS_REQ,
|
|
|
|
SSVC_TYPE_ROOM_UPD_REQ,
|
|
|
|
SSVC_TYPE_ROOM_INFO_UPD_REQ,
|
2019-10-10 10:43:06 +09:00
|
|
|
SSVC_TYPE_ROOM_FONT_UPD_REQ,
|
|
|
|
SSVC_TYPE_ROOM_INVITE_NOTI,
|
|
|
|
SSVC_TYPE_ROOM_EXIT_NOTI,
|
|
|
|
SSVC_TYPE_ROOM_EXIT_FORCING_NOTI,
|
|
|
|
SSVC_TYPE_ROOM_FONT_UPD_NOTI
|
2019-09-23 14:38:22 +09:00
|
|
|
} from '../types/service';
|
|
|
|
import {
|
2019-09-25 16:13:33 +09:00
|
|
|
OpenRequest,
|
|
|
|
encodeOpen,
|
|
|
|
decodeOpen,
|
|
|
|
OpenResponse,
|
|
|
|
Open2Request,
|
|
|
|
Open2Response,
|
|
|
|
decodeOpen2,
|
|
|
|
encodeOpen2,
|
|
|
|
Open3Request,
|
|
|
|
Open3Response,
|
|
|
|
encodeOpen3,
|
|
|
|
decodeOpen3,
|
|
|
|
Open4Request,
|
|
|
|
Open4Response,
|
|
|
|
encodeOpen4,
|
|
|
|
decodeOpen4
|
2019-10-07 10:08:14 +09:00
|
|
|
} from '../protocols/open';
|
2019-09-23 15:18:17 +09:00
|
|
|
import {
|
2019-09-25 16:13:33 +09:00
|
|
|
InviteRequest,
|
|
|
|
InviteResponse,
|
|
|
|
encodeInvite,
|
2019-10-10 10:43:06 +09:00
|
|
|
decodeInvite,
|
|
|
|
decodeInviteNotification,
|
|
|
|
InviteNotification
|
2019-10-07 10:08:14 +09:00
|
|
|
} from '../protocols/invite';
|
2019-09-23 17:00:05 +09:00
|
|
|
import {
|
2019-09-25 16:13:33 +09:00
|
|
|
InfoRequest,
|
|
|
|
InfoResponse,
|
|
|
|
InfoData,
|
|
|
|
UserShortData,
|
|
|
|
UserData,
|
|
|
|
encodeInfo,
|
|
|
|
decodeInfoData,
|
|
|
|
decodeInfo,
|
|
|
|
decodeUserShortData,
|
|
|
|
decodeUserData,
|
|
|
|
UserStatusOfflineRequest,
|
|
|
|
UserStatusOfflineResponse,
|
|
|
|
encodeUserStatusOffline,
|
|
|
|
decodeUserStatusOffline
|
2019-10-07 10:08:14 +09:00
|
|
|
} from '../protocols/info';
|
2019-09-25 13:21:07 +09:00
|
|
|
import {
|
2019-09-25 16:13:33 +09:00
|
|
|
ExitRequest,
|
|
|
|
ExitResponse,
|
|
|
|
encodeExit,
|
|
|
|
decodeExit,
|
|
|
|
ExitAllRequest,
|
|
|
|
encodeAllExit,
|
|
|
|
ExitForcingRequest,
|
|
|
|
ExitForcingResponse,
|
|
|
|
encodeExitForcing,
|
2019-09-25 17:33:44 +09:00
|
|
|
decodeExitForcing,
|
|
|
|
decodeAllExit,
|
2019-10-10 10:43:06 +09:00
|
|
|
ExitAllResponse,
|
|
|
|
decodeExitForcingNotification,
|
|
|
|
decodeExitNotification,
|
|
|
|
ExitNotification,
|
|
|
|
ExitForcingNotification
|
2019-10-07 10:08:14 +09:00
|
|
|
} from '../protocols/exit';
|
2019-09-25 13:21:07 +09:00
|
|
|
import {
|
2019-09-25 16:13:33 +09:00
|
|
|
UpdateRequest,
|
|
|
|
UpdateResponse,
|
|
|
|
encodeUpdate,
|
|
|
|
decodeUpdate,
|
|
|
|
UpdateTimerSetRequest,
|
|
|
|
UpdateTimerSetResponse,
|
|
|
|
encodeUpdateTimerSet,
|
|
|
|
decodeUpdateTimerSet,
|
|
|
|
UpdateFontRequest,
|
|
|
|
UpdateFontResponse,
|
|
|
|
encodeUpdateFont,
|
2019-10-10 10:43:06 +09:00
|
|
|
decodeUpdateFont,
|
|
|
|
decodeUpdateFontNotification,
|
|
|
|
UpdateFontNotification
|
2019-10-07 10:08:14 +09:00
|
|
|
} from '../protocols/update';
|
2019-09-23 14:38:22 +09:00
|
|
|
|
2019-10-10 10:43:06 +09:00
|
|
|
type Notifications =
|
|
|
|
| UpdateFontNotification
|
|
|
|
| InviteNotification
|
|
|
|
| ExitNotification
|
|
|
|
| ExitForcingNotification;
|
|
|
|
|
2019-09-18 15:02:21 +09:00
|
|
|
@Injectable({
|
|
|
|
providedIn: 'root'
|
|
|
|
})
|
|
|
|
export class RoomProtocolService {
|
2019-10-10 10:43:06 +09:00
|
|
|
private notificationSubject: Subject<Notifications>;
|
|
|
|
public notification$: Observable<Notifications>;
|
|
|
|
|
|
|
|
constructor(private protocolService: ProtocolService) {
|
|
|
|
this.notificationSubject = new Subject();
|
|
|
|
this.notification$ = this.notificationSubject.asObservable().pipe(share());
|
|
|
|
|
|
|
|
this.protocolService.serverMessage
|
|
|
|
.pipe(
|
|
|
|
filter(message => message.serviceType === SVC_TYPE_ROOM),
|
|
|
|
tap(message => {
|
|
|
|
switch (message.subServiceType) {
|
|
|
|
case SSVC_TYPE_ROOM_INVITE_NOTI:
|
|
|
|
{
|
|
|
|
this.notificationSubject.next({
|
|
|
|
...decodeInviteNotification(message),
|
|
|
|
Type: SSVC_TYPE_ROOM_INVITE_NOTI
|
|
|
|
});
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SSVC_TYPE_ROOM_EXIT_NOTI:
|
|
|
|
{
|
|
|
|
this.notificationSubject.next({
|
|
|
|
...decodeExitNotification(message),
|
|
|
|
Type: SSVC_TYPE_ROOM_EXIT_NOTI
|
|
|
|
});
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SSVC_TYPE_ROOM_EXIT_FORCING_NOTI:
|
|
|
|
{
|
|
|
|
this.notificationSubject.next({
|
|
|
|
...decodeExitForcingNotification(message),
|
|
|
|
Type: SSVC_TYPE_ROOM_EXIT_FORCING_NOTI
|
|
|
|
});
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SSVC_TYPE_ROOM_FONT_UPD_NOTI:
|
|
|
|
{
|
|
|
|
this.notificationSubject.next({
|
|
|
|
...decodeUpdateFontNotification(message),
|
|
|
|
Type: SSVC_TYPE_ROOM_FONT_UPD_NOTI
|
|
|
|
});
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.subscribe();
|
|
|
|
}
|
2019-09-23 14:38:22 +09:00
|
|
|
|
2019-09-25 16:13:33 +09:00
|
|
|
public open(req: OpenRequest): Observable<OpenResponse> {
|
2019-09-23 14:38:22 +09:00
|
|
|
return this.protocolService
|
2019-09-25 16:13:33 +09:00
|
|
|
.call(SVC_TYPE_ROOM, SSVC_TYPE_ROOM_OPEN_REQ, ...encodeOpen(req))
|
2019-09-23 15:17:48 +09:00
|
|
|
.pipe(
|
|
|
|
take(1),
|
2019-09-25 16:13:33 +09:00
|
|
|
map(res => decodeOpen(res))
|
2019-09-23 15:17:48 +09:00
|
|
|
);
|
2019-09-23 14:38:22 +09:00
|
|
|
}
|
2019-09-25 16:13:33 +09:00
|
|
|
public open2(req: Open2Request): Observable<Open2Response> {
|
2019-09-23 14:38:22 +09:00
|
|
|
return this.protocolService
|
2019-09-25 16:13:33 +09:00
|
|
|
.call(SVC_TYPE_ROOM, SSVC_TYPE_ROOM_OPEN2_REQ, ...encodeOpen2(req))
|
2019-09-23 15:17:48 +09:00
|
|
|
.pipe(
|
|
|
|
take(1),
|
2019-09-25 16:13:33 +09:00
|
|
|
map(res => decodeOpen2(res))
|
2019-09-23 15:17:48 +09:00
|
|
|
);
|
2019-09-23 14:38:22 +09:00
|
|
|
}
|
2019-09-25 16:13:33 +09:00
|
|
|
public open3(req: Open3Request): Observable<Open3Response> {
|
2019-09-23 14:38:22 +09:00
|
|
|
return this.protocolService
|
2019-09-25 16:13:33 +09:00
|
|
|
.call(SVC_TYPE_ROOM, SSVC_TYPE_ROOM_OPEN3_REQ, ...encodeOpen3(req))
|
2019-09-23 15:17:48 +09:00
|
|
|
.pipe(
|
|
|
|
take(1),
|
2019-09-25 16:13:33 +09:00
|
|
|
map(res => decodeOpen3(res))
|
2019-09-23 15:17:48 +09:00
|
|
|
);
|
2019-09-23 14:38:22 +09:00
|
|
|
}
|
2019-09-25 16:13:33 +09:00
|
|
|
public open4(req: Open4Request): Observable<Open4Response> {
|
2019-09-23 14:38:22 +09:00
|
|
|
return this.protocolService
|
2019-09-25 16:13:33 +09:00
|
|
|
.call(SVC_TYPE_ROOM, SSVC_TYPE_ROOM_OPEN4_REQ, ...encodeOpen4(req))
|
2019-09-23 15:17:48 +09:00
|
|
|
.pipe(
|
|
|
|
take(1),
|
2019-09-25 16:13:33 +09:00
|
|
|
map(res => decodeOpen4(res))
|
2019-09-23 15:17:48 +09:00
|
|
|
);
|
2019-09-23 14:38:22 +09:00
|
|
|
}
|
2019-09-23 15:18:17 +09:00
|
|
|
|
2019-09-25 16:13:33 +09:00
|
|
|
public invite(req: InviteRequest): Observable<InviteResponse> {
|
2019-09-23 15:18:17 +09:00
|
|
|
return this.protocolService
|
2019-09-25 16:13:33 +09:00
|
|
|
.call(SVC_TYPE_ROOM, SSVC_TYPE_ROOM_INVITE_REQ, ...encodeInvite(req))
|
2019-09-23 15:18:17 +09:00
|
|
|
.pipe(
|
|
|
|
take(1),
|
2019-09-25 16:13:33 +09:00
|
|
|
map(res => decodeInvite(res))
|
2019-09-23 15:18:17 +09:00
|
|
|
);
|
|
|
|
}
|
2019-09-23 17:00:05 +09:00
|
|
|
|
2019-09-25 16:13:33 +09:00
|
|
|
public info(
|
|
|
|
req: InfoRequest
|
|
|
|
): Observable<InfoResponse | InfoData | UserShortData | UserData> {
|
2019-09-23 17:00:05 +09:00
|
|
|
return this.protocolService
|
2019-09-25 16:13:33 +09:00
|
|
|
.call(SVC_TYPE_ROOM, SSVC_TYPE_ROOM_INFO_REQ, ...encodeInfo(req))
|
2019-09-23 17:00:05 +09:00
|
|
|
.pipe(
|
2019-09-25 15:35:06 +09:00
|
|
|
takeWhile(res => SSVC_TYPE_ROOM_INFO_RES !== res.subServiceType, true),
|
2019-09-23 17:00:05 +09:00
|
|
|
map(res => {
|
|
|
|
if (SSVC_TYPE_ROOM_INFO_ROOM === res.subServiceType) {
|
2019-09-25 16:13:33 +09:00
|
|
|
return { ...decodeInfoData(res), Type: SSVC_TYPE_ROOM_INFO_ROOM };
|
2019-09-23 17:00:05 +09:00
|
|
|
} else if (SSVC_TYPE_ROOM_INFO_USER === res.subServiceType) {
|
2019-09-25 16:13:33 +09:00
|
|
|
return {
|
|
|
|
...decodeUserShortData(res),
|
|
|
|
Type: SSVC_TYPE_ROOM_INFO_USER
|
|
|
|
};
|
2019-09-23 17:00:05 +09:00
|
|
|
} else if (SSVC_TYPE_ROOM_INFO_USER2 === res.subServiceType) {
|
2019-09-25 16:13:33 +09:00
|
|
|
return { ...decodeUserData(res), Type: SSVC_TYPE_ROOM_INFO_USER2 };
|
2019-09-23 17:00:05 +09:00
|
|
|
}
|
|
|
|
|
2019-09-25 16:13:33 +09:00
|
|
|
return { ...decodeInfo(res), Type: SSVC_TYPE_ROOM_INFO_RES };
|
2019-09-23 17:00:05 +09:00
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2019-09-25 16:13:33 +09:00
|
|
|
public userStatusOffline(
|
|
|
|
req: UserStatusOfflineRequest
|
|
|
|
): Observable<UserStatusOfflineResponse> {
|
2019-09-25 13:21:07 +09:00
|
|
|
return this.protocolService
|
|
|
|
.call(
|
|
|
|
SVC_TYPE_ROOM,
|
|
|
|
SSVC_TYPE_ROOM_USER_STATUS_REQ,
|
2019-09-25 16:13:33 +09:00
|
|
|
...encodeUserStatusOffline(req)
|
2019-09-25 13:21:07 +09:00
|
|
|
)
|
|
|
|
.pipe(
|
2019-09-25 17:33:44 +09:00
|
|
|
take(1),
|
2019-09-25 13:21:07 +09:00
|
|
|
map(res => {
|
2019-09-25 16:13:33 +09:00
|
|
|
return decodeUserStatusOffline(res);
|
2019-09-25 13:21:07 +09:00
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-09-25 16:13:33 +09:00
|
|
|
public exit(req: ExitRequest): Observable<ExitResponse> {
|
2019-09-25 13:21:07 +09:00
|
|
|
return this.protocolService
|
2019-09-25 16:13:33 +09:00
|
|
|
.call(SVC_TYPE_ROOM, SSVC_TYPE_ROOM_EXIT_REQ, ...encodeExit(req))
|
2019-09-25 13:21:07 +09:00
|
|
|
.pipe(
|
2019-09-25 17:33:44 +09:00
|
|
|
take(1),
|
2019-09-25 13:21:07 +09:00
|
|
|
map(res => {
|
2019-09-25 16:13:33 +09:00
|
|
|
return decodeExit(res);
|
2019-09-25 13:21:07 +09:00
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2019-09-25 17:33:44 +09:00
|
|
|
public exitAll(req: ExitAllRequest): Observable<ExitAllResponse> {
|
2019-09-25 13:21:07 +09:00
|
|
|
return this.protocolService
|
2019-09-25 16:13:33 +09:00
|
|
|
.call(SVC_TYPE_ROOM, SSVC_TYPE_ROOM_EXIT_ALL_REQ, ...encodeAllExit(req))
|
2019-09-25 13:21:07 +09:00
|
|
|
.pipe(
|
2019-09-25 17:33:44 +09:00
|
|
|
take(1),
|
2019-09-25 13:21:07 +09:00
|
|
|
map(res => {
|
2019-09-25 17:33:44 +09:00
|
|
|
return decodeAllExit(res);
|
2019-09-25 13:21:07 +09:00
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2019-09-25 16:13:33 +09:00
|
|
|
public exitForcing(req: ExitForcingRequest): Observable<ExitForcingResponse> {
|
2019-09-25 13:21:07 +09:00
|
|
|
return this.protocolService
|
|
|
|
.call(
|
|
|
|
SVC_TYPE_ROOM,
|
|
|
|
SSVC_TYPE_ROOM_EXIT_FORCING_REQ,
|
2019-09-25 16:13:33 +09:00
|
|
|
...encodeExitForcing(req)
|
2019-09-25 13:21:07 +09:00
|
|
|
)
|
|
|
|
.pipe(
|
2019-09-25 17:33:44 +09:00
|
|
|
take(1),
|
2019-09-25 13:21:07 +09:00
|
|
|
map(res => {
|
2019-09-25 16:13:33 +09:00
|
|
|
return decodeExitForcing(res);
|
2019-09-25 13:21:07 +09:00
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-09-25 16:13:33 +09:00
|
|
|
public update(req: UpdateRequest): Observable<UpdateResponse> {
|
2019-09-25 13:21:07 +09:00
|
|
|
return this.protocolService
|
2019-09-25 16:13:33 +09:00
|
|
|
.call(SVC_TYPE_ROOM, SSVC_TYPE_ROOM_UPD_REQ, ...encodeUpdate(req))
|
2019-09-25 13:21:07 +09:00
|
|
|
.pipe(
|
2019-09-25 17:33:44 +09:00
|
|
|
take(1),
|
2019-09-25 13:21:07 +09:00
|
|
|
map(res => {
|
2019-09-25 16:13:33 +09:00
|
|
|
return decodeUpdate(res);
|
2019-09-25 13:21:07 +09:00
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2019-09-25 16:13:33 +09:00
|
|
|
public updateTimerSet(
|
|
|
|
req: UpdateTimerSetRequest
|
|
|
|
): Observable<UpdateTimerSetResponse> {
|
2019-09-25 13:21:07 +09:00
|
|
|
return this.protocolService
|
|
|
|
.call(
|
|
|
|
SVC_TYPE_ROOM,
|
|
|
|
SSVC_TYPE_ROOM_INFO_UPD_REQ,
|
2019-09-25 16:13:33 +09:00
|
|
|
...encodeUpdateTimerSet(req)
|
2019-09-25 13:21:07 +09:00
|
|
|
)
|
|
|
|
.pipe(
|
2019-09-25 17:33:44 +09:00
|
|
|
take(1),
|
2019-09-25 13:21:07 +09:00
|
|
|
map(res => {
|
2019-09-25 16:13:33 +09:00
|
|
|
return decodeUpdateTimerSet(res);
|
2019-09-25 13:21:07 +09:00
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2019-09-25 16:13:33 +09:00
|
|
|
public updateFont(req: UpdateFontRequest): Observable<UpdateFontResponse> {
|
2019-09-25 13:21:07 +09:00
|
|
|
return this.protocolService
|
|
|
|
.call(
|
|
|
|
SVC_TYPE_ROOM,
|
|
|
|
SSVC_TYPE_ROOM_FONT_UPD_REQ,
|
2019-09-25 16:13:33 +09:00
|
|
|
...encodeUpdateFont(req)
|
2019-09-25 13:21:07 +09:00
|
|
|
)
|
|
|
|
.pipe(
|
2019-09-25 17:33:44 +09:00
|
|
|
take(1),
|
2019-09-25 13:21:07 +09:00
|
|
|
map(res => {
|
2019-09-25 16:13:33 +09:00
|
|
|
return decodeUpdateFont(res);
|
2019-09-25 13:21:07 +09:00
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2019-09-18 15:02:21 +09:00
|
|
|
}
|