다른디바이스와의 Sync 처리. ::: 동료 / 그룹
This commit is contained in:
parent
93eb386825
commit
fb94b5480a
|
@ -1,8 +1,9 @@
|
|||
import { delGroupSuccess, buddy2 } from './../store/messenger/sync/actions';
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
import { tap } from 'rxjs/operators';
|
||||
import { tap, withLatestFrom } from 'rxjs/operators';
|
||||
|
||||
import { Store } from '@ngrx/store';
|
||||
import { Store, select } from '@ngrx/store';
|
||||
|
||||
import {
|
||||
SSVC_TYPE_LOGOUT_RES,
|
||||
|
@ -35,7 +36,7 @@ import {
|
|||
SSVC_TYPE_ROOM_EXIT_FORCING_NOTI,
|
||||
SSVC_TYPE_ROOM_FONT_UPD_NOTI,
|
||||
InviteNotification,
|
||||
UpdateNotification,
|
||||
UpdateNotification as RoomUpdateNotification,
|
||||
SSVC_TYPE_ROOM_UPD_RES
|
||||
} from '@ucap-webmessenger/protocol-room';
|
||||
import {
|
||||
|
@ -53,10 +54,29 @@ import {
|
|||
ExitForcingNotification,
|
||||
UpdateFontNotification
|
||||
} from '@ucap-webmessenger/protocol-room';
|
||||
import {
|
||||
GroupProtocolService,
|
||||
SSVC_TYPE_GROUP_UPD_RES2,
|
||||
UpdateNotification as GroupUpdateNotification,
|
||||
SSVC_TYPE_GROUP_ADD_RES,
|
||||
AddNotification as GroupAddNotification,
|
||||
SSVC_TYPE_GROUP_DEL_RES,
|
||||
DelNotification as GroupDelNotification
|
||||
} from '@ucap-webmessenger/protocol-group';
|
||||
import {
|
||||
BuddyProtocolService,
|
||||
SSVC_TYPE_BUDDY_UPD_RES,
|
||||
UpdateNotification as BuddyUpdateNotification,
|
||||
SSVC_TYPE_BUDDY_ADD_RES,
|
||||
AddNotification as BuddyAddNotification,
|
||||
SSVC_TYPE_BUDDY_DEL_RES,
|
||||
DelNotification as BuddyDelNotification
|
||||
} from '@ucap-webmessenger/protocol-buddy';
|
||||
|
||||
import * as AuthenticationStore from '@app/store/account/authentication';
|
||||
import * as InfoStore from '@app/store/account/info';
|
||||
import * as EventStore from '@app/store/messenger/event';
|
||||
import * as SyncStore from '@app/store/messenger/sync';
|
||||
import * as RoomStore from '@app/store/messenger/room';
|
||||
import * as StatusStore from '@app/store/messenger/status';
|
||||
|
||||
|
@ -67,6 +87,8 @@ export class AppNotificationService {
|
|||
private eventProtocolService: EventProtocolService,
|
||||
private infoProtocolService: InfoProtocolService,
|
||||
private roomProtocolService: RoomProtocolService,
|
||||
private groupProtocolService: GroupProtocolService,
|
||||
private buddyProtocolService: BuddyProtocolService,
|
||||
private statusProtocolService: StatusProtocolService,
|
||||
private store: Store<any>,
|
||||
private logger: NGXLogger
|
||||
|
@ -197,15 +219,115 @@ export class AppNotificationService {
|
|||
})
|
||||
)
|
||||
.subscribe();
|
||||
this.groupProtocolService.notification$
|
||||
.pipe(
|
||||
withLatestFrom(
|
||||
this.store.pipe(
|
||||
select(
|
||||
(state: any) => state.messenger.sync.group2.syncDate as string
|
||||
)
|
||||
)
|
||||
),
|
||||
tap(([notiOrRes, syncDate]) => {
|
||||
switch (notiOrRes.SSVC_TYPE) {
|
||||
case SSVC_TYPE_GROUP_UPD_RES2:
|
||||
{
|
||||
const noti = notiOrRes as GroupUpdateNotification;
|
||||
this.logger.debug(
|
||||
'Notification::groupProtocolService::GroupUpdateNotification',
|
||||
noti
|
||||
);
|
||||
this.store.dispatch(
|
||||
SyncStore.group2({
|
||||
syncDate
|
||||
})
|
||||
);
|
||||
}
|
||||
break;
|
||||
case SSVC_TYPE_GROUP_ADD_RES:
|
||||
{
|
||||
const noti = notiOrRes as GroupAddNotification;
|
||||
this.logger.debug(
|
||||
'Notification::groupProtocolService::GroupAddNotification',
|
||||
noti
|
||||
);
|
||||
this.store.dispatch(SyncStore.createGroupSuccess(noti));
|
||||
}
|
||||
break;
|
||||
case SSVC_TYPE_GROUP_DEL_RES:
|
||||
{
|
||||
const noti = notiOrRes as GroupDelNotification;
|
||||
this.logger.debug(
|
||||
'Notification::groupProtocolService::GroupDelNotification',
|
||||
noti
|
||||
);
|
||||
this.store.dispatch(SyncStore.delGroupSuccess(noti));
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
})
|
||||
)
|
||||
.subscribe();
|
||||
this.buddyProtocolService.notification$
|
||||
.pipe(
|
||||
withLatestFrom(
|
||||
this.store.pipe(
|
||||
select(
|
||||
(state: any) => state.messenger.sync.buddy2.syncDate as string
|
||||
)
|
||||
)
|
||||
),
|
||||
tap(([notiOrRes, syncDate]) => {
|
||||
switch (notiOrRes.SSVC_TYPE) {
|
||||
case SSVC_TYPE_BUDDY_UPD_RES:
|
||||
{
|
||||
const noti = notiOrRes as BuddyUpdateNotification;
|
||||
this.logger.debug(
|
||||
'Notification::groupProtocolService::BuddyUpdateNotification',
|
||||
noti
|
||||
);
|
||||
this.store.dispatch(SyncStore.updateBuddySuccess(noti));
|
||||
}
|
||||
break;
|
||||
case SSVC_TYPE_BUDDY_ADD_RES:
|
||||
{
|
||||
const noti = notiOrRes as BuddyAddNotification;
|
||||
this.logger.debug(
|
||||
'Notification::groupProtocolService::BuddyAddNotification',
|
||||
noti
|
||||
);
|
||||
this.store.dispatch(SyncStore.buddy2({ syncDate }));
|
||||
}
|
||||
break;
|
||||
case SSVC_TYPE_BUDDY_DEL_RES:
|
||||
{
|
||||
const noti = notiOrRes as BuddyDelNotification;
|
||||
this.logger.debug(
|
||||
'Notification::groupProtocolService::BuddyDelNotification',
|
||||
noti
|
||||
);
|
||||
this.store.dispatch(SyncStore.delBuddySuccess(noti));
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
})
|
||||
)
|
||||
.subscribe();
|
||||
this.roomProtocolService.notification$
|
||||
.pipe(
|
||||
tap(notiOrRes => {
|
||||
switch (notiOrRes.SSVC_TYPE) {
|
||||
case SSVC_TYPE_ROOM_UPD_RES:
|
||||
{
|
||||
const noti = notiOrRes as UpdateNotification;
|
||||
const noti = notiOrRes as RoomUpdateNotification;
|
||||
this.logger.debug(
|
||||
'Notification::roomProtocolService::UpdateNotification',
|
||||
'Notification::roomProtocolService::RoomUpdateNotification',
|
||||
noti
|
||||
);
|
||||
this.store.dispatch(
|
||||
|
|
|
@ -571,73 +571,68 @@ export class Effects {
|
|||
{ dispatch: false }
|
||||
);
|
||||
|
||||
delGroup$ = createEffect(
|
||||
() => {
|
||||
return this.actions$.pipe(
|
||||
ofType(delGroup),
|
||||
withLatestFrom(
|
||||
this.store.pipe(
|
||||
select(
|
||||
(state: any) =>
|
||||
state.messenger.sync.group2.entities as Dictionary<
|
||||
GroupDetailData
|
||||
>
|
||||
)
|
||||
delGroup$ = createEffect(() =>
|
||||
this.actions$.pipe(
|
||||
ofType(delGroup),
|
||||
withLatestFrom(
|
||||
this.store.pipe(
|
||||
select(
|
||||
(state: any) =>
|
||||
state.messenger.sync.group2.entities as Dictionary<
|
||||
GroupDetailData
|
||||
>
|
||||
)
|
||||
),
|
||||
map(([action, groupList]) => {
|
||||
// Del Buddy
|
||||
const trgtBuddys = action.group.userSeqs;
|
||||
// tslint:disable-next-line: no-shadowed-variable
|
||||
const delBuddyList = trgtBuddys.filter(delBuddy => {
|
||||
let exist = false;
|
||||
// tslint:disable-next-line: forin
|
||||
for (const key in groupList) {
|
||||
const group: GroupDetailData = groupList[key];
|
||||
if (
|
||||
group.seq !== action.group.seq &&
|
||||
group.userSeqs.filter(v => v === delBuddy).length > 0
|
||||
) {
|
||||
exist = true;
|
||||
break;
|
||||
}
|
||||
)
|
||||
),
|
||||
exhaustMap(([action, groupList]) => {
|
||||
// Del Buddy
|
||||
const trgtBuddys = action.group.userSeqs;
|
||||
// tslint:disable-next-line: no-shadowed-variable
|
||||
const delBuddyList = trgtBuddys.filter(delBuddy => {
|
||||
let exist = false;
|
||||
// tslint:disable-next-line: forin
|
||||
for (const key in groupList) {
|
||||
const group: GroupDetailData = groupList[key];
|
||||
if (
|
||||
group.seq !== action.group.seq &&
|
||||
group.userSeqs.filter(v => v === delBuddy).length > 0
|
||||
) {
|
||||
exist = true;
|
||||
break;
|
||||
}
|
||||
return !exist;
|
||||
}
|
||||
return !exist;
|
||||
});
|
||||
|
||||
if (delBuddyList.length > 0) {
|
||||
this.logger.debug('Del Buddy', delBuddyList);
|
||||
// 즐겨찾기 해제.
|
||||
delBuddyList.forEach(buddySeq => {
|
||||
this.buddyProtocolService
|
||||
.update({
|
||||
seq: buddySeq,
|
||||
isFavorit: false
|
||||
})
|
||||
.pipe(catchError(error => of(delBuddyFailure({ error }))));
|
||||
});
|
||||
|
||||
if (delBuddyList.length > 0) {
|
||||
this.logger.debug('Del Buddy', delBuddyList);
|
||||
// 즐겨찾기 해제.
|
||||
delBuddyList.forEach(buddySeq => {
|
||||
this.buddyProtocolService
|
||||
.update({
|
||||
seq: buddySeq,
|
||||
isFavorit: false
|
||||
})
|
||||
.pipe(catchError(error => of(delBuddyFailure({ error }))));
|
||||
});
|
||||
// 동료 삭제
|
||||
this.store.dispatch(delBuddy({ userSeqs: delBuddyList }));
|
||||
}
|
||||
|
||||
// 동료 삭제
|
||||
this.store.dispatch(delBuddy({ userSeqs: delBuddyList }));
|
||||
}
|
||||
|
||||
return action.group;
|
||||
}),
|
||||
tap(group => {
|
||||
this.groupProtocolService
|
||||
.del({
|
||||
groupSeq: group.seq
|
||||
})
|
||||
.pipe(
|
||||
map((res: GroupDelResponse) => {
|
||||
return delGroupSuccess(res);
|
||||
}),
|
||||
catchError(error => of(delGroupFailure({ error })))
|
||||
);
|
||||
})
|
||||
);
|
||||
},
|
||||
{ dispatch: false }
|
||||
return this.groupProtocolService
|
||||
.del({
|
||||
groupSeq: action.group.seq
|
||||
})
|
||||
.pipe(
|
||||
map((res: GroupDelResponse) => {
|
||||
// this.store.dispatch(delGroupSuccess(res));
|
||||
return delGroupSuccess(res);
|
||||
}),
|
||||
catchError(error => of(delGroupFailure({ error })))
|
||||
);
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
addBuddy$ = createEffect(() =>
|
||||
|
@ -674,11 +669,6 @@ export class Effects {
|
|||
map((res: BuddyDelResponse) => {
|
||||
return delBuddySuccess(res);
|
||||
}),
|
||||
// map((res: BuddyDelResponse) => {
|
||||
// return buddy2({
|
||||
// syncDate
|
||||
// });
|
||||
// }),
|
||||
catchError(error => of(delBuddyFailure({ error })))
|
||||
)
|
||||
)
|
||||
|
|
|
@ -7,16 +7,22 @@ import {
|
|||
PacketBodyValue,
|
||||
ProtocolDecoder,
|
||||
ProtocolMessage,
|
||||
decodeProtocolMessage
|
||||
decodeProtocolMessage,
|
||||
ProtocolNotification
|
||||
} from '@ucap-webmessenger/protocol';
|
||||
|
||||
export interface AddRequest extends ProtocolRequest {
|
||||
// 0n. 사용자SEQ(n)...
|
||||
/** 0n. 사용자SEQ(n)... */
|
||||
userSeqs: number[];
|
||||
}
|
||||
|
||||
export interface AddResponse extends ProtocolResponse {
|
||||
// 0n. 사용자SEQ(n)...
|
||||
/** 0n. 사용자SEQ(n)... */
|
||||
userSeqs: number[];
|
||||
}
|
||||
|
||||
export interface AddNotification extends ProtocolNotification {
|
||||
/** 0n. 사용자SEQ(n)... */
|
||||
userSeqs: number[];
|
||||
}
|
||||
|
||||
|
@ -38,3 +44,12 @@ export const decodeAdd: ProtocolDecoder<AddResponse> = (
|
|||
userSeqs: userSeqArray
|
||||
} as AddResponse);
|
||||
};
|
||||
|
||||
export const decodeAddNotification: ProtocolDecoder<AddNotification> = (
|
||||
message: ProtocolMessage
|
||||
) => {
|
||||
const userSeqArray: number[] = [...message.bodyList];
|
||||
return decodeProtocolMessage(message, {
|
||||
userSeqs: userSeqArray
|
||||
} as AddNotification);
|
||||
};
|
||||
|
|
|
@ -7,16 +7,22 @@ import {
|
|||
PacketBodyValue,
|
||||
ProtocolDecoder,
|
||||
ProtocolMessage,
|
||||
decodeProtocolMessage
|
||||
decodeProtocolMessage,
|
||||
ProtocolNotification
|
||||
} from '@ucap-webmessenger/protocol';
|
||||
|
||||
export interface DelRequest extends ProtocolRequest {
|
||||
// 0n. 사용자SEQ(n)...
|
||||
/** 0n. 사용자SEQ(n)... */
|
||||
userSeqs: number[];
|
||||
}
|
||||
|
||||
export interface DelResponse extends ProtocolResponse {
|
||||
// 0n. 사용자SEQ(n)...
|
||||
/** 0n. 사용자SEQ(n)... */
|
||||
userSeqs: number[];
|
||||
}
|
||||
|
||||
export interface DelNotification extends ProtocolNotification {
|
||||
/** 0n. 사용자SEQ(n)... */
|
||||
userSeqs: number[];
|
||||
}
|
||||
|
||||
|
@ -38,3 +44,12 @@ export const decodeDel: ProtocolDecoder<DelResponse> = (
|
|||
userSeqs: userSeqArray
|
||||
} as DelResponse);
|
||||
};
|
||||
|
||||
export const decodeDelNotification: ProtocolDecoder<DelNotification> = (
|
||||
message: ProtocolMessage
|
||||
) => {
|
||||
const userSeqArray: number[] = [...message.bodyList];
|
||||
return decodeProtocolMessage(message, {
|
||||
userSeqs: userSeqArray
|
||||
} as DelNotification);
|
||||
};
|
||||
|
|
|
@ -7,7 +7,8 @@ import {
|
|||
PacketBodyValue,
|
||||
ProtocolDecoder,
|
||||
ProtocolMessage,
|
||||
decodeProtocolMessage
|
||||
decodeProtocolMessage,
|
||||
ProtocolNotification
|
||||
} from '@ucap-webmessenger/protocol';
|
||||
|
||||
export interface UpdateRequest extends ProtocolRequest {
|
||||
|
@ -24,6 +25,13 @@ export interface UpdateResponse extends ProtocolResponse {
|
|||
isFavorit: boolean;
|
||||
}
|
||||
|
||||
export interface UpdateNotification extends ProtocolNotification {
|
||||
// 0. 사용자SEQ(n)
|
||||
seq: number;
|
||||
// 1. 즐겨찾기여부(y)
|
||||
isFavorit: boolean;
|
||||
}
|
||||
|
||||
export const encodeUpdate: ProtocolEncoder<UpdateRequest> = (
|
||||
req: UpdateRequest
|
||||
) => {
|
||||
|
@ -46,3 +54,12 @@ export const decodeUpdate: ProtocolDecoder<UpdateResponse> = (
|
|||
isFavorit: message.bodyList[1] === 'Y' ? true : false
|
||||
} as UpdateResponse);
|
||||
};
|
||||
|
||||
export const decodeUpdateNotification: ProtocolDecoder<UpdateNotification> = (
|
||||
message: ProtocolMessage
|
||||
) => {
|
||||
return decodeProtocolMessage(message, {
|
||||
seq: message.bodyList[0],
|
||||
isFavorit: message.bodyList[1] === 'Y' ? true : false
|
||||
} as UpdateNotification);
|
||||
};
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { map, take } from 'rxjs/operators';
|
||||
import { Observable, Subject } from 'rxjs';
|
||||
import { map, take, share, filter, tap } from 'rxjs/operators';
|
||||
|
||||
import { ProtocolService } from '@ucap-webmessenger/protocol';
|
||||
|
||||
|
@ -9,33 +9,80 @@ import {
|
|||
SVC_TYPE_BUDDY,
|
||||
SSVC_TYPE_BUDDY_ADD_REQ,
|
||||
SSVC_TYPE_BUDDY_DEL_REQ,
|
||||
SSVC_TYPE_BUDDY_UPD_REQ
|
||||
SSVC_TYPE_BUDDY_UPD_REQ,
|
||||
SSVC_TYPE_BUDDY_UPD_RES,
|
||||
SSVC_TYPE_BUDDY_ADD_RES,
|
||||
SSVC_TYPE_BUDDY_DEL_RES
|
||||
} from '../types/service';
|
||||
|
||||
import {
|
||||
AddRequest,
|
||||
encodeAdd,
|
||||
decodeAdd,
|
||||
AddResponse
|
||||
AddResponse,
|
||||
decodeAddNotification,
|
||||
AddNotification
|
||||
} from '../protocols/add';
|
||||
import {
|
||||
DelRequest,
|
||||
encodeDel,
|
||||
decodeDel,
|
||||
DelResponse
|
||||
DelResponse,
|
||||
decodeDelNotification,
|
||||
DelNotification
|
||||
} from '../protocols/del';
|
||||
import {
|
||||
UpdateRequest,
|
||||
decodeUpdate,
|
||||
encodeUpdate,
|
||||
UpdateResponse
|
||||
UpdateResponse,
|
||||
UpdateNotification,
|
||||
decodeUpdateNotification
|
||||
} from '../protocols/update';
|
||||
|
||||
type Notifications = UpdateNotification | AddNotification | DelNotification;
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class BuddyProtocolService {
|
||||
constructor(private protocolService: ProtocolService) {}
|
||||
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_BUDDY),
|
||||
tap(message => {
|
||||
switch (message.subServiceType) {
|
||||
case SSVC_TYPE_BUDDY_UPD_RES:
|
||||
{
|
||||
this.notificationSubject.next(
|
||||
decodeUpdateNotification(message)
|
||||
);
|
||||
}
|
||||
break;
|
||||
case SSVC_TYPE_BUDDY_ADD_RES:
|
||||
{
|
||||
this.notificationSubject.next(decodeAddNotification(message));
|
||||
}
|
||||
break;
|
||||
case SSVC_TYPE_BUDDY_DEL_RES:
|
||||
{
|
||||
this.notificationSubject.next(decodeDelNotification(message));
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
})
|
||||
)
|
||||
.subscribe();
|
||||
}
|
||||
|
||||
public add(req: AddRequest): Observable<AddResponse> {
|
||||
return this.protocolService
|
||||
|
|
|
@ -7,18 +7,26 @@ import {
|
|||
PacketBodyValue,
|
||||
ProtocolDecoder,
|
||||
ProtocolMessage,
|
||||
decodeProtocolMessage
|
||||
decodeProtocolMessage,
|
||||
ProtocolNotification
|
||||
} from '@ucap-webmessenger/protocol';
|
||||
|
||||
export interface AddRequest extends ProtocolRequest {
|
||||
// 0. 동료그룹이름
|
||||
/** 0. 동료그룹이름 */
|
||||
groupName: string;
|
||||
}
|
||||
|
||||
export interface AddResponse extends ProtocolResponse {
|
||||
// 0: 동료그룹SEQ(n)
|
||||
/** 0: 동료그룹SEQ(n) */
|
||||
groupSeq: number;
|
||||
// 1: 동료그룹이름(s)
|
||||
/** 1: 동료그룹이름(s) */
|
||||
groupName: string;
|
||||
}
|
||||
|
||||
export interface AddNotification extends ProtocolNotification {
|
||||
/** 0: 동료그룹SEQ(n) */
|
||||
groupSeq: number;
|
||||
/** 1: 동료그룹이름(s) */
|
||||
groupName: string;
|
||||
}
|
||||
|
||||
|
@ -38,3 +46,12 @@ export const decodeAdd: ProtocolDecoder<AddResponse> = (
|
|||
groupName: message.bodyList[1]
|
||||
} as AddResponse);
|
||||
};
|
||||
|
||||
export const decodeAddNotification: ProtocolDecoder<AddNotification> = (
|
||||
message: ProtocolMessage
|
||||
) => {
|
||||
return decodeProtocolMessage(message, {
|
||||
groupSeq: message.bodyList[0],
|
||||
groupName: message.bodyList[1]
|
||||
} as AddNotification);
|
||||
};
|
||||
|
|
|
@ -7,16 +7,22 @@ import {
|
|||
PacketBodyValue,
|
||||
ProtocolDecoder,
|
||||
ProtocolMessage,
|
||||
decodeProtocolMessage
|
||||
decodeProtocolMessage,
|
||||
ProtocolNotification
|
||||
} from '@ucap-webmessenger/protocol';
|
||||
|
||||
export interface DelRequest extends ProtocolRequest {
|
||||
// 0: 동료그룹SEQ(n)
|
||||
/** 동료그룹SEQ(n) */
|
||||
groupSeq: number;
|
||||
}
|
||||
|
||||
export interface DelResponse extends ProtocolResponse {
|
||||
// 0: 동료그룹SEQ(n)
|
||||
/** 동료그룹SEQ(n) */
|
||||
groupSeq: number;
|
||||
}
|
||||
|
||||
export interface DelNotification extends ProtocolNotification {
|
||||
/** 동료그룹SEQ(n) */
|
||||
groupSeq: number;
|
||||
}
|
||||
|
||||
|
@ -35,3 +41,11 @@ export const decodeDel: ProtocolDecoder<DelResponse> = (
|
|||
groupSeq: message.bodyList[0]
|
||||
} as DelResponse);
|
||||
};
|
||||
|
||||
export const decodeDelNotification: ProtocolDecoder<DelNotification> = (
|
||||
message: ProtocolMessage
|
||||
) => {
|
||||
return decodeProtocolMessage(message, {
|
||||
groupSeq: message.bodyList[0]
|
||||
} as DelNotification);
|
||||
};
|
||||
|
|
|
@ -7,24 +7,34 @@ import {
|
|||
PacketBodyValue,
|
||||
ProtocolDecoder,
|
||||
ProtocolMessage,
|
||||
decodeProtocolMessage
|
||||
decodeProtocolMessage,
|
||||
ProtocolNotification
|
||||
} from '@ucap-webmessenger/protocol';
|
||||
|
||||
export interface UpdateRequest extends ProtocolRequest {
|
||||
// 0: 동료그룹SEQ(n)
|
||||
/** 0: 동료그룹SEQ(n) */
|
||||
groupSeq: number;
|
||||
// 1: 동료그룹이름(s)
|
||||
/** 1: 동료그룹이름(s) */
|
||||
groupName: string;
|
||||
// 2n: 사용자SEQ(n)...
|
||||
/** 2n: 사용자SEQ(n)... */
|
||||
userSeqs: number[];
|
||||
}
|
||||
|
||||
export interface UpdateResponse extends ProtocolResponse {
|
||||
// 0: 동료그룹SEQ(n)
|
||||
/** 0: 동료그룹SEQ(n) */
|
||||
groupSeq: number;
|
||||
// 1: 동료그룹이름(s)
|
||||
/** 1: 동료그룹이름(s) */
|
||||
groupName: string;
|
||||
// 2n: 사용자SEQ(n)...
|
||||
/** 2n: 사용자SEQ(n)... */
|
||||
userSeqs: number[];
|
||||
}
|
||||
|
||||
export interface UpdateNotification extends ProtocolNotification {
|
||||
/** 0: 동료그룹SEQ(n) */
|
||||
groupSeq: number;
|
||||
/** 1: 동료그룹이름(s) */
|
||||
groupName: string;
|
||||
/** 2n: 사용자SEQ(n)... */
|
||||
userSeqs: number[];
|
||||
}
|
||||
|
||||
|
@ -90,3 +100,18 @@ export const decodeUpdate2: ProtocolDecoder<UpdateResponse> = (
|
|||
userSeqs: userSeqArray
|
||||
} as UpdateResponse);
|
||||
};
|
||||
|
||||
export const decodeUpdate2Notification: ProtocolDecoder<UpdateNotification> = (
|
||||
message: ProtocolMessage
|
||||
) => {
|
||||
let userSeqArray: number[] = [];
|
||||
if (message.bodyList.length > 2) {
|
||||
userSeqArray = message.bodyList.slice(2);
|
||||
}
|
||||
|
||||
return decodeProtocolMessage(message, {
|
||||
groupSeq: message.bodyList[0],
|
||||
groupName: message.bodyList[1],
|
||||
userSeqs: userSeqArray
|
||||
} as UpdateNotification);
|
||||
};
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
import {
|
||||
SSVC_TYPE_GROUP_UPD_RES2,
|
||||
SSVC_TYPE_GROUP_ADD_RES,
|
||||
SSVC_TYPE_GROUP_DEL_RES
|
||||
} from './../types/service';
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { map, take } from 'rxjs/operators';
|
||||
import { Observable, Subject } from 'rxjs';
|
||||
import { map, take, share, filter, tap } from 'rxjs/operators';
|
||||
|
||||
import { ProtocolService } from '@ucap-webmessenger/protocol';
|
||||
import {
|
||||
|
@ -15,13 +20,17 @@ import {
|
|||
AddRequest,
|
||||
encodeAdd,
|
||||
decodeAdd,
|
||||
AddResponse
|
||||
AddResponse,
|
||||
decodeAddNotification,
|
||||
AddNotification
|
||||
} from '../protocols/add';
|
||||
import {
|
||||
DelRequest,
|
||||
encodeDel,
|
||||
decodeDel,
|
||||
DelResponse
|
||||
DelResponse,
|
||||
decodeDelNotification,
|
||||
DelNotification
|
||||
} from '../protocols/del';
|
||||
import {
|
||||
UpdateRequest,
|
||||
|
@ -29,13 +38,54 @@ import {
|
|||
decodeUpdate,
|
||||
encodeUpdate2,
|
||||
decodeUpdate2,
|
||||
UpdateResponse
|
||||
UpdateResponse,
|
||||
UpdateNotification,
|
||||
decodeUpdate2Notification
|
||||
} from '../protocols/update';
|
||||
|
||||
type Notifications = UpdateNotification | AddNotification | DelNotification;
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class GroupProtocolService {
|
||||
constructor(private protocolService: ProtocolService) {}
|
||||
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_GROUP),
|
||||
tap(message => {
|
||||
switch (message.subServiceType) {
|
||||
case SSVC_TYPE_GROUP_UPD_RES2:
|
||||
{
|
||||
this.notificationSubject.next(
|
||||
decodeUpdate2Notification(message)
|
||||
);
|
||||
}
|
||||
break;
|
||||
case SSVC_TYPE_GROUP_ADD_RES:
|
||||
{
|
||||
this.notificationSubject.next(decodeAddNotification(message));
|
||||
}
|
||||
break;
|
||||
case SSVC_TYPE_GROUP_DEL_RES:
|
||||
{
|
||||
this.notificationSubject.next(decodeDelNotification(message));
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
})
|
||||
)
|
||||
.subscribe();
|
||||
}
|
||||
|
||||
public add(req: AddRequest): Observable<AddResponse> {
|
||||
return this.protocolService
|
||||
|
|
|
@ -103,11 +103,14 @@ import {
|
|||
encodeUpdateFont,
|
||||
decodeUpdateFont,
|
||||
decodeUpdateFontNotification,
|
||||
UpdateFontNotification
|
||||
UpdateFontNotification,
|
||||
decodeUpdateNotification,
|
||||
UpdateNotification
|
||||
} from '../protocols/update';
|
||||
|
||||
type Notifications =
|
||||
| UpdateFontNotification
|
||||
| UpdateNotification
|
||||
| InviteNotification
|
||||
| ExitNotification
|
||||
| ExitForcingNotification;
|
||||
|
@ -130,7 +133,9 @@ export class RoomProtocolService {
|
|||
switch (message.subServiceType) {
|
||||
case SSVC_TYPE_ROOM_UPD_RES:
|
||||
{
|
||||
this.notificationSubject.next(decodeUpdate(message));
|
||||
this.notificationSubject.next(
|
||||
decodeUpdateNotification(message)
|
||||
);
|
||||
}
|
||||
break;
|
||||
case SSVC_TYPE_ROOM_INVITE_NOTI:
|
||||
|
|
Loading…
Reference in New Issue
Block a user