next-ucap-messenger/projects/ucap-webmessenger-ui/src/lib/components/file-viewer.component.ts
2019-11-06 18:19:37 +09:00

62 lines
1.4 KiB
TypeScript

import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { ucapAnimations } from '../animations';
import { Info, FileEventJson } from '@ucap-webmessenger/protocol-event';
import { FileViewerType } from '../types/file-viewer.type';
import { FileType } from '@ucap-webmessenger/protocol-file';
import { DeviceType } from '@ucap-webmessenger/core';
@Component({
selector: 'ucap-file-viewer',
templateUrl: './file-viewer.component.html',
styleUrls: ['./file-viewer.component.scss'],
animations: ucapAnimations
})
export class FileViewerComponent implements OnInit {
@Input()
fileInfo: FileEventJson;
@Input()
downloadUrl: string;
@Input()
userSeq: number;
@Input()
deviceType: DeviceType;
@Input()
token: string;
@Output()
download = new EventEmitter<Blob>();
@Output()
closed = new EventEmitter<void>();
FileViewerType = FileViewerType;
constructor() {}
ngOnInit() {}
detectFileViewerType(fileInfo: FileEventJson): FileViewerType {
switch (fileInfo.fileType) {
case FileType.Image:
return FileViewerType.Image;
case FileType.Sound:
return FileViewerType.Sound;
case FileType.Video:
return FileViewerType.Video;
default:
return FileViewerType.Binary;
}
}
onDownload(blob: Blob): void {
this.download.emit(blob);
}
onClosedViewer(): void {
this.closed.emit();
}
}