import { Observable, Subject } from 'rxjs'; import { NativeService, WindowState, NotificationRequest, WindowIdle, } from '@ucap-webmessenger/native'; import { HttpClient } from '@angular/common/http'; import { map, share } from 'rxjs/operators'; import { TranslateLoader } from '@ngx-translate/core'; import { TranslateLoaderService } from '../translate/browser-loader'; import { NotificationService } from '../notification/notification.service'; import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) export class BrowserNativeService extends NativeService { private notificationService: NotificationService; private chatOpenRoomSubject: Subject | null = null; private chatOpenRoom$: Observable | null = null; postAppInit(): void { this.notificationService.requestPermission(); } notify(noti: NotificationRequest): void { this.notificationService.notify(noti, () => { window.focus(); this.chatOpenRoomSubject.next(noti.roomSeq); }); } closeAllNotify(): void {} checkForUpdates(): Observable { return new Observable(subscriber => { try { subscriber.next(false); } catch (error) { subscriber.error(error); } finally { subscriber.complete(); } }); } showImageViewer(): void {} readFile(path: string): Observable { return this.httpClient.get(path, { responseType: 'arraybuffer' }).pipe( map(arrayBuffer => { return Buffer.from(arrayBuffer); }) ); } saveFile( buffer: Buffer, fileName: string, path?: string ): Observable { return this.httpClient.post(path, buffer, {}); } windowStateChanged(): Observable { return new Observable(subscriber => { try { subscriber.next(WindowState.Normal); } catch (error) { subscriber.error(error); } finally { subscriber.complete(); } }); } windowClose(): void {} windowMinimize(): void {} windowMaximize(): void {} idleStateChanged(): Observable { return new Observable(subscriber => { try { subscriber.next(WindowIdle.Active); } catch (error) { subscriber.error(error); } finally { subscriber.complete(); } }); } chatOpenRoom(): Observable { if (!this.chatOpenRoomSubject) { this.chatOpenRoomSubject = new Subject(); this.chatOpenRoom$ = this.chatOpenRoomSubject .asObservable() .pipe(share()); } return this.chatOpenRoom$; } getTranslateLoader(prefix?: string, suffix?: string): TranslateLoader { return new TranslateLoaderService(this, prefix, suffix); } constructor(private httpClient: HttpClient) { super(); this.notificationService = new NotificationService(); } }