72 lines
1.6 KiB
TypeScript
Raw Normal View History

2019-09-18 15:02:21 +09:00
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { map, take } from 'rxjs/operators';
2019-09-18 15:02:21 +09:00
2019-09-20 11:39:09 +09:00
import { ProtocolService } from '@ucap-webmessenger/protocol';
2019-09-18 15:02:21 +09:00
import {
2019-09-20 11:39:09 +09:00
LoginRequest,
LoginResponse,
encodeLogin,
decodeLogin
} from '../models/login';
2019-09-18 15:02:21 +09:00
import {
SVC_TYPE_LOGIN,
SSVC_TYPE_LOGIN_REQ,
2019-09-19 17:03:39 +09:00
SVC_TYPE_LOGOUT,
2019-09-19 18:05:59 +09:00
SSVC_TYPE_LOGOUT_REQ,
SSVC_TYPE_LOGOUT_REMOTE_REQ
2019-09-18 15:02:21 +09:00
} from '../types/service';
2019-09-19 18:05:59 +09:00
import {
LogoutRequest,
LogoutResponse,
2019-09-20 11:39:09 +09:00
encodeLogout,
decodeLogout
2019-09-19 18:05:59 +09:00
} from '../models/logout';
2019-09-20 11:39:09 +09:00
import {
encodeLogoutRemote,
decodeLogoutRemote,
LogoutRemoteRequest,
LogoutRemoteResponse
} from '../models/logout-remote';
2019-09-18 15:02:21 +09:00
@Injectable({
providedIn: 'root'
})
export class AuthenticationProtocolService {
constructor(private protocolService: ProtocolService) {}
public login(req: LoginRequest): Observable<LoginResponse> {
return this.protocolService
2019-09-20 11:39:09 +09:00
.call(SVC_TYPE_LOGIN, SSVC_TYPE_LOGIN_REQ, ...encodeLogin(req))
.pipe(
take(1),
map(res => decodeLogin(res))
);
2019-09-19 18:05:59 +09:00
}
2019-09-19 17:03:39 +09:00
public logout(req: LogoutRequest): Observable<LogoutResponse> {
return this.protocolService
2019-09-20 11:39:09 +09:00
.call(SVC_TYPE_LOGOUT, SSVC_TYPE_LOGOUT_REQ, ...encodeLogout(req))
.pipe(
take(1),
map(res => decodeLogout(res))
);
2019-09-19 18:05:59 +09:00
}
public logoutRemote(
req: LogoutRemoteRequest
): Observable<LogoutRemoteResponse> {
return this.protocolService
2019-09-20 11:39:09 +09:00
.call(
SVC_TYPE_LOGOUT,
SSVC_TYPE_LOGOUT_REMOTE_REQ,
...encodeLogoutRemote(req)
)
.pipe(
take(1),
map(res => decodeLogoutRemote(res))
);
2019-09-19 18:05:59 +09:00
}
2019-09-18 15:02:21 +09:00
}