64 lines
1.7 KiB
TypeScript
Raw Normal View History

import { map, tap } from 'rxjs/operators';
import { Component, OnInit, Inject, OnDestroy } from '@angular/core';
2019-09-27 12:53:21 +09:00
import { Store, select } from '@ngrx/store';
import * as AppSotre from '@app/store';
import { Observable, Subscription } from 'rxjs';
import {
WindowIdle,
UCAP_NATIVE_SERVICE,
NativeService
} from '@ucap-webmessenger/native';
import { StatusProtocolService } from '@ucap-webmessenger/protocol-status';
import { StatusType, StatusCode } from '@ucap-webmessenger/core';
2019-09-18 15:02:21 +09:00
@Component({
selector: 'app-page-messenger-main',
templateUrl: './main.page.component.html',
styleUrls: ['./main.page.component.scss']
})
2019-09-19 14:15:43 +09:00
export class MainPageComponent implements OnInit {
2019-10-08 11:19:47 +09:00
selectedChat$: Observable<string | null>;
idleStateChangedSubscription: Subscription;
constructor(
@Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService,
private store: Store<any>,
private statusProtocolService: StatusProtocolService
) {}
2019-09-19 14:15:43 +09:00
ngOnInit(): void {
2019-09-27 12:53:21 +09:00
this.selectedChat$ = this.store.pipe(
select(AppSotre.MessengerSelector.ChatSelector.selectedRoom)
);
this.idleStateChangedSubscription = this.nativeService
.idleStateChanged()
.subscribe(action => {
console.log(action);
let statusType: StatusCode;
if (action === 'IDLE') {
// away
statusType = StatusCode.Away;
} else {
// online
statusType = StatusCode.OnLine;
}
this.statusProtocolService.status({
statusDivisionType: StatusType.Messenger,
statusType,
statusMessage: ''
});
});
}
OnDestroy(): void {
if (!!this.idleStateChangedSubscription) {
this.idleStateChangedSubscription.unsubscribe();
}
2019-09-19 14:15:43 +09:00
}
2019-09-18 15:02:21 +09:00
}