import Debug from '../../conf/Debug'; import BrowserDetect from '../../conf/BrowserDetect'; import Logger from '../Logger'; import { browser } from 'webextension-polyfill-ts'; import Settings from '../Settings'; import EventBus from '../EventBus'; if (process.env.CHANNEL !== 'stable'){ console.info("Loading CommsClient"); } /** * Ultrawidify communication spans a few different "domains" that require a few different * means of communication. The four isolated domains are: * * > content script event bus (CS) * > player UI event bus (UI) * > UWServer event bus (BG) * > popup event bus * * It is our goal to route messages between various domains. It is our goal that eventBus * instances in different parts of our script are at least somewhat interoperable between * each other. As such, scripts sending commands should be unaware that Comms object even * exists. * * EventBus is started first. Other components (including commsClient) follow later. * * Messages that pass through CommsServer need to define context object with * context.comms.forwardTo field defined, with one of the following values: * * - all : all content scripts of ALL TABS * - active : all content scripts in CURRENT TAB * - contentScript : specific content script (requires other EventBusContext fields!) * - backgroundScript : background script (considered default behaviour) * - sameOrigin : ??? * - popup : extension popup * * * * * fig 0. ULTRAWIDIFY COMMUNICATION MAP * * CS EVENT BUS * (accessible within tab scripts) * | BG EVENT BUS * PageInfo x (accessible within background page) * x | * : : x UWServer * x CommsClient <---------------x CommsServer x * | (Connect to popup) X POPUP EVENT BUS * | A (accessible within popup) /todo * x eventBus.sendToTunnel() | | *