2022-09-11 15:58:32 +02:00
|
|
|
export default class MessageService {
|
|
|
|
private viewerType: string;
|
|
|
|
public constructor(type: string) {
|
|
|
|
this.viewerType = type;
|
|
|
|
}
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2022-09-11 15:58:32 +02:00
|
|
|
private sendMessage = (name: string, data?: any) => {
|
|
|
|
if (this.viewerType === 'full') {
|
|
|
|
const message = {
|
|
|
|
name,
|
|
|
|
...data,
|
|
|
|
};
|
|
|
|
window.postMessage(message, '*');
|
|
|
|
} else if (this.viewerType === 'mini') {
|
|
|
|
const message = {
|
|
|
|
name,
|
|
|
|
data,
|
|
|
|
target: 'webview',
|
|
|
|
};
|
|
|
|
window.parent.postMessage(message, '*');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
public textSelected = (text: string) => {
|
|
|
|
this.sendMessage('textSelected', { text });
|
|
|
|
};
|
|
|
|
public close = () => {
|
|
|
|
this.sendMessage('close');
|
|
|
|
};
|
|
|
|
public openExternalViewer = () => {
|
|
|
|
this.sendMessage('externalViewer');
|
|
|
|
};
|
|
|
|
|
|
|
|
public openFullScreenViewer = (resourceId: string, pageNo: number) => {
|
|
|
|
this.sendMessage('openPdfViewer', { resourceId, pageNo });
|
|
|
|
};
|
|
|
|
}
|