2019-09-18 15:02:21 +09:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
|
2019-09-23 14:23:24 +09:00
|
|
|
import { Observable } from 'rxjs';
|
2019-09-23 18:09:04 +09:00
|
|
|
import { map, takeWhile, timeout, take } from 'rxjs/operators';
|
2019-09-23 14:23:24 +09:00
|
|
|
|
|
|
|
import { ProtocolService } from '@ucap-webmessenger/protocol';
|
|
|
|
|
|
|
|
import {
|
|
|
|
InfoRequest,
|
|
|
|
InfoResponse,
|
|
|
|
encodeInfo,
|
|
|
|
decodeInfo,
|
|
|
|
decodeInfoData,
|
|
|
|
InfoData
|
|
|
|
} from '../models/info';
|
|
|
|
import {
|
|
|
|
SVC_TYPE_EVENT,
|
|
|
|
SSVC_TYPE_EVENT_INFO_REQ,
|
|
|
|
SSVC_TYPE_EVENT_INFO_RES,
|
2019-09-23 18:09:04 +09:00
|
|
|
SSVC_TYPE_EVENT_INFO_DATA,
|
|
|
|
SSVC_TYPE_EVENT_SEND_REQ
|
2019-09-23 14:23:24 +09:00
|
|
|
} from '../types/service';
|
2019-09-23 18:09:04 +09:00
|
|
|
import {
|
2019-09-25 16:40:35 +09:00
|
|
|
SendRequest,
|
|
|
|
SendResponse,
|
|
|
|
decodeSend,
|
|
|
|
encodeSend
|
|
|
|
} from '../models/send';
|
2019-09-23 14:23:24 +09:00
|
|
|
|
2019-09-18 15:02:21 +09:00
|
|
|
@Injectable({
|
|
|
|
providedIn: 'root'
|
|
|
|
})
|
|
|
|
export class EventProtocolService {
|
2019-09-23 14:23:24 +09:00
|
|
|
constructor(private protocolService: ProtocolService) {}
|
|
|
|
|
|
|
|
public info(req: InfoRequest): Observable<InfoResponse | InfoData> {
|
|
|
|
return this.protocolService
|
|
|
|
.call(SVC_TYPE_EVENT, SSVC_TYPE_EVENT_INFO_REQ, ...encodeInfo(req))
|
|
|
|
.pipe(
|
2019-09-25 15:35:06 +09:00
|
|
|
takeWhile(res => SSVC_TYPE_EVENT_INFO_RES !== res.subServiceType, true),
|
2019-09-23 14:23:24 +09:00
|
|
|
map(res => {
|
|
|
|
if (SSVC_TYPE_EVENT_INFO_DATA === res.subServiceType) {
|
2019-09-25 15:35:06 +09:00
|
|
|
return {
|
|
|
|
...decodeInfoData(res),
|
|
|
|
Type: SSVC_TYPE_EVENT_INFO_DATA
|
|
|
|
};
|
2019-09-23 14:23:24 +09:00
|
|
|
}
|
2019-09-25 15:35:06 +09:00
|
|
|
return {
|
|
|
|
...decodeInfo(res),
|
|
|
|
Type: SSVC_TYPE_EVENT_INFO_RES
|
|
|
|
};
|
2019-09-23 14:23:24 +09:00
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2019-09-23 18:09:04 +09:00
|
|
|
|
2019-09-25 16:40:35 +09:00
|
|
|
public send(req: SendRequest): Observable<SendResponse> {
|
2019-09-23 18:09:04 +09:00
|
|
|
return this.protocolService
|
2019-09-25 16:40:35 +09:00
|
|
|
.call(SVC_TYPE_EVENT, SSVC_TYPE_EVENT_SEND_REQ, ...encodeSend(req))
|
2019-09-23 18:09:04 +09:00
|
|
|
.pipe(
|
|
|
|
take(1),
|
|
|
|
map(res => {
|
2019-09-25 16:40:35 +09:00
|
|
|
return decodeSend(res);
|
2019-09-23 18:09:04 +09:00
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2019-09-18 15:02:21 +09:00
|
|
|
}
|