@dxos/rpc-tunnel 0.8.4-main.f9ba587 → 0.8.4-main.fffef41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  // src/ports/iframe.ts
2
- import { UAParser } from "ua-parser-js";
2
+ import UAParser from "ua-parser-js";
3
3
  import { log } from "@dxos/log";
4
4
  var __dxlog_file = "/__w/dxos/dxos/packages/core/mesh/rpc-tunnel/src/ports/iframe.ts";
5
5
  var browser;
@@ -154,10 +154,11 @@ var createWorkerPort = ({ port, channel, subscribe }) => ({
154
154
  import { log as log3 } from "@dxos/log";
155
155
  var __dxlog_file3 = "/__w/dxos/dxos/packages/core/mesh/rpc-tunnel/src/port-muxer.ts";
156
156
  var PortMuxer = class {
157
+ _messagePort;
158
+ _activeChannels = /* @__PURE__ */ new Map();
159
+ _rpcPorts = /* @__PURE__ */ new Map();
157
160
  constructor(_messagePort) {
158
161
  this._messagePort = _messagePort;
159
- this._activeChannels = /* @__PURE__ */ new Map();
160
- this._rpcPorts = /* @__PURE__ */ new Map();
161
162
  if (this._messagePort) {
162
163
  this._messagePort.onmessage = (event) => this.onWorkerMessage(event);
163
164
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/ports/iframe.ts", "../../../src/ports/worker.ts", "../../../src/port-muxer.ts"],
4
- "sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nimport { UAParser } from 'ua-parser-js';\n\nimport { log } from '@dxos/log';\nimport { type RpcPort } from '@dxos/rpc';\n\nimport { type MessageData } from '../message';\n\nlet browser: string | undefined;\nlet os: string | undefined;\n\nif (typeof navigator !== 'undefined') {\n // TODO(wittjosiah): Stop user agent parsing.\n const parser = new UAParser(navigator.userAgent);\n browser = parser.getBrowser().name;\n os = parser.getOS().name;\n}\n\nconst sendToIFrame = (iframe: HTMLIFrameElement, origin: string, message: MessageData) => {\n if (!iframe.contentWindow) {\n log('IFrame content window missing', { origin });\n return;\n }\n\n if (browser === 'Chrome' && os === 'iOS') {\n iframe.contentWindow.postMessage(message, origin);\n } else {\n iframe.contentWindow.postMessage(message, origin, [message.payload]);\n }\n};\n\nconst sendToParentWindow = (origin: string, message: MessageData) => {\n if (browser === 'Chrome' && os === 'iOS') {\n window.parent.postMessage(message, origin);\n } else {\n window.parent.postMessage(message, origin, [message.payload]);\n }\n};\n\nexport type IFramePortOptions = {\n channel: string;\n iframe?: HTMLIFrameElement;\n origin?: string;\n onOrigin?: (origin: string) => void;\n};\n\n/**\n * Create a RPC port with an iframe over window messaging.\n * @param options.channel Identifier for sent/recieved messages.\n * @param options.iframe Instance of the iframe if sending to child.\n * @param options.origin Origin of the destination window.\n * @param options.onOrigin Callback triggered when origin of destination window is verified.\n * @returns RPC port for messaging.\n */\nexport const createIFramePort = ({ channel, iframe, origin, onOrigin }: IFramePortOptions): RpcPort => {\n return {\n send: async (data) => {\n if (!origin) {\n log('no origin set', { channel });\n return;\n }\n\n log('sending', { channel, data: data.length });\n const payload = data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);\n const message = { channel, payload };\n if (iframe) {\n sendToIFrame(iframe, origin, message);\n } else {\n sendToParentWindow(origin, message);\n }\n },\n\n subscribe: (callback) => {\n const handler = (event: MessageEvent<unknown>) => {\n if (!iframe && event.source !== window.parent) {\n // Not from parent window.\n return;\n } else if (iframe && event.source !== iframe.contentWindow) {\n // Not from child window.\n return;\n }\n\n const isMessageData =\n event.data && typeof event.data === 'object' && 'channel' in event.data && 'payload' in event.data;\n const message = isMessageData ? (event.data as MessageData) : undefined;\n if (message?.channel !== channel) {\n return;\n }\n\n if (!origin) {\n origin = event.origin;\n onOrigin?.(origin);\n }\n\n log('received', message);\n callback(new Uint8Array(message.payload));\n };\n\n window.addEventListener('message', handler);\n return () => window.removeEventListener('message', handler);\n },\n };\n};\n\nexport type CreateIFrameOptions = {\n hidden?: boolean;\n allow?: string;\n};\n\n/**\n * Create a hidden iframe and insert it into the DOM.\n * If an element with the same id already exists it will be returned instead.\n * @param source Source of the iframe.\n * @param id DOM id of the iframe.\n * @returns The created iframe.\n */\nexport const createIFrame = (source: string, id: string, { hidden = true, allow }: CreateIFrameOptions = {}) => {\n const create = () => {\n const iframe = document.createElement('iframe') as HTMLIFrameElement;\n iframe.id = id;\n iframe.src = source;\n hidden && iframe.setAttribute('style', 'display: none;');\n allow && iframe.setAttribute('allow', allow);\n document.body.appendChild(iframe);\n return iframe;\n };\n\n return (document.getElementById(id) as HTMLIFrameElement) ?? create();\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { log } from '@dxos/log';\nimport { type RpcPort } from '@dxos/rpc';\n\nimport { type MessageData } from '../message';\n\nexport type WorkerPortOptions = {\n port: MessagePort;\n channel?: string;\n subscribe?: RpcPort['subscribe'];\n};\n\n/**\n * Create a RPC port for a worker.\n * @param options.port Message port to send message on.\n * @param options.channel Identifier for sent/recieved messages.\n * @param options.subscribe\n * @returns RPC port for messaging.\n */\n// TODO(wittjosiah): Rename for more general purpose MessagePort.\nexport const createWorkerPort = ({ port, channel, subscribe }: WorkerPortOptions): RpcPort => ({\n send: async (message) => {\n // Based on https://stackoverflow.com/a/54646864/2804332.\n const payload = message.buffer.slice(message.byteOffset, message.byteOffset + message.byteLength);\n port.postMessage(\n {\n channel,\n payload,\n },\n [payload],\n );\n },\n\n subscribe:\n subscribe ??\n ((callback) => {\n const handler = (event: MessageEvent<MessageData>) => {\n const message = event.data;\n if (channel && message.channel !== channel) {\n return;\n }\n\n log.debug('received', { message });\n callback(new Uint8Array(message.payload));\n };\n\n port.onmessage = handler;\n return () => {\n port.onmessage = null;\n };\n }),\n});\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { log } from '@dxos/log';\nimport { type RpcPort } from '@dxos/rpc';\n\nimport { type MessageData } from './message';\nimport { createIFramePort, createWorkerPort, type IFramePortOptions, type WorkerPortOptions } from './ports';\n\n/**\n * Facilitates the multiplexing of multiple RpcPorts over a single MessagePort.\n */\nexport class PortMuxer {\n private readonly _activeChannels = new Map<string, (msg: Uint8Array) => void>();\n\n private readonly _rpcPorts = new Map<string, RpcPort>();\n\n constructor(private readonly _messagePort?: MessagePort) {\n if (this._messagePort) {\n this._messagePort.onmessage = (event) => this.onWorkerMessage(event);\n }\n\n if (typeof window !== 'undefined') {\n window.addEventListener('message', (event) => this.onWindowMessage(event));\n }\n }\n\n createWorkerPort(options: Omit<WorkerPortOptions, 'port' | 'subscribe' | 'channel'> & { channel: string }): RpcPort {\n if (!this._messagePort) {\n throw new Error('Message port is required to create worker ports');\n }\n\n const port = createWorkerPort({\n ...options,\n port: this._messagePort,\n subscribe: (callback) => {\n this._activeChannels.set(options.channel, callback);\n return () => this._activeChannels.delete(options.channel);\n },\n });\n this._rpcPorts.set(options.channel, port);\n\n return port;\n }\n\n createIFramePort(options: IFramePortOptions): RpcPort {\n const port = createIFramePort(options);\n this._rpcPorts.set(options.channel, port);\n\n return port;\n }\n\n private onWorkerMessage(event: MessageEvent<MessageData>): void {\n const message = event.data;\n log.debug('Recieved message from worker port', {\n channel: message.channel,\n payload: message.payload,\n });\n\n const callback = this._activeChannels.get(message.channel);\n callback?.(new Uint8Array(message.payload));\n }\n\n private onWindowMessage(event: MessageEvent<MessageData>): void {\n const message = event.data;\n log.debug('Recieved message from window', {\n channel: message.channel,\n payload: message.payload,\n });\n }\n}\n"],
5
- "mappings": ";AAIA,SAASA,gBAAgB;AAEzB,SAASC,WAAW;;AAKpB,IAAIC;AACJ,IAAIC;AAEJ,IAAI,OAAOC,cAAc,aAAa;AAEpC,QAAMC,SAAS,IAAIL,SAASI,UAAUE,SAAS;AAC/CJ,YAAUG,OAAOE,WAAU,EAAGC;AAC9BL,OAAKE,OAAOI,MAAK,EAAGD;AACtB;AAEA,IAAME,eAAe,CAACC,QAA2BC,QAAgBC,YAAAA;AAC/D,MAAI,CAACF,OAAOG,eAAe;AACzBb,QAAI,iCAAiC;MAAEW;IAAO,GAAA;;;;;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AwC;AAC9D,UAAMe,UAAUf,MAAMgB;AACtBC,IAAAA,KAAIC,MAAM,gCAAgC;MACxCN,SAASG,QAAQH;MACjBO,SAASJ,QAAQI;IACnB,GAAA;;;;;;EACF;AACF;",
6
- "names": ["UAParser", "log", "browser", "os", "navigator", "parser", "userAgent", "getBrowser", "name", "getOS", "sendToIFrame", "iframe", "origin", "message", "contentWindow", "postMessage", "payload", "sendToParentWindow", "window", "parent", "createIFramePort", "channel", "onOrigin", "send", "data", "length", "buffer", "slice", "byteOffset", "byteLength", "subscribe", "callback", "handler", "event", "source", "isMessageData", "undefined", "Uint8Array", "addEventListener", "removeEventListener", "createIFrame", "id", "hidden", "allow", "create", "document", "createElement", "src", "setAttribute", "body", "appendChild", "getElementById", "log", "createWorkerPort", "port", "channel", "subscribe", "send", "message", "payload", "buffer", "slice", "byteOffset", "byteLength", "postMessage", "callback", "handler", "event", "data", "debug", "Uint8Array", "onmessage", "log", "PortMuxer", "_messagePort", "_activeChannels", "Map", "_rpcPorts", "onmessage", "event", "onWorkerMessage", "window", "addEventListener", "onWindowMessage", "createWorkerPort", "options", "Error", "port", "subscribe", "callback", "set", "channel", "delete", "createIFramePort", "message", "data", "log", "debug", "payload", "get", "Uint8Array"]
4
+ "sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nimport UAParser from 'ua-parser-js';\n\nimport { log } from '@dxos/log';\nimport { type RpcPort } from '@dxos/rpc';\n\nimport { type MessageData } from '../message';\n\nlet browser: string | undefined;\nlet os: string | undefined;\n\nif (typeof navigator !== 'undefined') {\n // TODO(wittjosiah): Stop user agent parsing.\n const parser = new UAParser(navigator.userAgent);\n browser = parser.getBrowser().name;\n os = parser.getOS().name;\n}\n\nconst sendToIFrame = (iframe: HTMLIFrameElement, origin: string, message: MessageData) => {\n if (!iframe.contentWindow) {\n log('IFrame content window missing', { origin });\n return;\n }\n\n if (browser === 'Chrome' && os === 'iOS') {\n iframe.contentWindow.postMessage(message, origin);\n } else {\n iframe.contentWindow.postMessage(message, origin, [message.payload]);\n }\n};\n\nconst sendToParentWindow = (origin: string, message: MessageData) => {\n if (browser === 'Chrome' && os === 'iOS') {\n window.parent.postMessage(message, origin);\n } else {\n window.parent.postMessage(message, origin, [message.payload]);\n }\n};\n\nexport type IFramePortOptions = {\n channel: string;\n iframe?: HTMLIFrameElement;\n origin?: string;\n onOrigin?: (origin: string) => void;\n};\n\n/**\n * Create a RPC port with an iframe over window messaging.\n * @param options.channel Identifier for sent/recieved messages.\n * @param options.iframe Instance of the iframe if sending to child.\n * @param options.origin Origin of the destination window.\n * @param options.onOrigin Callback triggered when origin of destination window is verified.\n * @returns RPC port for messaging.\n */\nexport const createIFramePort = ({ channel, iframe, origin, onOrigin }: IFramePortOptions): RpcPort => {\n return {\n send: async (data) => {\n if (!origin) {\n log('no origin set', { channel });\n return;\n }\n\n log('sending', { channel, data: data.length });\n const payload = data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);\n const message = { channel, payload };\n if (iframe) {\n sendToIFrame(iframe, origin, message);\n } else {\n sendToParentWindow(origin, message);\n }\n },\n\n subscribe: (callback) => {\n const handler = (event: MessageEvent<unknown>) => {\n if (!iframe && event.source !== window.parent) {\n // Not from parent window.\n return;\n } else if (iframe && event.source !== iframe.contentWindow) {\n // Not from child window.\n return;\n }\n\n const isMessageData =\n event.data && typeof event.data === 'object' && 'channel' in event.data && 'payload' in event.data;\n const message = isMessageData ? (event.data as MessageData) : undefined;\n if (message?.channel !== channel) {\n return;\n }\n\n if (!origin) {\n origin = event.origin;\n onOrigin?.(origin);\n }\n\n log('received', message);\n callback(new Uint8Array(message.payload));\n };\n\n window.addEventListener('message', handler);\n return () => window.removeEventListener('message', handler);\n },\n };\n};\n\nexport type CreateIFrameOptions = {\n hidden?: boolean;\n allow?: string;\n};\n\n/**\n * Create a hidden iframe and insert it into the DOM.\n * If an element with the same id already exists it will be returned instead.\n * @param source Source of the iframe.\n * @param id DOM id of the iframe.\n * @returns The created iframe.\n */\nexport const createIFrame = (source: string, id: string, { hidden = true, allow }: CreateIFrameOptions = {}) => {\n const create = () => {\n const iframe = document.createElement('iframe') as HTMLIFrameElement;\n iframe.id = id;\n iframe.src = source;\n hidden && iframe.setAttribute('style', 'display: none;');\n allow && iframe.setAttribute('allow', allow);\n document.body.appendChild(iframe);\n return iframe;\n };\n\n return (document.getElementById(id) as HTMLIFrameElement) ?? create();\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { log } from '@dxos/log';\nimport { type RpcPort } from '@dxos/rpc';\n\nimport { type MessageData } from '../message';\n\nexport type WorkerPortOptions = {\n port: MessagePort;\n channel?: string;\n subscribe?: RpcPort['subscribe'];\n};\n\n/**\n * Create a RPC port for a worker.\n * @param options.port Message port to send message on.\n * @param options.channel Identifier for sent/recieved messages.\n * @param options.subscribe\n * @returns RPC port for messaging.\n */\n// TODO(wittjosiah): Rename for more general purpose MessagePort.\nexport const createWorkerPort = ({ port, channel, subscribe }: WorkerPortOptions): RpcPort => ({\n send: async (message) => {\n // Based on https://stackoverflow.com/a/54646864/2804332.\n const payload = message.buffer.slice(message.byteOffset, message.byteOffset + message.byteLength);\n port.postMessage(\n {\n channel,\n payload,\n },\n [payload],\n );\n },\n\n subscribe:\n subscribe ??\n ((callback) => {\n const handler = (event: MessageEvent<MessageData>) => {\n const message = event.data;\n if (channel && message.channel !== channel) {\n return;\n }\n\n log.debug('received', { message });\n callback(new Uint8Array(message.payload));\n };\n\n port.onmessage = handler;\n return () => {\n port.onmessage = null;\n };\n }),\n});\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { log } from '@dxos/log';\nimport { type RpcPort } from '@dxos/rpc';\n\nimport { type MessageData } from './message';\nimport { type IFramePortOptions, type WorkerPortOptions, createIFramePort, createWorkerPort } from './ports';\n\n/**\n * Facilitates the multiplexing of multiple RpcPorts over a single MessagePort.\n */\nexport class PortMuxer {\n private readonly _activeChannels = new Map<string, (msg: Uint8Array) => void>();\n\n private readonly _rpcPorts = new Map<string, RpcPort>();\n\n constructor(private readonly _messagePort?: MessagePort) {\n if (this._messagePort) {\n this._messagePort.onmessage = (event) => this.onWorkerMessage(event);\n }\n\n if (typeof window !== 'undefined') {\n window.addEventListener('message', (event) => this.onWindowMessage(event));\n }\n }\n\n createWorkerPort(options: Omit<WorkerPortOptions, 'port' | 'subscribe' | 'channel'> & { channel: string }): RpcPort {\n if (!this._messagePort) {\n throw new Error('Message port is required to create worker ports');\n }\n\n const port = createWorkerPort({\n ...options,\n port: this._messagePort,\n subscribe: (callback) => {\n this._activeChannels.set(options.channel, callback);\n return () => this._activeChannels.delete(options.channel);\n },\n });\n this._rpcPorts.set(options.channel, port);\n\n return port;\n }\n\n createIFramePort(options: IFramePortOptions): RpcPort {\n const port = createIFramePort(options);\n this._rpcPorts.set(options.channel, port);\n\n return port;\n }\n\n private onWorkerMessage(event: MessageEvent<MessageData>): void {\n const message = event.data;\n log.debug('Recieved message from worker port', {\n channel: message.channel,\n payload: message.payload,\n });\n\n const callback = this._activeChannels.get(message.channel);\n callback?.(new Uint8Array(message.payload));\n }\n\n private onWindowMessage(event: MessageEvent<MessageData>): void {\n const message = event.data;\n log.debug('Recieved message from window', {\n channel: message.channel,\n payload: message.payload,\n });\n }\n}\n"],
5
+ "mappings": ";AAIA,OAAOA,cAAc;AAErB,SAASC,WAAW;;AAKpB,IAAIC;AACJ,IAAIC;AAEJ,IAAI,OAAOC,cAAc,aAAa;AAEpC,QAAMC,SAAS,IAAIL,SAASI,UAAUE,SAAS;AAC/CJ,YAAUG,OAAOE,WAAU,EAAGC;AAC9BL,OAAKE,OAAOI,MAAK,EAAGD;AACtB;AAEA,IAAME,eAAe,CAACC,QAA2BC,QAAgBC,YAAAA;AAC/D,MAAI,CAACF,OAAOG,eAAe;AACzBb,QAAI,iCAAiC;MAAEW;IAAO,GAAA;;;;;;AAC9C;EACF;AAEA,MAAIV,YAAY,YAAYC,OAAO,OAAO;AACxCQ,WAAOG,cAAcC,YAAYF,SAASD,MAAAA;EAC5C,OAA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,QAAQI;IACnB,GAAA;;;;;;EACF;AACF;",
6
+ "names": ["UAParser", "log", "browser", "os", "navigator", "parser", "userAgent", "getBrowser", "name", "getOS", "sendToIFrame", "iframe", "origin", "message", "contentWindow", "postMessage", "payload", "sendToParentWindow", "window", "parent", "createIFramePort", "channel", "onOrigin", "send", "data", "length", "buffer", "slice", "byteOffset", "byteLength", "subscribe", "callback", "handler", "event", "source", "isMessageData", "undefined", "Uint8Array", "addEventListener", "removeEventListener", "createIFrame", "id", "hidden", "allow", "create", "document", "createElement", "src", "setAttribute", "body", "appendChild", "getElementById", "log", "createWorkerPort", "port", "channel", "subscribe", "send", "message", "payload", "buffer", "slice", "byteOffset", "byteLength", "postMessage", "callback", "handler", "event", "data", "debug", "Uint8Array", "onmessage", "log", "PortMuxer", "_activeChannels", "Map", "_rpcPorts", "_messagePort", "onmessage", "event", "onWorkerMessage", "window", "addEventListener", "onWindowMessage", "createWorkerPort", "options", "Error", "port", "subscribe", "callback", "set", "channel", "delete", "createIFramePort", "message", "data", "log", "debug", "payload", "get", "Uint8Array"]
7
7
  }
@@ -1 +1 @@
1
- {"inputs":{"src/message.ts":{"bytes":510,"imports":[],"format":"esm"},"src/ports/iframe.ts":{"bytes":13983,"imports":[{"path":"ua-parser-js","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"format":"esm"},"src/ports/worker.ts":{"bytes":4832,"imports":[{"path":"@dxos/log","kind":"import-statement","external":true}],"format":"esm"},"src/ports/index.ts":{"bytes":542,"imports":[{"path":"src/ports/iframe.ts","kind":"import-statement","original":"./iframe"},{"path":"src/ports/worker.ts","kind":"import-statement","original":"./worker"}],"format":"esm"},"src/port-muxer.ts":{"bytes":7608,"imports":[{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"src/ports/index.ts","kind":"import-statement","original":"./ports"}],"format":"esm"},"src/index.ts":{"bytes":630,"imports":[{"path":"src/message.ts","kind":"import-statement","original":"./message"},{"path":"src/ports/index.ts","kind":"import-statement","original":"./ports"},{"path":"src/port-muxer.ts","kind":"import-statement","original":"./port-muxer"}],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":12796},"dist/lib/browser/index.mjs":{"imports":[{"path":"ua-parser-js","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"exports":["PortMuxer","createIFrame","createIFramePort","createWorkerPort"],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":0},"src/ports/iframe.ts":{"bytesInOutput":3186},"src/ports/index.ts":{"bytesInOutput":0},"src/ports/worker.ts":{"bytesInOutput":902},"src/port-muxer.ts":{"bytesInOutput":1840}},"bytes":6112}}}
1
+ {"inputs":{"src/ports/iframe.ts":{"bytes":13967,"imports":[{"path":"ua-parser-js","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"format":"esm"},"src/ports/worker.ts":{"bytes":4832,"imports":[{"path":"@dxos/log","kind":"import-statement","external":true}],"format":"esm"},"src/ports/index.ts":{"bytes":542,"imports":[{"path":"src/ports/iframe.ts","kind":"import-statement","original":"./iframe"},{"path":"src/ports/worker.ts","kind":"import-statement","original":"./worker"}],"format":"esm"},"src/port-muxer.ts":{"bytes":7534,"imports":[{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"src/ports/index.ts","kind":"import-statement","original":"./ports"}],"format":"esm"},"src/index.ts":{"bytes":587,"imports":[{"path":"src/ports/index.ts","kind":"import-statement","original":"./ports"},{"path":"src/port-muxer.ts","kind":"import-statement","original":"./port-muxer"}],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":12793},"dist/lib/browser/index.mjs":{"imports":[{"path":"ua-parser-js","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"exports":["PortMuxer","createIFrame","createIFramePort","createWorkerPort"],"entryPoint":"src/index.ts","inputs":{"src/ports/iframe.ts":{"bytesInOutput":3182},"src/ports/index.ts":{"bytesInOutput":0},"src/ports/worker.ts":{"bytesInOutput":902},"src/index.ts":{"bytesInOutput":0},"src/port-muxer.ts":{"bytesInOutput":1842}},"bytes":6110}}}
@@ -1,7 +1,7 @@
1
1
  import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
2
 
3
3
  // src/ports/iframe.ts
4
- import { UAParser } from "ua-parser-js";
4
+ import UAParser from "ua-parser-js";
5
5
  import { log } from "@dxos/log";
6
6
  var __dxlog_file = "/__w/dxos/dxos/packages/core/mesh/rpc-tunnel/src/ports/iframe.ts";
7
7
  var browser;
@@ -156,10 +156,11 @@ var createWorkerPort = ({ port, channel, subscribe }) => ({
156
156
  import { log as log3 } from "@dxos/log";
157
157
  var __dxlog_file3 = "/__w/dxos/dxos/packages/core/mesh/rpc-tunnel/src/port-muxer.ts";
158
158
  var PortMuxer = class {
159
+ _messagePort;
160
+ _activeChannels = /* @__PURE__ */ new Map();
161
+ _rpcPorts = /* @__PURE__ */ new Map();
159
162
  constructor(_messagePort) {
160
163
  this._messagePort = _messagePort;
161
- this._activeChannels = /* @__PURE__ */ new Map();
162
- this._rpcPorts = /* @__PURE__ */ new Map();
163
164
  if (this._messagePort) {
164
165
  this._messagePort.onmessage = (event) => this.onWorkerMessage(event);
165
166
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/ports/iframe.ts", "../../../src/ports/worker.ts", "../../../src/port-muxer.ts"],
4
- "sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nimport { UAParser } from 'ua-parser-js';\n\nimport { log } from '@dxos/log';\nimport { type RpcPort } from '@dxos/rpc';\n\nimport { type MessageData } from '../message';\n\nlet browser: string | undefined;\nlet os: string | undefined;\n\nif (typeof navigator !== 'undefined') {\n // TODO(wittjosiah): Stop user agent parsing.\n const parser = new UAParser(navigator.userAgent);\n browser = parser.getBrowser().name;\n os = parser.getOS().name;\n}\n\nconst sendToIFrame = (iframe: HTMLIFrameElement, origin: string, message: MessageData) => {\n if (!iframe.contentWindow) {\n log('IFrame content window missing', { origin });\n return;\n }\n\n if (browser === 'Chrome' && os === 'iOS') {\n iframe.contentWindow.postMessage(message, origin);\n } else {\n iframe.contentWindow.postMessage(message, origin, [message.payload]);\n }\n};\n\nconst sendToParentWindow = (origin: string, message: MessageData) => {\n if (browser === 'Chrome' && os === 'iOS') {\n window.parent.postMessage(message, origin);\n } else {\n window.parent.postMessage(message, origin, [message.payload]);\n }\n};\n\nexport type IFramePortOptions = {\n channel: string;\n iframe?: HTMLIFrameElement;\n origin?: string;\n onOrigin?: (origin: string) => void;\n};\n\n/**\n * Create a RPC port with an iframe over window messaging.\n * @param options.channel Identifier for sent/recieved messages.\n * @param options.iframe Instance of the iframe if sending to child.\n * @param options.origin Origin of the destination window.\n * @param options.onOrigin Callback triggered when origin of destination window is verified.\n * @returns RPC port for messaging.\n */\nexport const createIFramePort = ({ channel, iframe, origin, onOrigin }: IFramePortOptions): RpcPort => {\n return {\n send: async (data) => {\n if (!origin) {\n log('no origin set', { channel });\n return;\n }\n\n log('sending', { channel, data: data.length });\n const payload = data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);\n const message = { channel, payload };\n if (iframe) {\n sendToIFrame(iframe, origin, message);\n } else {\n sendToParentWindow(origin, message);\n }\n },\n\n subscribe: (callback) => {\n const handler = (event: MessageEvent<unknown>) => {\n if (!iframe && event.source !== window.parent) {\n // Not from parent window.\n return;\n } else if (iframe && event.source !== iframe.contentWindow) {\n // Not from child window.\n return;\n }\n\n const isMessageData =\n event.data && typeof event.data === 'object' && 'channel' in event.data && 'payload' in event.data;\n const message = isMessageData ? (event.data as MessageData) : undefined;\n if (message?.channel !== channel) {\n return;\n }\n\n if (!origin) {\n origin = event.origin;\n onOrigin?.(origin);\n }\n\n log('received', message);\n callback(new Uint8Array(message.payload));\n };\n\n window.addEventListener('message', handler);\n return () => window.removeEventListener('message', handler);\n },\n };\n};\n\nexport type CreateIFrameOptions = {\n hidden?: boolean;\n allow?: string;\n};\n\n/**\n * Create a hidden iframe and insert it into the DOM.\n * If an element with the same id already exists it will be returned instead.\n * @param source Source of the iframe.\n * @param id DOM id of the iframe.\n * @returns The created iframe.\n */\nexport const createIFrame = (source: string, id: string, { hidden = true, allow }: CreateIFrameOptions = {}) => {\n const create = () => {\n const iframe = document.createElement('iframe') as HTMLIFrameElement;\n iframe.id = id;\n iframe.src = source;\n hidden && iframe.setAttribute('style', 'display: none;');\n allow && iframe.setAttribute('allow', allow);\n document.body.appendChild(iframe);\n return iframe;\n };\n\n return (document.getElementById(id) as HTMLIFrameElement) ?? create();\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { log } from '@dxos/log';\nimport { type RpcPort } from '@dxos/rpc';\n\nimport { type MessageData } from '../message';\n\nexport type WorkerPortOptions = {\n port: MessagePort;\n channel?: string;\n subscribe?: RpcPort['subscribe'];\n};\n\n/**\n * Create a RPC port for a worker.\n * @param options.port Message port to send message on.\n * @param options.channel Identifier for sent/recieved messages.\n * @param options.subscribe\n * @returns RPC port for messaging.\n */\n// TODO(wittjosiah): Rename for more general purpose MessagePort.\nexport const createWorkerPort = ({ port, channel, subscribe }: WorkerPortOptions): RpcPort => ({\n send: async (message) => {\n // Based on https://stackoverflow.com/a/54646864/2804332.\n const payload = message.buffer.slice(message.byteOffset, message.byteOffset + message.byteLength);\n port.postMessage(\n {\n channel,\n payload,\n },\n [payload],\n );\n },\n\n subscribe:\n subscribe ??\n ((callback) => {\n const handler = (event: MessageEvent<MessageData>) => {\n const message = event.data;\n if (channel && message.channel !== channel) {\n return;\n }\n\n log.debug('received', { message });\n callback(new Uint8Array(message.payload));\n };\n\n port.onmessage = handler;\n return () => {\n port.onmessage = null;\n };\n }),\n});\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { log } from '@dxos/log';\nimport { type RpcPort } from '@dxos/rpc';\n\nimport { type MessageData } from './message';\nimport { createIFramePort, createWorkerPort, type IFramePortOptions, type WorkerPortOptions } from './ports';\n\n/**\n * Facilitates the multiplexing of multiple RpcPorts over a single MessagePort.\n */\nexport class PortMuxer {\n private readonly _activeChannels = new Map<string, (msg: Uint8Array) => void>();\n\n private readonly _rpcPorts = new Map<string, RpcPort>();\n\n constructor(private readonly _messagePort?: MessagePort) {\n if (this._messagePort) {\n this._messagePort.onmessage = (event) => this.onWorkerMessage(event);\n }\n\n if (typeof window !== 'undefined') {\n window.addEventListener('message', (event) => this.onWindowMessage(event));\n }\n }\n\n createWorkerPort(options: Omit<WorkerPortOptions, 'port' | 'subscribe' | 'channel'> & { channel: string }): RpcPort {\n if (!this._messagePort) {\n throw new Error('Message port is required to create worker ports');\n }\n\n const port = createWorkerPort({\n ...options,\n port: this._messagePort,\n subscribe: (callback) => {\n this._activeChannels.set(options.channel, callback);\n return () => this._activeChannels.delete(options.channel);\n },\n });\n this._rpcPorts.set(options.channel, port);\n\n return port;\n }\n\n createIFramePort(options: IFramePortOptions): RpcPort {\n const port = createIFramePort(options);\n this._rpcPorts.set(options.channel, port);\n\n return port;\n }\n\n private onWorkerMessage(event: MessageEvent<MessageData>): void {\n const message = event.data;\n log.debug('Recieved message from worker port', {\n channel: message.channel,\n payload: message.payload,\n });\n\n const callback = this._activeChannels.get(message.channel);\n callback?.(new Uint8Array(message.payload));\n }\n\n private onWindowMessage(event: MessageEvent<MessageData>): void {\n const message = event.data;\n log.debug('Recieved message from window', {\n channel: message.channel,\n payload: message.payload,\n });\n }\n}\n"],
5
- "mappings": ";;;AAIA,SAASA,gBAAgB;AAEzB,SAASC,WAAW;;AAKpB,IAAIC;AACJ,IAAIC;AAEJ,IAAI,OAAOC,cAAc,aAAa;AAEpC,QAAMC,SAAS,IAAIL,SAASI,UAAUE,SAAS;AAC/CJ,YAAUG,OAAOE,WAAU,EAAGC;AAC9BL,OAA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AAQI;IACnB,GAAA;;;;;;AAEA,UAAMT,WAAW,KAAKd,gBAAgBwB,IAAIL,QAAQH,OAAO;AACzDF,eAAW,IAAIW,WAAWN,QAAQI,OAAO,CAAA;EAC3C;EAEQf,gBAAgBJ,OAAwC;AAC9D,UAAMe,UAAUf,MAAMgB;AACtBC,IAAAA,KAAIC,MAAM,gCAAgC;MACxCN,SAASG,QAAQH;MACjBO,SAASJ,QAAQI;IACnB,GAAA;;;;;;EACF;AACF;",
6
- "names": ["UAParser", "log", "browser", "os", "navigator", "parser", "userAgent", "getBrowser", "name", "getOS", "sendToIFrame", "iframe", "origin", "message", "contentWindow", "postMessage", "payload", "sendToParentWindow", "window", "parent", "createIFramePort", "channel", "onOrigin", "send", "data", "length", "buffer", "slice", "byteOffset", "byteLength", "subscribe", "callback", "handler", "event", "source", "isMessageData", "undefined", "Uint8Array", "addEventListener", "removeEventListener", "createIFrame", "id", "hidden", "allow", "create", "document", "createElement", "src", "setAttribute", "body", "appendChild", "getElementById", "log", "createWorkerPort", "port", "channel", "subscribe", "send", "message", "payload", "buffer", "slice", "byteOffset", "byteLength", "postMessage", "callback", "handler", "event", "data", "debug", "Uint8Array", "onmessage", "log", "PortMuxer", "_messagePort", "_activeChannels", "Map", "_rpcPorts", "onmessage", "event", "onWorkerMessage", "window", "addEventListener", "onWindowMessage", "createWorkerPort", "options", "Error", "port", "subscribe", "callback", "set", "channel", "delete", "createIFramePort", "message", "data", "log", "debug", "payload", "get", "Uint8Array"]
4
+ "sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nimport UAParser from 'ua-parser-js';\n\nimport { log } from '@dxos/log';\nimport { type RpcPort } from '@dxos/rpc';\n\nimport { type MessageData } from '../message';\n\nlet browser: string | undefined;\nlet os: string | undefined;\n\nif (typeof navigator !== 'undefined') {\n // TODO(wittjosiah): Stop user agent parsing.\n const parser = new UAParser(navigator.userAgent);\n browser = parser.getBrowser().name;\n os = parser.getOS().name;\n}\n\nconst sendToIFrame = (iframe: HTMLIFrameElement, origin: string, message: MessageData) => {\n if (!iframe.contentWindow) {\n log('IFrame content window missing', { origin });\n return;\n }\n\n if (browser === 'Chrome' && os === 'iOS') {\n iframe.contentWindow.postMessage(message, origin);\n } else {\n iframe.contentWindow.postMessage(message, origin, [message.payload]);\n }\n};\n\nconst sendToParentWindow = (origin: string, message: MessageData) => {\n if (browser === 'Chrome' && os === 'iOS') {\n window.parent.postMessage(message, origin);\n } else {\n window.parent.postMessage(message, origin, [message.payload]);\n }\n};\n\nexport type IFramePortOptions = {\n channel: string;\n iframe?: HTMLIFrameElement;\n origin?: string;\n onOrigin?: (origin: string) => void;\n};\n\n/**\n * Create a RPC port with an iframe over window messaging.\n * @param options.channel Identifier for sent/recieved messages.\n * @param options.iframe Instance of the iframe if sending to child.\n * @param options.origin Origin of the destination window.\n * @param options.onOrigin Callback triggered when origin of destination window is verified.\n * @returns RPC port for messaging.\n */\nexport const createIFramePort = ({ channel, iframe, origin, onOrigin }: IFramePortOptions): RpcPort => {\n return {\n send: async (data) => {\n if (!origin) {\n log('no origin set', { channel });\n return;\n }\n\n log('sending', { channel, data: data.length });\n const payload = data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);\n const message = { channel, payload };\n if (iframe) {\n sendToIFrame(iframe, origin, message);\n } else {\n sendToParentWindow(origin, message);\n }\n },\n\n subscribe: (callback) => {\n const handler = (event: MessageEvent<unknown>) => {\n if (!iframe && event.source !== window.parent) {\n // Not from parent window.\n return;\n } else if (iframe && event.source !== iframe.contentWindow) {\n // Not from child window.\n return;\n }\n\n const isMessageData =\n event.data && typeof event.data === 'object' && 'channel' in event.data && 'payload' in event.data;\n const message = isMessageData ? (event.data as MessageData) : undefined;\n if (message?.channel !== channel) {\n return;\n }\n\n if (!origin) {\n origin = event.origin;\n onOrigin?.(origin);\n }\n\n log('received', message);\n callback(new Uint8Array(message.payload));\n };\n\n window.addEventListener('message', handler);\n return () => window.removeEventListener('message', handler);\n },\n };\n};\n\nexport type CreateIFrameOptions = {\n hidden?: boolean;\n allow?: string;\n};\n\n/**\n * Create a hidden iframe and insert it into the DOM.\n * If an element with the same id already exists it will be returned instead.\n * @param source Source of the iframe.\n * @param id DOM id of the iframe.\n * @returns The created iframe.\n */\nexport const createIFrame = (source: string, id: string, { hidden = true, allow }: CreateIFrameOptions = {}) => {\n const create = () => {\n const iframe = document.createElement('iframe') as HTMLIFrameElement;\n iframe.id = id;\n iframe.src = source;\n hidden && iframe.setAttribute('style', 'display: none;');\n allow && iframe.setAttribute('allow', allow);\n document.body.appendChild(iframe);\n return iframe;\n };\n\n return (document.getElementById(id) as HTMLIFrameElement) ?? create();\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { log } from '@dxos/log';\nimport { type RpcPort } from '@dxos/rpc';\n\nimport { type MessageData } from '../message';\n\nexport type WorkerPortOptions = {\n port: MessagePort;\n channel?: string;\n subscribe?: RpcPort['subscribe'];\n};\n\n/**\n * Create a RPC port for a worker.\n * @param options.port Message port to send message on.\n * @param options.channel Identifier for sent/recieved messages.\n * @param options.subscribe\n * @returns RPC port for messaging.\n */\n// TODO(wittjosiah): Rename for more general purpose MessagePort.\nexport const createWorkerPort = ({ port, channel, subscribe }: WorkerPortOptions): RpcPort => ({\n send: async (message) => {\n // Based on https://stackoverflow.com/a/54646864/2804332.\n const payload = message.buffer.slice(message.byteOffset, message.byteOffset + message.byteLength);\n port.postMessage(\n {\n channel,\n payload,\n },\n [payload],\n );\n },\n\n subscribe:\n subscribe ??\n ((callback) => {\n const handler = (event: MessageEvent<MessageData>) => {\n const message = event.data;\n if (channel && message.channel !== channel) {\n return;\n }\n\n log.debug('received', { message });\n callback(new Uint8Array(message.payload));\n };\n\n port.onmessage = handler;\n return () => {\n port.onmessage = null;\n };\n }),\n});\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { log } from '@dxos/log';\nimport { type RpcPort } from '@dxos/rpc';\n\nimport { type MessageData } from './message';\nimport { type IFramePortOptions, type WorkerPortOptions, createIFramePort, createWorkerPort } from './ports';\n\n/**\n * Facilitates the multiplexing of multiple RpcPorts over a single MessagePort.\n */\nexport class PortMuxer {\n private readonly _activeChannels = new Map<string, (msg: Uint8Array) => void>();\n\n private readonly _rpcPorts = new Map<string, RpcPort>();\n\n constructor(private readonly _messagePort?: MessagePort) {\n if (this._messagePort) {\n this._messagePort.onmessage = (event) => this.onWorkerMessage(event);\n }\n\n if (typeof window !== 'undefined') {\n window.addEventListener('message', (event) => this.onWindowMessage(event));\n }\n }\n\n createWorkerPort(options: Omit<WorkerPortOptions, 'port' | 'subscribe' | 'channel'> & { channel: string }): RpcPort {\n if (!this._messagePort) {\n throw new Error('Message port is required to create worker ports');\n }\n\n const port = createWorkerPort({\n ...options,\n port: this._messagePort,\n subscribe: (callback) => {\n this._activeChannels.set(options.channel, callback);\n return () => this._activeChannels.delete(options.channel);\n },\n });\n this._rpcPorts.set(options.channel, port);\n\n return port;\n }\n\n createIFramePort(options: IFramePortOptions): RpcPort {\n const port = createIFramePort(options);\n this._rpcPorts.set(options.channel, port);\n\n return port;\n }\n\n private onWorkerMessage(event: MessageEvent<MessageData>): void {\n const message = event.data;\n log.debug('Recieved message from worker port', {\n channel: message.channel,\n payload: message.payload,\n });\n\n const callback = this._activeChannels.get(message.channel);\n callback?.(new Uint8Array(message.payload));\n }\n\n private onWindowMessage(event: MessageEvent<MessageData>): void {\n const message = event.data;\n log.debug('Recieved message from window', {\n channel: message.channel,\n payload: message.payload,\n });\n }\n}\n"],
5
+ "mappings": ";;;AAIA,OAAOA,cAAc;AAErB,SAASC,WAAW;;AAKpB,IAAIC;AACJ,IAAIC;AAEJ,IAAI,OAAOC,cAAc,aAAa;AAEpC,QAAMC,SAAS,IAAIL,SAASI,UAAUE,SAAS;AAC/CJ,YAAUG,OAAOE,WAAU,EAAGC;AAC9BL,OAAKE,OAAOI,MAAK,EAAGD;AACtB;AAEA,IAAME,eAAe,CAACC,QAA2BC,QAAgBC,YAAAA;AAC/D,MAAI,CAACF,OAAOG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WAAWN,QAAQI,OAAO,CAAA;EAC3C;EAEQf,gBAAgBJ,OAAwC;AAC9D,UAAMe,UAAUf,MAAMgB;AACtBC,IAAAA,KAAIC,MAAM,gCAAgC;MACxCN,SAASG,QAAQH;MACjBO,SAASJ,QAAQI;IACnB,GAAA;;;;;;EACF;AACF;",
6
+ "names": ["UAParser", "log", "browser", "os", "navigator", "parser", "userAgent", "getBrowser", "name", "getOS", "sendToIFrame", "iframe", "origin", "message", "contentWindow", "postMessage", "payload", "sendToParentWindow", "window", "parent", "createIFramePort", "channel", "onOrigin", "send", "data", "length", "buffer", "slice", "byteOffset", "byteLength", "subscribe", "callback", "handler", "event", "source", "isMessageData", "undefined", "Uint8Array", "addEventListener", "removeEventListener", "createIFrame", "id", "hidden", "allow", "create", "document", "createElement", "src", "setAttribute", "body", "appendChild", "getElementById", "log", "createWorkerPort", "port", "channel", "subscribe", "send", "message", "payload", "buffer", "slice", "byteOffset", "byteLength", "postMessage", "callback", "handler", "event", "data", "debug", "Uint8Array", "onmessage", "log", "PortMuxer", "_activeChannels", "Map", "_rpcPorts", "_messagePort", "onmessage", "event", "onWorkerMessage", "window", "addEventListener", "onWindowMessage", "createWorkerPort", "options", "Error", "port", "subscribe", "callback", "set", "channel", "delete", "createIFramePort", "message", "data", "log", "debug", "payload", "get", "Uint8Array"]
7
7
  }
@@ -1 +1 @@
1
- {"inputs":{"src/message.ts":{"bytes":510,"imports":[],"format":"esm"},"src/ports/iframe.ts":{"bytes":13983,"imports":[{"path":"ua-parser-js","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"format":"esm"},"src/ports/worker.ts":{"bytes":4832,"imports":[{"path":"@dxos/log","kind":"import-statement","external":true}],"format":"esm"},"src/ports/index.ts":{"bytes":542,"imports":[{"path":"src/ports/iframe.ts","kind":"import-statement","original":"./iframe"},{"path":"src/ports/worker.ts","kind":"import-statement","original":"./worker"}],"format":"esm"},"src/port-muxer.ts":{"bytes":7608,"imports":[{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"src/ports/index.ts","kind":"import-statement","original":"./ports"}],"format":"esm"},"src/index.ts":{"bytes":630,"imports":[{"path":"src/message.ts","kind":"import-statement","original":"./message"},{"path":"src/ports/index.ts","kind":"import-statement","original":"./ports"},{"path":"src/port-muxer.ts","kind":"import-statement","original":"./port-muxer"}],"format":"esm"}},"outputs":{"dist/lib/node-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":12798},"dist/lib/node-esm/index.mjs":{"imports":[{"path":"ua-parser-js","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"exports":["PortMuxer","createIFrame","createIFramePort","createWorkerPort"],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":0},"src/ports/iframe.ts":{"bytesInOutput":3186},"src/ports/index.ts":{"bytesInOutput":0},"src/ports/worker.ts":{"bytesInOutput":902},"src/port-muxer.ts":{"bytesInOutput":1840}},"bytes":6205}}}
1
+ {"inputs":{"src/ports/iframe.ts":{"bytes":13967,"imports":[{"path":"ua-parser-js","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"format":"esm"},"src/ports/worker.ts":{"bytes":4832,"imports":[{"path":"@dxos/log","kind":"import-statement","external":true}],"format":"esm"},"src/ports/index.ts":{"bytes":542,"imports":[{"path":"src/ports/iframe.ts","kind":"import-statement","original":"./iframe"},{"path":"src/ports/worker.ts","kind":"import-statement","original":"./worker"}],"format":"esm"},"src/port-muxer.ts":{"bytes":7534,"imports":[{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"src/ports/index.ts","kind":"import-statement","original":"./ports"}],"format":"esm"},"src/index.ts":{"bytes":587,"imports":[{"path":"src/ports/index.ts","kind":"import-statement","original":"./ports"},{"path":"src/port-muxer.ts","kind":"import-statement","original":"./port-muxer"}],"format":"esm"}},"outputs":{"dist/lib/node-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":12795},"dist/lib/node-esm/index.mjs":{"imports":[{"path":"ua-parser-js","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"exports":["PortMuxer","createIFrame","createIFramePort","createWorkerPort"],"entryPoint":"src/index.ts","inputs":{"src/ports/iframe.ts":{"bytesInOutput":3182},"src/ports/index.ts":{"bytesInOutput":0},"src/ports/worker.ts":{"bytesInOutput":902},"src/index.ts":{"bytesInOutput":0},"src/port-muxer.ts":{"bytesInOutput":1842}},"bytes":6203}}}
@@ -1,4 +1,4 @@
1
- export * from './message';
1
+ export type * from './message';
2
2
  export * from './ports';
3
3
  export * from './port-muxer';
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,mBAAmB,WAAW,CAAC;AAC/B,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"port-muxer.d.ts","sourceRoot":"","sources":["../../../src/port-muxer.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,WAAW,CAAC;AAGzC,OAAO,EAAsC,KAAK,iBAAiB,EAAE,KAAK,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAE7G;;GAEG;AACH,qBAAa,SAAS;IAKR,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC;IAJ1C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAgD;IAEhF,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA8B;gBAE3B,YAAY,CAAC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