2018-01-14 00:16:19 +01:00
|
|
|
import { BrowserApi } from '../browser/browserApi';
|
2019-08-13 17:40:54 +02:00
|
|
|
import { SafariApp } from '../browser/safariApp';
|
2018-01-14 00:16:19 +01:00
|
|
|
|
2019-08-13 17:40:54 +02:00
|
|
|
import { MessagingService } from 'jslib/abstractions/messaging.service';
|
2018-01-04 22:06:00 +01:00
|
|
|
|
2018-01-09 20:26:20 +01:00
|
|
|
export default class BrowserMessagingService implements MessagingService {
|
2018-01-04 22:06:00 +01:00
|
|
|
send(subscriber: string, arg: any = {}) {
|
2018-04-10 20:20:03 +02:00
|
|
|
if (BrowserApi.isSafariApi) {
|
2019-08-13 17:40:54 +02:00
|
|
|
SafariApp.sendMessageToApp(subscriber, arg);
|
2018-01-11 21:34:55 +01:00
|
|
|
} else {
|
2019-08-13 17:40:54 +02:00
|
|
|
const message = Object.assign({}, { command: subscriber }, arg);
|
2018-01-11 21:34:55 +01:00
|
|
|
chrome.runtime.sendMessage(message);
|
|
|
|
}
|
2018-01-04 22:06:00 +01:00
|
|
|
}
|
|
|
|
}
|