@zhyi64/message-bridge 0.1.0 → 0.1.1

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.
package/dist/index.cjs.js CHANGED
@@ -1,2 +1,2 @@
1
- var c=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var m=(i,e)=>{for(var t in e)c(i,t,{get:e[t],enumerable:!0})},b=(i,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of p(e))!w.call(i,r)&&r!==t&&c(i,r,{get:()=>e[r],enumerable:!(n=f(e,r))||n.enumerable});return i};var W=i=>b(c({},"__esModule",{value:!0}),i);var R={};m(R,{OnePcBridge:()=>u,Router:()=>o,createEnvelope:()=>a,parseEnvelope:()=>l,serializeEnvelope:()=>s});module.exports=W(R);var y=0;function h(){let i=Date.now().toString(36),e=(++y).toString(36);return`mb_${i}_${e}`}function a(i,e,t,n){return{protocol:"message-bridge-v1",id:h(),from:i,to:e,type:t,payload:n??null,timestamp:Date.now()}}function l(i){if(!i)return null;if(i.protocol==="message-bridge-v1")return i;let e=i;if(e.message&&e.message.subtype==="webToPc"){let t=e.message.data,n;if(typeof t=="string")try{n=JSON.parse(t)}catch{return null}else if(typeof t=="object")n=t;else return null;let{type:r,...d}=n;return r?{protocol:"message-bridge-v1",id:e.id||h(),from:g(e.from),to:E(e.to),type:String(r),payload:d,timestamp:Date.now()}:null}return e.message&&e.message.subtype==="openclawToPc"?{protocol:"message-bridge-v1",id:e.id||h(),from:g(e.from),to:"onepcweb",type:"openclawToPc",payload:e.message.data,timestamp:Date.now()}:null}function g(i){return i?i.includes("openclaw")||i.includes("claw")?"openclaw":i.includes("intelligent")?"intelligent":i.includes("vantage")||i.includes("onepc")?"onepcweb":"intelligent":"intelligent"}function E(i){return i?i.includes("pcWeb")||i.includes("pcMessage")?"onepcweb":i.includes("intelligent")?"intelligent":i.includes("openclaw")||i.includes("claw")?"openclaw":"intelligent":"intelligent"}function s(i){return{...i}}var o=class{constructor(e={}){this.routes=[],this.parentWindow=e.parentWindow??null,this.getChildWindow=e.getChildWindow??null,this.debug=e.debug??!1}addRoute(e,t){this.removeRoute(e,t),this.routes.push({from:e,to:t}),this.log("route registered:",`${e} \u2192 ${t}`)}removeRoute(e,t){this.routes=this.routes.filter(n=>!(n.from===e&&n.to===t))}clearRoutes(){this.routes=[]}getForwardTarget(e){return this.routes.find(n=>n.from===e.from&&n.to===e.to)?e.to==="onepcweb"&&this.parentWindow?this.parentWindow:e.from==="onepcweb"&&this.getChildWindow?this.getChildWindow():e.to!=="intelligent"&&this.parentWindow?this.parentWindow:null:null}forward(e){let t=this.getForwardTarget(e);if(!t)return!1;let n=s(e);return t.postMessage(n,"*"),this.log("forwarded:",`${e.from} \u2192 ${e.to} via postMessage`,e.type),!0}hasRoute(e,t){return this.routes.some(n=>n.from===e&&n.to===t)}process(e){return this.hasRoute(e.from,e.to)?this.forward(e):!1}log(...e){this.debug&&console.log("[OnePcBridge-Router]",...e)}};var u=class{constructor(e){this.config=e,this.handlers=new Map,this.router=new o({parentWindow:e.parentWindow,getChildWindow:e.getChildWindow,debug:e.debug??!1}),this.messageHandler=null,this.initialized=!1}init(){this.initialized||(this.messageHandler=this.handleMessage.bind(this),window.addEventListener("message",this.messageHandler),this.initialized=!0,this.log("initialized",this.config.nodeId))}destroy(){this.messageHandler&&(window.removeEventListener("message",this.messageHandler),this.messageHandler=null),this.handlers.clear(),this.initialized=!1,this.log("destroyed")}send(e,t,n){let r=a(this.config.nodeId,e,t,n);this.log("send:",`${this.config.nodeId} \u2192 ${e}`,t,n);let d=this.getTargetWindow(e);d?d.postMessage(s(r),"*"):this.warn("no target window for:",e)}on(e,t){return this.handlers.has(e)||this.handlers.set(e,new Set),this.handlers.get(e).add(t),()=>{let n=this.handlers.get(e);n&&(n.delete(t),n.size===0&&this.handlers.delete(e))}}addRoute(e,t){this.router?.addRoute(e,t)}removeRoute(e,t){this.router?.removeRoute(e,t)}handleMessage(e){if(e.origin&&!this.config.allowedOrigins.includes(e.origin))return;let t=l(e.data);if(t&&!(t.from===this.config.nodeId&&t.to===this.config.nodeId)){if(t.to!==this.config.nodeId){if(this.router?.process(t)){this.dispatch(t);return}return}this.dispatch(t)}}dispatch(e){let t=this.handlers.get(e.type);if(t)for(let n of t)try{n(e.payload,e)}catch(r){this.warn("handler error:",e.type,r)}}getTargetWindow(e){return this.config.parentWindow&&e!==this.config.nodeId?this.config.parentWindow:this.config.getChildWindow?this.config.getChildWindow():null}log(...e){this.config.debug&&console.log(`[OnePcBridge:${this.config.nodeId}]`,...e)}warn(...e){console.warn(`[OnePcBridge:${this.config.nodeId}]`,...e)}};
1
+ var a=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames,l=Object.getOwnPropertySymbols;var c=Object.prototype.hasOwnProperty,w=Object.prototype.propertyIsEnumerable;var p=(i,e,t)=>e in i?a(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,m=(i,e)=>{for(var t in e||(e={}))c.call(e,t)&&p(i,t,e[t]);if(l)for(var t of l(e))w.call(e,t)&&p(i,t,e[t]);return i};var b=(i,e)=>{var t={};for(var n in i)c.call(i,n)&&e.indexOf(n)<0&&(t[n]=i[n]);if(i!=null&&l)for(var n of l(i))e.indexOf(n)<0&&w.call(i,n)&&(t[n]=i[n]);return t};var v=(i,e)=>{for(var t in e)a(i,t,{get:e[t],enumerable:!0})},z=(i,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of R(e))!c.call(i,r)&&r!==t&&a(i,r,{get:()=>e[r],enumerable:!(n=E(e,r))||n.enumerable});return i};var I=i=>z(a({},"__esModule",{value:!0}),i);var x={};v(x,{OnePcBridge:()=>h,Router:()=>o,createEnvelope:()=>u,parseEnvelope:()=>g,serializeEnvelope:()=>s});module.exports=I(x);var $=0;function f(){let i=Date.now().toString(36),e=(++$).toString(36);return`mb_${i}_${e}`}function u(i,e,t,n){return{protocol:"message-bridge-v1",id:f(),from:i,to:e,type:t,payload:n!=null?n:null,timestamp:Date.now()}}function g(i){if(!i)return null;if(i.protocol==="message-bridge-v1")return i;let e=i;if(e.message&&e.message.subtype==="webToPc"){let n=e.message.data,r;if(typeof n=="string")try{r=JSON.parse(n)}catch(T){return null}else if(typeof n=="object")r=n;else return null;let t=r,{type:d}=t,y=b(t,["type"]);return d?{protocol:"message-bridge-v1",id:e.id||f(),from:W(e.from),to:C(e.to),type:String(d),payload:y,timestamp:Date.now()}:null}return e.message&&e.message.subtype==="openclawToPc"?{protocol:"message-bridge-v1",id:e.id||f(),from:W(e.from),to:"onepcweb",type:"openclawToPc",payload:e.message.data,timestamp:Date.now()}:null}function W(i){return i?i.includes("openclaw")||i.includes("claw")?"openclaw":i.includes("intelligent")?"intelligent":i.includes("vantage")||i.includes("onepc")?"onepcweb":"intelligent":"intelligent"}function C(i){return i?i.includes("pcWeb")||i.includes("pcMessage")?"onepcweb":i.includes("intelligent")?"intelligent":i.includes("openclaw")||i.includes("claw")?"openclaw":"intelligent":"intelligent"}function s(i){return m({},i)}var o=class{constructor(e={}){this.routes=[],this.parentWindow=e.parentWindow!=null?e.parentWindow:null,this.getChildWindow=e.getChildWindow!=null?e.getChildWindow:null,this.debug=e.debug!=null?e.debug:!1}addRoute(e,t){this.removeRoute(e,t),this.routes.push({from:e,to:t}),this.log("route registered:",`${e} \u2192 ${t}`)}removeRoute(e,t){this.routes=this.routes.filter(n=>!(n.from===e&&n.to===t))}clearRoutes(){this.routes=[]}getForwardTarget(e){return this.routes.find(n=>n.from===e.from&&n.to===e.to)?e.to==="onepcweb"&&this.parentWindow?this.parentWindow:e.from==="onepcweb"&&this.getChildWindow?this.getChildWindow():e.to!=="intelligent"&&this.parentWindow?this.parentWindow:null:null}forward(e){let t=this.getForwardTarget(e);if(!t)return!1;let n=s(e);return t.postMessage(n,"*"),this.log("forwarded:",`${e.from} \u2192 ${e.to} via postMessage`,e.type),!0}hasRoute(e,t){return this.routes.some(n=>n.from===e&&n.to===t)}process(e){return this.hasRoute(e.from,e.to)?this.forward(e):!1}log(...e){this.debug&&console.log("[OnePcBridge-Router]",...e)}};var h=class{constructor(e){this.config=e,this.handlers=new Map,this.router=new o({parentWindow:e.parentWindow,getChildWindow:e.getChildWindow,debug:e.debug!=null?e.debug:!1}),this.messageHandler=null,this.initialized=!1}init(){this.initialized||(this.messageHandler=this.handleMessage.bind(this),window.addEventListener("message",this.messageHandler),this.initialized=!0,this.log("initialized",this.config.nodeId))}destroy(){this.messageHandler&&(window.removeEventListener("message",this.messageHandler),this.messageHandler=null),this.handlers.clear(),this.initialized=!1,this.log("destroyed")}send(e,t,n){let r=u(this.config.nodeId,e,t,n);this.log("send:",`${this.config.nodeId} \u2192 ${e}`,t,n);let d=this.getTargetWindow(e);d?d.postMessage(s(r),"*"):this.warn("no target window for:",e)}on(e,t){return this.handlers.has(e)||this.handlers.set(e,new Set),this.handlers.get(e).add(t),()=>{let n=this.handlers.get(e);n&&(n.delete(t),n.size===0&&this.handlers.delete(e))}}addRoute(e,t){var n;(n=this.router)==null||n.addRoute(e,t)}removeRoute(e,t){var n;(n=this.router)==null||n.removeRoute(e,t)}handleMessage(e){var n;if(e.origin&&!this.config.allowedOrigins.includes(e.origin))return;let t=g(e.data);if(t&&!(t.from===this.config.nodeId&&t.to===this.config.nodeId)){if(t.to!==this.config.nodeId){if((n=this.router)!=null&&n.process(t)){this.dispatch(t);return}return}this.dispatch(t)}}dispatch(e){let t=this.handlers.get(e.type);if(t)for(let n of t)try{n(e.payload,e)}catch(r){this.warn("handler error:",e.type,r)}}getTargetWindow(e){return this.config.parentWindow&&e!==this.config.nodeId?this.config.parentWindow:this.config.getChildWindow?this.config.getChildWindow():null}log(...e){this.config.debug&&console.log(`[OnePcBridge:${this.config.nodeId}]`,...e)}warn(...e){console.warn(`[OnePcBridge:${this.config.nodeId}]`,...e)}};
2
2
  //# sourceMappingURL=index.cjs.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.js", "../src/envelope.js", "../src/router.js", "../src/MessageBridge.js"],
4
- "sourcesContent": ["export { OnePcBridge } from './MessageBridge'\nexport { createEnvelope, parseEnvelope, serializeEnvelope } from './envelope'\nexport { Router } from './router'\n", "let _counter = 0\n\n/**\n * Generate a lightweight unique ID without external dependencies.\n * Uses timestamp + counter for uniqueness within a session.\n */\nfunction generateId() {\n const ts = Date.now().toString(36)\n const seq = (++_counter).toString(36)\n return `mb_${ts}_${seq}`\n}\n\n/**\n * Create a new message envelope (new protocol format).\n */\nexport function createEnvelope(from, to, type, payload) {\n return {\n protocol: 'message-bridge-v1',\n id: generateId(),\n from,\n to,\n type,\n payload: payload ?? null,\n timestamp: Date.now(),\n }\n}\n\n/**\n * Parse a raw postMessage event into an Envelope.\n * Supports both the new protocol format and the legacy format\n * for backward compatibility during migration.\n *\n * New format:\n * { protocol: 'message-bridge-v1', from, to, type, payload, ... }\n *\n * Legacy format:\n * { to, from, id, message: { subtype: 'webToPc', data: JSON.stringify({type, ...}) } }\n */\nexport function parseEnvelope(raw) {\n if (!raw) return null\n\n // --- New protocol ---\n if (raw.protocol === 'message-bridge-v1') {\n return raw\n }\n\n // --- Legacy format detection ---\n const legacy = raw\n if (legacy.message && legacy.message.subtype === 'webToPc') {\n const data = legacy.message.data\n let parsed\n\n if (typeof data === 'string') {\n try {\n parsed = JSON.parse(data)\n } catch {\n return null\n }\n } else if (typeof data === 'object') {\n parsed = data\n } else {\n return null\n }\n\n const { type, ...restPayload } = parsed\n if (!type) return null\n\n return {\n protocol: 'message-bridge-v1',\n id: legacy.id || generateId(),\n from: detectFromNode(legacy.from),\n to: detectToNode(legacy.to),\n type: String(type),\n payload: restPayload,\n timestamp: Date.now(),\n }\n }\n\n // Legacy: openclawToPc subtype\n if (legacy.message && legacy.message.subtype === 'openclawToPc') {\n return {\n protocol: 'message-bridge-v1',\n id: legacy.id || generateId(),\n from: detectFromNode(legacy.from),\n to: 'onepcweb',\n type: 'openclawToPc',\n payload: legacy.message.data,\n timestamp: Date.now(),\n }\n }\n\n return null\n}\n\n/**\n * Detect the source NodeId from legacy message's `from` field.\n */\nfunction detectFromNode(from) {\n if (!from) return 'intelligent'\n if (from.includes('openclaw') || from.includes('claw')) return 'openclaw'\n if (from.includes('intelligent')) return 'intelligent'\n if (from.includes('vantage') || from.includes('onepc')) return 'onepcweb'\n return 'intelligent'\n}\n\n/**\n * Detect the target NodeId from legacy message's `to` field.\n */\nfunction detectToNode(to) {\n if (!to) return 'intelligent'\n if (to.includes('pcWeb') || to.includes('pcMessage')) return 'onepcweb'\n if (to.includes('intelligent')) return 'intelligent'\n if (to.includes('openclaw') || to.includes('claw')) return 'openclaw'\n return 'intelligent'\n}\n\n/**\n * Serialize an Envelope for postMessage transmission.\n */\nexport function serializeEnvelope(envelope) {\n return { ...envelope }\n}\n", "import { createEnvelope, serializeEnvelope } from './envelope'\n\n/**\n * Router manages automatic message forwarding for middle-layer nodes.\n */\nexport class Router {\n constructor(opts = {}) {\n this.routes = []\n this.parentWindow = opts.parentWindow ?? null\n this.getChildWindow = opts.getChildWindow ?? null\n this.debug = opts.debug ?? false\n }\n\n addRoute(from, to) {\n this.removeRoute(from, to)\n this.routes.push({ from, to })\n this.log('route registered:', `${from} \u2192 ${to}`)\n }\n\n removeRoute(from, to) {\n this.routes = this.routes.filter(\n r => !(r.from === from && r.to === to)\n )\n }\n\n clearRoutes() {\n this.routes = []\n }\n\n getForwardTarget(envelope) {\n const route = this.routes.find(\n r => r.from === envelope.from && r.to === envelope.to\n )\n if (!route) return null\n\n if (envelope.to === 'onepcweb' && this.parentWindow) {\n return this.parentWindow\n }\n if (envelope.from === 'onepcweb' && this.getChildWindow) {\n return this.getChildWindow()\n }\n if (envelope.to !== 'intelligent' && this.parentWindow) {\n return this.parentWindow\n }\n\n return null\n }\n\n forward(envelope) {\n const target = this.getForwardTarget(envelope)\n if (!target) return false\n\n const body = serializeEnvelope(envelope)\n target.postMessage(body, '*')\n this.log('forwarded:', `${envelope.from} \u2192 ${envelope.to} via postMessage`, envelope.type)\n return true\n }\n\n hasRoute(from, to) {\n return this.routes.some(r => r.from === from && r.to === to)\n }\n\n process(envelope) {\n if (this.hasRoute(envelope.from, envelope.to)) {\n return this.forward(envelope)\n }\n return false\n }\n\n log(...args) {\n if (this.debug) {\n console.log('[OnePcBridge-Router]', ...args)\n }\n }\n}\n", "import { createEnvelope, parseEnvelope, serializeEnvelope } from './envelope'\nimport { Router } from './router'\n\n/**\n * OnePcBridge \u2014 unified cross-iframe communication SDK.\n *\n * Usage:\n * // Leaf node (C - openclaw)\n * const bridge = new OnePcBridge({\n * nodeId: 'openclaw',\n * allowedOrigins: ['https://...'],\n * parentWindow: window.parent,\n * })\n * bridge.init()\n * bridge.send('onepcweb', 'menu', { data: '...' })\n *\n * // Middle node (B - intelligent-web)\n * const bridge = new OnePcBridge({\n * nodeId: 'intelligent',\n * allowedOrigins: ['https://...', CHILD_ORIGIN],\n * parentWindow: window.parent,\n * getChildWindow: () => iframeRef.value?.contentWindow,\n * })\n * bridge.addRoute('openclaw', 'onepcweb')\n * bridge.init()\n */\nexport class OnePcBridge {\n constructor(config) {\n this.config = config\n this.handlers = new Map()\n this.router = new Router({\n parentWindow: config.parentWindow,\n getChildWindow: config.getChildWindow,\n debug: config.debug ?? false,\n })\n this.messageHandler = null\n this.initialized = false\n }\n\n init() {\n if (this.initialized) return\n\n this.messageHandler = this.handleMessage.bind(this)\n window.addEventListener('message', this.messageHandler)\n this.initialized = true\n this.log('initialized', this.config.nodeId)\n }\n\n destroy() {\n if (this.messageHandler) {\n window.removeEventListener('message', this.messageHandler)\n this.messageHandler = null\n }\n this.handlers.clear()\n this.initialized = false\n this.log('destroyed')\n }\n\n send(target, type, payload) {\n const envelope = createEnvelope(this.config.nodeId, target, type, payload)\n this.log('send:', `${this.config.nodeId} \u2192 ${target}`, type, payload)\n\n const targetWindow = this.getTargetWindow(target)\n if (targetWindow) {\n targetWindow.postMessage(serializeEnvelope(envelope), '*')\n } else {\n this.warn('no target window for:', target)\n }\n }\n\n on(type, handler) {\n if (!this.handlers.has(type)) {\n this.handlers.set(type, new Set())\n }\n this.handlers.get(type).add(handler)\n\n return () => {\n const set = this.handlers.get(type)\n if (set) {\n set.delete(handler)\n if (set.size === 0) {\n this.handlers.delete(type)\n }\n }\n }\n }\n\n addRoute(from, to) {\n this.router?.addRoute(from, to)\n }\n\n removeRoute(from, to) {\n this.router?.removeRoute(from, to)\n }\n\n // \u2500\u2500\u2500 Private \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n handleMessage(event) {\n if (event.origin && !this.config.allowedOrigins.includes(event.origin)) {\n return\n }\n\n const envelope = parseEnvelope(event.data)\n if (!envelope) return\n\n if (envelope.from === this.config.nodeId && envelope.to === this.config.nodeId) {\n return\n }\n\n if (envelope.to !== this.config.nodeId) {\n if (this.router?.process(envelope)) {\n this.dispatch(envelope)\n return\n }\n return\n }\n\n this.dispatch(envelope)\n }\n\n dispatch(envelope) {\n const typeHandlers = this.handlers.get(envelope.type)\n if (typeHandlers) {\n for (const handler of typeHandlers) {\n try {\n handler(envelope.payload, envelope)\n } catch (err) {\n this.warn('handler error:', envelope.type, err)\n }\n }\n }\n }\n\n getTargetWindow(target) {\n if (this.config.parentWindow && target !== this.config.nodeId) {\n return this.config.parentWindow\n }\n if (this.config.getChildWindow) {\n return this.config.getChildWindow()\n }\n return null\n }\n\n log(...args) {\n if (this.config.debug) {\n console.log(`[OnePcBridge:${this.config.nodeId}]`, ...args)\n }\n }\n\n warn(...args) {\n console.warn(`[OnePcBridge:${this.config.nodeId}]`, ...args)\n }\n}\n"],
5
-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V,EAAS,IAAI,EACpD,GAAIU,EACF,QAAWN,KAAWM,EACpB,GAAI,CACFN,EAAQJ,EAAS,QAASA,CAAQ,CACpC,OAASW,EAAK,CACZ,KAAK,KAAK,iBAAkBX,EAAS,KAAMW,CAAG,CAChD,CAGN,CAEA,gBAAgBd,EAAQ,CACtB,OAAI,KAAK,OAAO,cAAgBA,IAAW,KAAK,OAAO,OAC9C,KAAK,OAAO,aAEjB,KAAK,OAAO,eACP,KAAK,OAAO,eAAe,EAE7B,IACT,CAEA,OAAOe,EAAM,CACP,KAAK,OAAO,OACd,QAAQ,IAAI,gBAAgB,KAAK,OAAO,MAAM,IAAK,GAAGA,CAAI,CAE9D,CAEA,QAAQA,EAAM,CACZ,QAAQ,KAAK,gBAAgB,KAAK,OAAO,MAAM,IAAK,GAAGA,CAAI,CAC7D,CACF",
6
- "names": ["index_exports", "__export", "OnePcBridge", "Router", "createEnvelope", "parseEnvelope", "serializeEnvelope", "__toCommonJS", "_counter", "generateId", "ts", "seq", "createEnvelope", "from", "to", "type", "payload", "parseEnvelope", "raw", "legacy", "data", "parsed", "restPayload", "detectFromNode", "detectToNode", "serializeEnvelope", "envelope", "Router", "opts", "from", "to", "r", "envelope", "target", "body", "serializeEnvelope", "args", "OnePcBridge", "config", "Router", "target", "type", "payload", "envelope", "createEnvelope", "targetWindow", "serializeEnvelope", "handler", "set", "from", "to", "event", "parseEnvelope", "typeHandlers", "err", "args"]
4
+ "sourcesContent": ["export { OnePcBridge } from './MessageBridge'\nexport { createEnvelope, parseEnvelope, serializeEnvelope } from './envelope'\nexport { Router } from './router'\n", "let _counter = 0\n\n/**\n * Generate a lightweight unique ID without external dependencies.\n * Uses timestamp + counter for uniqueness within a session.\n */\nfunction generateId() {\n const ts = Date.now().toString(36)\n const seq = (++_counter).toString(36)\n return `mb_${ts}_${seq}`\n}\n\n/**\n * Create a new message envelope (new protocol format).\n */\nexport function createEnvelope(from, to, type, payload) {\n return {\n protocol: 'message-bridge-v1',\n id: generateId(),\n from,\n to,\n type,\n payload: payload != null ? payload : null,\n timestamp: Date.now(),\n }\n}\n\n/**\n * Parse a raw postMessage event into an Envelope.\n * Supports both the new protocol format and the legacy format\n * for backward compatibility during migration.\n *\n * New format:\n * { protocol: 'message-bridge-v1', from, to, type, payload, ... }\n *\n * Legacy format:\n * { to, from, id, message: { subtype: 'webToPc', data: JSON.stringify({type, ...}) } }\n */\nexport function parseEnvelope(raw) {\n if (!raw) return null\n\n // --- New protocol ---\n if (raw.protocol === 'message-bridge-v1') {\n return raw\n }\n\n // --- Legacy format detection ---\n const legacy = raw\n if (legacy.message && legacy.message.subtype === 'webToPc') {\n const data = legacy.message.data\n let parsed\n\n if (typeof data === 'string') {\n try {\n parsed = JSON.parse(data)\n } catch {\n return null\n }\n } else if (typeof data === 'object') {\n parsed = data\n } else {\n return null\n }\n\n const { type, ...restPayload } = parsed\n if (!type) return null\n\n return {\n protocol: 'message-bridge-v1',\n id: legacy.id || generateId(),\n from: detectFromNode(legacy.from),\n to: detectToNode(legacy.to),\n type: String(type),\n payload: restPayload,\n timestamp: Date.now(),\n }\n }\n\n // Legacy: openclawToPc subtype\n if (legacy.message && legacy.message.subtype === 'openclawToPc') {\n return {\n protocol: 'message-bridge-v1',\n id: legacy.id || generateId(),\n from: detectFromNode(legacy.from),\n to: 'onepcweb',\n type: 'openclawToPc',\n payload: legacy.message.data,\n timestamp: Date.now(),\n }\n }\n\n return null\n}\n\n/**\n * Detect the source NodeId from legacy message's `from` field.\n */\nfunction detectFromNode(from) {\n if (!from) return 'intelligent'\n if (from.includes('openclaw') || from.includes('claw')) return 'openclaw'\n if (from.includes('intelligent')) return 'intelligent'\n if (from.includes('vantage') || from.includes('onepc')) return 'onepcweb'\n return 'intelligent'\n}\n\n/**\n * Detect the target NodeId from legacy message's `to` field.\n */\nfunction detectToNode(to) {\n if (!to) return 'intelligent'\n if (to.includes('pcWeb') || to.includes('pcMessage')) return 'onepcweb'\n if (to.includes('intelligent')) return 'intelligent'\n if (to.includes('openclaw') || to.includes('claw')) return 'openclaw'\n return 'intelligent'\n}\n\n/**\n * Serialize an Envelope for postMessage transmission.\n */\nexport function serializeEnvelope(envelope) {\n return { ...envelope }\n}\n", "import { createEnvelope, serializeEnvelope } from './envelope'\n\n/**\n * Router manages automatic message forwarding for middle-layer nodes.\n */\nexport class Router {\n constructor(opts = {}) {\n this.routes = []\n this.parentWindow = opts.parentWindow != null ? opts.parentWindow : null\n this.getChildWindow = opts.getChildWindow != null ? opts.getChildWindow : null\n this.debug = opts.debug != null ? opts.debug : false\n }\n\n addRoute(from, to) {\n this.removeRoute(from, to)\n this.routes.push({ from, to })\n this.log('route registered:', `${from} \u2192 ${to}`)\n }\n\n removeRoute(from, to) {\n this.routes = this.routes.filter(\n r => !(r.from === from && r.to === to)\n )\n }\n\n clearRoutes() {\n this.routes = []\n }\n\n getForwardTarget(envelope) {\n const route = this.routes.find(\n r => r.from === envelope.from && r.to === envelope.to\n )\n if (!route) return null\n\n if (envelope.to === 'onepcweb' && this.parentWindow) {\n return this.parentWindow\n }\n if (envelope.from === 'onepcweb' && this.getChildWindow) {\n return this.getChildWindow()\n }\n if (envelope.to !== 'intelligent' && this.parentWindow) {\n return this.parentWindow\n }\n\n return null\n }\n\n forward(envelope) {\n const target = this.getForwardTarget(envelope)\n if (!target) return false\n\n const body = serializeEnvelope(envelope)\n target.postMessage(body, '*')\n this.log('forwarded:', `${envelope.from} \u2192 ${envelope.to} via postMessage`, envelope.type)\n return true\n }\n\n hasRoute(from, to) {\n return this.routes.some(r => r.from === from && r.to === to)\n }\n\n process(envelope) {\n if (this.hasRoute(envelope.from, envelope.to)) {\n return this.forward(envelope)\n }\n return false\n }\n\n log(...args) {\n if (this.debug) {\n console.log('[OnePcBridge-Router]', ...args)\n }\n }\n}\n", "import { createEnvelope, parseEnvelope, serializeEnvelope } from './envelope'\nimport { Router } from './router'\n\n/**\n * OnePcBridge \u2014 unified cross-iframe communication SDK.\n *\n * Usage:\n * // Leaf node (C - openclaw)\n * const bridge = new OnePcBridge({\n * nodeId: 'openclaw',\n * allowedOrigins: ['https://...'],\n * parentWindow: window.parent,\n * })\n * bridge.init()\n * bridge.send('onepcweb', 'menu', { data: '...' })\n *\n * // Middle node (B - intelligent-web)\n * const bridge = new OnePcBridge({\n * nodeId: 'intelligent',\n * allowedOrigins: ['https://...', CHILD_ORIGIN],\n * parentWindow: window.parent,\n * getChildWindow: () => iframeRef.value?.contentWindow,\n * })\n * bridge.addRoute('openclaw', 'onepcweb')\n * bridge.init()\n */\nexport class OnePcBridge {\n constructor(config) {\n this.config = config\n this.handlers = new Map()\n this.router = new Router({\n parentWindow: config.parentWindow,\n getChildWindow: config.getChildWindow,\n debug: config.debug != null ? config.debug : false,\n })\n this.messageHandler = null\n this.initialized = false\n }\n\n init() {\n if (this.initialized) return\n\n this.messageHandler = this.handleMessage.bind(this)\n window.addEventListener('message', this.messageHandler)\n this.initialized = true\n this.log('initialized', this.config.nodeId)\n }\n\n destroy() {\n if (this.messageHandler) {\n window.removeEventListener('message', this.messageHandler)\n this.messageHandler = null\n }\n this.handlers.clear()\n this.initialized = false\n this.log('destroyed')\n }\n\n send(target, type, payload) {\n const envelope = createEnvelope(this.config.nodeId, target, type, payload)\n this.log('send:', `${this.config.nodeId} \u2192 ${target}`, type, payload)\n\n const targetWindow = this.getTargetWindow(target)\n if (targetWindow) {\n targetWindow.postMessage(serializeEnvelope(envelope), '*')\n } else {\n this.warn('no target window for:', target)\n }\n }\n\n on(type, handler) {\n if (!this.handlers.has(type)) {\n this.handlers.set(type, new Set())\n }\n this.handlers.get(type).add(handler)\n\n return () => {\n const set = this.handlers.get(type)\n if (set) {\n set.delete(handler)\n if (set.size === 0) {\n this.handlers.delete(type)\n }\n }\n }\n }\n\n addRoute(from, to) {\n this.router?.addRoute(from, to)\n }\n\n removeRoute(from, to) {\n this.router?.removeRoute(from, to)\n }\n\n // \u2500\u2500\u2500 Private \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n handleMessage(event) {\n if (event.origin && !this.config.allowedOrigins.includes(event.origin)) {\n return\n }\n\n const envelope = parseEnvelope(event.data)\n if (!envelope) return\n\n if (envelope.from === this.config.nodeId && envelope.to === this.config.nodeId) {\n return\n }\n\n if (envelope.to !== this.config.nodeId) {\n if (this.router?.process(envelope)) {\n this.dispatch(envelope)\n return\n }\n return\n }\n\n this.dispatch(envelope)\n }\n\n dispatch(envelope) {\n const typeHandlers = this.handlers.get(envelope.type)\n if (typeHandlers) {\n for (const handler of typeHandlers) {\n try {\n handler(envelope.payload, envelope)\n } catch (err) {\n this.warn('handler error:', envelope.type, err)\n }\n }\n }\n }\n\n getTargetWindow(target) {\n if (this.config.parentWindow && target !== this.config.nodeId) {\n return this.config.parentWindow\n }\n if (this.config.getChildWindow) {\n return this.config.getChildWindow()\n }\n return null\n }\n\n log(...args) {\n if (this.config.debug) {\n console.log(`[OnePcBridge:${this.config.nodeId}]`, ...args)\n }\n }\n\n warn(...args) {\n console.warn(`[OnePcBridge:${this.config.nodeId}]`, ...args)\n }\n}\n"],
5
+ "mappings": "i1BAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,iBAAAE,EAAA,WAAAC,EAAA,mBAAAC,EAAA,kBAAAC,EAAA,sBAAAC,IAAA,eAAAC,EAAAP,GCAA,IAAIQ,EAAW,EAMf,SAASC,GAAa,CACpB,IAAMC,EAAK,KAAK,IAAI,EAAE,SAAS,EAAE,EAC3BC,GAAO,EAAEH,GAAU,SAAS,EAAE,EACpC,MAAO,MAAME,CAAE,IAAIC,CAAG,EACxB,CAKO,SAASC,EAAeC,EAAMC,EAAIC,EAAMC,EAAS,CACtD,MAAO,CACL,SAAU,oBACV,GAA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AChD,CAGN,CAEA,gBAAgBf,EAAQ,CACtB,OAAI,KAAK,OAAO,cAAgBA,IAAW,KAAK,OAAO,OAC9C,KAAK,OAAO,aAEjB,KAAK,OAAO,eACP,KAAK,OAAO,eAAe,EAE7B,IACT,CAEA,OAAOgB,EAAM,CACP,KAAK,OAAO,OACd,QAAQ,IAAI,gBAAgB,KAAK,OAAO,MAAM,IAAK,GAAGA,CAAI,CAE9D,CAEA,QAAQA,EAAM,CACZ,QAAQ,KAAK,gBAAgB,KAAK,OAAO,MAAM,IAAK,GAAGA,CAAI,CAC7D,CACF",
6
+ "names": ["index_exports", "__export", "OnePcBridge", "Router", "createEnvelope", "parseEnvelope", "serializeEnvelope", "__toCommonJS", "_counter", "generateId", "ts", "seq", "createEnvelope", "from", "to", "type", "payload", "parseEnvelope", "raw", "legacy", "data", "parsed", "e", "_a", "restPayload", "__objRest", "detectFromNode", "detectToNode", "serializeEnvelope", "envelope", "__spreadValues", "Router", "opts", "from", "to", "r", "envelope", "target", "body", "serializeEnvelope", "args", "OnePcBridge", "config", "Router", "target", "type", "payload", "envelope", "createEnvelope", "targetWindow", "serializeEnvelope", "handler", "set", "from", "to", "_a", "event", "parseEnvelope", "typeHandlers", "err", "args"]
7
7
  }
package/dist/index.esm.js CHANGED
@@ -1,2 +1,2 @@
1
- var g=0;function a(){let i=Date.now().toString(36),e=(++g).toString(36);return`mb_${i}_${e}`}function l(i,e,t,n){return{protocol:"message-bridge-v1",id:a(),from:i,to:e,type:t,payload:n??null,timestamp:Date.now()}}function u(i){if(!i)return null;if(i.protocol==="message-bridge-v1")return i;let e=i;if(e.message&&e.message.subtype==="webToPc"){let t=e.message.data,n;if(typeof t=="string")try{n=JSON.parse(t)}catch{return null}else if(typeof t=="object")n=t;else return null;let{type:r,...d}=n;return r?{protocol:"message-bridge-v1",id:e.id||a(),from:h(e.from),to:f(e.to),type:String(r),payload:d,timestamp:Date.now()}:null}return e.message&&e.message.subtype==="openclawToPc"?{protocol:"message-bridge-v1",id:e.id||a(),from:h(e.from),to:"onepcweb",type:"openclawToPc",payload:e.message.data,timestamp:Date.now()}:null}function h(i){return i?i.includes("openclaw")||i.includes("claw")?"openclaw":i.includes("intelligent")?"intelligent":i.includes("vantage")||i.includes("onepc")?"onepcweb":"intelligent":"intelligent"}function f(i){return i?i.includes("pcWeb")||i.includes("pcMessage")?"onepcweb":i.includes("intelligent")?"intelligent":i.includes("openclaw")||i.includes("claw")?"openclaw":"intelligent":"intelligent"}function s(i){return{...i}}var o=class{constructor(e={}){this.routes=[],this.parentWindow=e.parentWindow??null,this.getChildWindow=e.getChildWindow??null,this.debug=e.debug??!1}addRoute(e,t){this.removeRoute(e,t),this.routes.push({from:e,to:t}),this.log("route registered:",`${e} \u2192 ${t}`)}removeRoute(e,t){this.routes=this.routes.filter(n=>!(n.from===e&&n.to===t))}clearRoutes(){this.routes=[]}getForwardTarget(e){return this.routes.find(n=>n.from===e.from&&n.to===e.to)?e.to==="onepcweb"&&this.parentWindow?this.parentWindow:e.from==="onepcweb"&&this.getChildWindow?this.getChildWindow():e.to!=="intelligent"&&this.parentWindow?this.parentWindow:null:null}forward(e){let t=this.getForwardTarget(e);if(!t)return!1;let n=s(e);return t.postMessage(n,"*"),this.log("forwarded:",`${e.from} \u2192 ${e.to} via postMessage`,e.type),!0}hasRoute(e,t){return this.routes.some(n=>n.from===e&&n.to===t)}process(e){return this.hasRoute(e.from,e.to)?this.forward(e):!1}log(...e){this.debug&&console.log("[OnePcBridge-Router]",...e)}};var c=class{constructor(e){this.config=e,this.handlers=new Map,this.router=new o({parentWindow:e.parentWindow,getChildWindow:e.getChildWindow,debug:e.debug??!1}),this.messageHandler=null,this.initialized=!1}init(){this.initialized||(this.messageHandler=this.handleMessage.bind(this),window.addEventListener("message",this.messageHandler),this.initialized=!0,this.log("initialized",this.config.nodeId))}destroy(){this.messageHandler&&(window.removeEventListener("message",this.messageHandler),this.messageHandler=null),this.handlers.clear(),this.initialized=!1,this.log("destroyed")}send(e,t,n){let r=l(this.config.nodeId,e,t,n);this.log("send:",`${this.config.nodeId} \u2192 ${e}`,t,n);let d=this.getTargetWindow(e);d?d.postMessage(s(r),"*"):this.warn("no target window for:",e)}on(e,t){return this.handlers.has(e)||this.handlers.set(e,new Set),this.handlers.get(e).add(t),()=>{let n=this.handlers.get(e);n&&(n.delete(t),n.size===0&&this.handlers.delete(e))}}addRoute(e,t){this.router?.addRoute(e,t)}removeRoute(e,t){this.router?.removeRoute(e,t)}handleMessage(e){if(e.origin&&!this.config.allowedOrigins.includes(e.origin))return;let t=u(e.data);if(t&&!(t.from===this.config.nodeId&&t.to===this.config.nodeId)){if(t.to!==this.config.nodeId){if(this.router?.process(t)){this.dispatch(t);return}return}this.dispatch(t)}}dispatch(e){let t=this.handlers.get(e.type);if(t)for(let n of t)try{n(e.payload,e)}catch(r){this.warn("handler error:",e.type,r)}}getTargetWindow(e){return this.config.parentWindow&&e!==this.config.nodeId?this.config.parentWindow:this.config.getChildWindow?this.config.getChildWindow():null}log(...e){this.config.debug&&console.log(`[OnePcBridge:${this.config.nodeId}]`,...e)}warn(...e){console.warn(`[OnePcBridge:${this.config.nodeId}]`,...e)}};export{c as OnePcBridge,o as Router,l as createEnvelope,u as parseEnvelope,s as serializeEnvelope};
1
+ var y=Object.defineProperty;var l=Object.getOwnPropertySymbols;var f=Object.prototype.hasOwnProperty,p=Object.prototype.propertyIsEnumerable;var c=(n,e,t)=>e in n?y(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,w=(n,e)=>{for(var t in e||(e={}))f.call(e,t)&&c(n,t,e[t]);if(l)for(var t of l(e))p.call(e,t)&&c(n,t,e[t]);return n};var m=(n,e)=>{var t={};for(var i in n)f.call(n,i)&&e.indexOf(i)<0&&(t[i]=n[i]);if(n!=null&&l)for(var i of l(n))e.indexOf(i)<0&&p.call(n,i)&&(t[i]=n[i]);return t};var E=0;function a(){let n=Date.now().toString(36),e=(++E).toString(36);return`mb_${n}_${e}`}function u(n,e,t,i){return{protocol:"message-bridge-v1",id:a(),from:n,to:e,type:t,payload:i!=null?i:null,timestamp:Date.now()}}function g(n){if(!n)return null;if(n.protocol==="message-bridge-v1")return n;let e=n;if(e.message&&e.message.subtype==="webToPc"){let i=e.message.data,r;if(typeof i=="string")try{r=JSON.parse(i)}catch(v){return null}else if(typeof i=="object")r=i;else return null;let t=r,{type:s}=t,W=m(t,["type"]);return s?{protocol:"message-bridge-v1",id:e.id||a(),from:b(e.from),to:R(e.to),type:String(s),payload:W,timestamp:Date.now()}:null}return e.message&&e.message.subtype==="openclawToPc"?{protocol:"message-bridge-v1",id:e.id||a(),from:b(e.from),to:"onepcweb",type:"openclawToPc",payload:e.message.data,timestamp:Date.now()}:null}function b(n){return n?n.includes("openclaw")||n.includes("claw")?"openclaw":n.includes("intelligent")?"intelligent":n.includes("vantage")||n.includes("onepc")?"onepcweb":"intelligent":"intelligent"}function R(n){return n?n.includes("pcWeb")||n.includes("pcMessage")?"onepcweb":n.includes("intelligent")?"intelligent":n.includes("openclaw")||n.includes("claw")?"openclaw":"intelligent":"intelligent"}function o(n){return w({},n)}var d=class{constructor(e={}){this.routes=[],this.parentWindow=e.parentWindow!=null?e.parentWindow:null,this.getChildWindow=e.getChildWindow!=null?e.getChildWindow:null,this.debug=e.debug!=null?e.debug:!1}addRoute(e,t){this.removeRoute(e,t),this.routes.push({from:e,to:t}),this.log("route registered:",`${e} \u2192 ${t}`)}removeRoute(e,t){this.routes=this.routes.filter(i=>!(i.from===e&&i.to===t))}clearRoutes(){this.routes=[]}getForwardTarget(e){return this.routes.find(i=>i.from===e.from&&i.to===e.to)?e.to==="onepcweb"&&this.parentWindow?this.parentWindow:e.from==="onepcweb"&&this.getChildWindow?this.getChildWindow():e.to!=="intelligent"&&this.parentWindow?this.parentWindow:null:null}forward(e){let t=this.getForwardTarget(e);if(!t)return!1;let i=o(e);return t.postMessage(i,"*"),this.log("forwarded:",`${e.from} \u2192 ${e.to} via postMessage`,e.type),!0}hasRoute(e,t){return this.routes.some(i=>i.from===e&&i.to===t)}process(e){return this.hasRoute(e.from,e.to)?this.forward(e):!1}log(...e){this.debug&&console.log("[OnePcBridge-Router]",...e)}};var h=class{constructor(e){this.config=e,this.handlers=new Map,this.router=new d({parentWindow:e.parentWindow,getChildWindow:e.getChildWindow,debug:e.debug!=null?e.debug:!1}),this.messageHandler=null,this.initialized=!1}init(){this.initialized||(this.messageHandler=this.handleMessage.bind(this),window.addEventListener("message",this.messageHandler),this.initialized=!0,this.log("initialized",this.config.nodeId))}destroy(){this.messageHandler&&(window.removeEventListener("message",this.messageHandler),this.messageHandler=null),this.handlers.clear(),this.initialized=!1,this.log("destroyed")}send(e,t,i){let r=u(this.config.nodeId,e,t,i);this.log("send:",`${this.config.nodeId} \u2192 ${e}`,t,i);let s=this.getTargetWindow(e);s?s.postMessage(o(r),"*"):this.warn("no target window for:",e)}on(e,t){return this.handlers.has(e)||this.handlers.set(e,new Set),this.handlers.get(e).add(t),()=>{let i=this.handlers.get(e);i&&(i.delete(t),i.size===0&&this.handlers.delete(e))}}addRoute(e,t){var i;(i=this.router)==null||i.addRoute(e,t)}removeRoute(e,t){var i;(i=this.router)==null||i.removeRoute(e,t)}handleMessage(e){var i;if(e.origin&&!this.config.allowedOrigins.includes(e.origin))return;let t=g(e.data);if(t&&!(t.from===this.config.nodeId&&t.to===this.config.nodeId)){if(t.to!==this.config.nodeId){if((i=this.router)!=null&&i.process(t)){this.dispatch(t);return}return}this.dispatch(t)}}dispatch(e){let t=this.handlers.get(e.type);if(t)for(let i of t)try{i(e.payload,e)}catch(r){this.warn("handler error:",e.type,r)}}getTargetWindow(e){return this.config.parentWindow&&e!==this.config.nodeId?this.config.parentWindow:this.config.getChildWindow?this.config.getChildWindow():null}log(...e){this.config.debug&&console.log(`[OnePcBridge:${this.config.nodeId}]`,...e)}warn(...e){console.warn(`[OnePcBridge:${this.config.nodeId}]`,...e)}};export{h as OnePcBridge,d as Router,u as createEnvelope,g as parseEnvelope,o as serializeEnvelope};
2
2
  //# sourceMappingURL=index.esm.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/envelope.js", "../src/router.js", "../src/MessageBridge.js"],
4
- "sourcesContent": ["let _counter = 0\n\n/**\n * Generate a lightweight unique ID without external dependencies.\n * Uses timestamp + counter for uniqueness within a session.\n */\nfunction generateId() {\n const ts = Date.now().toString(36)\n const seq = (++_counter).toString(36)\n return `mb_${ts}_${seq}`\n}\n\n/**\n * Create a new message envelope (new protocol format).\n */\nexport function createEnvelope(from, to, type, payload) {\n return {\n protocol: 'message-bridge-v1',\n id: generateId(),\n from,\n to,\n type,\n payload: payload ?? null,\n timestamp: Date.now(),\n }\n}\n\n/**\n * Parse a raw postMessage event into an Envelope.\n * Supports both the new protocol format and the legacy format\n * for backward compatibility during migration.\n *\n * New format:\n * { protocol: 'message-bridge-v1', from, to, type, payload, ... }\n *\n * Legacy format:\n * { to, from, id, message: { subtype: 'webToPc', data: JSON.stringify({type, ...}) } }\n */\nexport function parseEnvelope(raw) {\n if (!raw) return null\n\n // --- New protocol ---\n if (raw.protocol === 'message-bridge-v1') {\n return raw\n }\n\n // --- Legacy format detection ---\n const legacy = raw\n if (legacy.message && legacy.message.subtype === 'webToPc') {\n const data = legacy.message.data\n let parsed\n\n if (typeof data === 'string') {\n try {\n parsed = JSON.parse(data)\n } catch {\n return null\n }\n } else if (typeof data === 'object') {\n parsed = data\n } else {\n return null\n }\n\n const { type, ...restPayload } = parsed\n if (!type) return null\n\n return {\n protocol: 'message-bridge-v1',\n id: legacy.id || generateId(),\n from: detectFromNode(legacy.from),\n to: detectToNode(legacy.to),\n type: String(type),\n payload: restPayload,\n timestamp: Date.now(),\n }\n }\n\n // Legacy: openclawToPc subtype\n if (legacy.message && legacy.message.subtype === 'openclawToPc') {\n return {\n protocol: 'message-bridge-v1',\n id: legacy.id || generateId(),\n from: detectFromNode(legacy.from),\n to: 'onepcweb',\n type: 'openclawToPc',\n payload: legacy.message.data,\n timestamp: Date.now(),\n }\n }\n\n return null\n}\n\n/**\n * Detect the source NodeId from legacy message's `from` field.\n */\nfunction detectFromNode(from) {\n if (!from) return 'intelligent'\n if (from.includes('openclaw') || from.includes('claw')) return 'openclaw'\n if (from.includes('intelligent')) return 'intelligent'\n if (from.includes('vantage') || from.includes('onepc')) return 'onepcweb'\n return 'intelligent'\n}\n\n/**\n * Detect the target NodeId from legacy message's `to` field.\n */\nfunction detectToNode(to) {\n if (!to) return 'intelligent'\n if (to.includes('pcWeb') || to.includes('pcMessage')) return 'onepcweb'\n if (to.includes('intelligent')) return 'intelligent'\n if (to.includes('openclaw') || to.includes('claw')) return 'openclaw'\n return 'intelligent'\n}\n\n/**\n * Serialize an Envelope for postMessage transmission.\n */\nexport function serializeEnvelope(envelope) {\n return { ...envelope }\n}\n", "import { createEnvelope, serializeEnvelope } from './envelope'\n\n/**\n * Router manages automatic message forwarding for middle-layer nodes.\n */\nexport class Router {\n constructor(opts = {}) {\n this.routes = []\n this.parentWindow = opts.parentWindow ?? null\n this.getChildWindow = opts.getChildWindow ?? null\n this.debug = opts.debug ?? false\n }\n\n addRoute(from, to) {\n this.removeRoute(from, to)\n this.routes.push({ from, to })\n this.log('route registered:', `${from} \u2192 ${to}`)\n }\n\n removeRoute(from, to) {\n this.routes = this.routes.filter(\n r => !(r.from === from && r.to === to)\n )\n }\n\n clearRoutes() {\n this.routes = []\n }\n\n getForwardTarget(envelope) {\n const route = this.routes.find(\n r => r.from === envelope.from && r.to === envelope.to\n )\n if (!route) return null\n\n if (envelope.to === 'onepcweb' && this.parentWindow) {\n return this.parentWindow\n }\n if (envelope.from === 'onepcweb' && this.getChildWindow) {\n return this.getChildWindow()\n }\n if (envelope.to !== 'intelligent' && this.parentWindow) {\n return this.parentWindow\n }\n\n return null\n }\n\n forward(envelope) {\n const target = this.getForwardTarget(envelope)\n if (!target) return false\n\n const body = serializeEnvelope(envelope)\n target.postMessage(body, '*')\n this.log('forwarded:', `${envelope.from} \u2192 ${envelope.to} via postMessage`, envelope.type)\n return true\n }\n\n hasRoute(from, to) {\n return this.routes.some(r => r.from === from && r.to === to)\n }\n\n process(envelope) {\n if (this.hasRoute(envelope.from, envelope.to)) {\n return this.forward(envelope)\n }\n return false\n }\n\n log(...args) {\n if (this.debug) {\n console.log('[OnePcBridge-Router]', ...args)\n }\n }\n}\n", "import { createEnvelope, parseEnvelope, serializeEnvelope } from './envelope'\nimport { Router } from './router'\n\n/**\n * OnePcBridge \u2014 unified cross-iframe communication SDK.\n *\n * Usage:\n * // Leaf node (C - openclaw)\n * const bridge = new OnePcBridge({\n * nodeId: 'openclaw',\n * allowedOrigins: ['https://...'],\n * parentWindow: window.parent,\n * })\n * bridge.init()\n * bridge.send('onepcweb', 'menu', { data: '...' })\n *\n * // Middle node (B - intelligent-web)\n * const bridge = new OnePcBridge({\n * nodeId: 'intelligent',\n * allowedOrigins: ['https://...', CHILD_ORIGIN],\n * parentWindow: window.parent,\n * getChildWindow: () => iframeRef.value?.contentWindow,\n * })\n * bridge.addRoute('openclaw', 'onepcweb')\n * bridge.init()\n */\nexport class OnePcBridge {\n constructor(config) {\n this.config = config\n this.handlers = new Map()\n this.router = new Router({\n parentWindow: config.parentWindow,\n getChildWindow: config.getChildWindow,\n debug: config.debug ?? false,\n })\n this.messageHandler = null\n this.initialized = false\n }\n\n init() {\n if (this.initialized) return\n\n this.messageHandler = this.handleMessage.bind(this)\n window.addEventListener('message', this.messageHandler)\n this.initialized = true\n this.log('initialized', this.config.nodeId)\n }\n\n destroy() {\n if (this.messageHandler) {\n window.removeEventListener('message', this.messageHandler)\n this.messageHandler = null\n }\n this.handlers.clear()\n this.initialized = false\n this.log('destroyed')\n }\n\n send(target, type, payload) {\n const envelope = createEnvelope(this.config.nodeId, target, type, payload)\n this.log('send:', `${this.config.nodeId} \u2192 ${target}`, type, payload)\n\n const targetWindow = this.getTargetWindow(target)\n if (targetWindow) {\n targetWindow.postMessage(serializeEnvelope(envelope), '*')\n } else {\n this.warn('no target window for:', target)\n }\n }\n\n on(type, handler) {\n if (!this.handlers.has(type)) {\n this.handlers.set(type, new Set())\n }\n this.handlers.get(type).add(handler)\n\n return () => {\n const set = this.handlers.get(type)\n if (set) {\n set.delete(handler)\n if (set.size === 0) {\n this.handlers.delete(type)\n }\n }\n }\n }\n\n addRoute(from, to) {\n this.router?.addRoute(from, to)\n }\n\n removeRoute(from, to) {\n this.router?.removeRoute(from, to)\n }\n\n // \u2500\u2500\u2500 Private \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n handleMessage(event) {\n if (event.origin && !this.config.allowedOrigins.includes(event.origin)) {\n return\n }\n\n const envelope = parseEnvelope(event.data)\n if (!envelope) return\n\n if (envelope.from === this.config.nodeId && envelope.to === this.config.nodeId) {\n return\n }\n\n if (envelope.to !== this.config.nodeId) {\n if (this.router?.process(envelope)) {\n this.dispatch(envelope)\n return\n }\n return\n }\n\n this.dispatch(envelope)\n }\n\n dispatch(envelope) {\n const typeHandlers = this.handlers.get(envelope.type)\n if (typeHandlers) {\n for (const handler of typeHandlers) {\n try {\n handler(envelope.payload, envelope)\n } catch (err) {\n this.warn('handler error:', envelope.type, err)\n }\n }\n }\n }\n\n getTargetWindow(target) {\n if (this.config.parentWindow && target !== this.config.nodeId) {\n return this.config.parentWindow\n }\n if (this.config.getChildWindow) {\n return this.config.getChildWindow()\n }\n return null\n }\n\n log(...args) {\n if (this.config.debug) {\n console.log(`[OnePcBridge:${this.config.nodeId}]`, ...args)\n }\n }\n\n warn(...args) {\n console.warn(`[OnePcBridge:${this.config.nodeId}]`, ...args)\n }\n}\n"],
5
- "mappings": "AAAA,IAAIA,EAAW,EAMf,SAASC,GAAa,CACpB,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AgBd,EAAQ,CACtB,OAAI,KAAK,OAAO,cAAgBA,IAAW,KAAK,OAAO,OAC9C,KAAK,OAAO,aAEjB,KAAK,OAAO,eACP,KAAK,OAAO,eAAe,EAE7B,IACT,CAEA,OAAOe,EAAM,CACP,KAAK,OAAO,OACd,QAAQ,IAAI,gBAAgB,KAAK,OAAO,MAAM,IAAK,GAAGA,CAAI,CAE9D,CAEA,QAAQA,EAAM,CACZ,QAAQ,KAAK,gBAAgB,KAAK,OAAO,MAAM,IAAK,GAAGA,CAAI,CAC7D,CACF",
6
- "names": ["_counter", "generateId", "ts", "seq", "createEnvelope", "from", "to", "type", "payload", "parseEnvelope", "raw", "legacy", "data", "parsed", "restPayload", "detectFromNode", "detectToNode", "serializeEnvelope", "envelope", "Router", "opts", "from", "to", "r", "envelope", "target", "body", "serializeEnvelope", "args", "OnePcBridge", "config", "Router", "target", "type", "payload", "envelope", "createEnvelope", "targetWindow", "serializeEnvelope", "handler", "set", "from", "to", "event", "parseEnvelope", "typeHandlers", "err", "args"]
4
+ "sourcesContent": ["let _counter = 0\n\n/**\n * Generate a lightweight unique ID without external dependencies.\n * Uses timestamp + counter for uniqueness within a session.\n */\nfunction generateId() {\n const ts = Date.now().toString(36)\n const seq = (++_counter).toString(36)\n return `mb_${ts}_${seq}`\n}\n\n/**\n * Create a new message envelope (new protocol format).\n */\nexport function createEnvelope(from, to, type, payload) {\n return {\n protocol: 'message-bridge-v1',\n id: generateId(),\n from,\n to,\n type,\n payload: payload != null ? payload : null,\n timestamp: Date.now(),\n }\n}\n\n/**\n * Parse a raw postMessage event into an Envelope.\n * Supports both the new protocol format and the legacy format\n * for backward compatibility during migration.\n *\n * New format:\n * { protocol: 'message-bridge-v1', from, to, type, payload, ... }\n *\n * Legacy format:\n * { to, from, id, message: { subtype: 'webToPc', data: JSON.stringify({type, ...}) } }\n */\nexport function parseEnvelope(raw) {\n if (!raw) return null\n\n // --- New protocol ---\n if (raw.protocol === 'message-bridge-v1') {\n return raw\n }\n\n // --- Legacy format detection ---\n const legacy = raw\n if (legacy.message && legacy.message.subtype === 'webToPc') {\n const data = legacy.message.data\n let parsed\n\n if (typeof data === 'string') {\n try {\n parsed = JSON.parse(data)\n } catch {\n return null\n }\n } else if (typeof data === 'object') {\n parsed = data\n } else {\n return null\n }\n\n const { type, ...restPayload } = parsed\n if (!type) return null\n\n return {\n protocol: 'message-bridge-v1',\n id: legacy.id || generateId(),\n from: detectFromNode(legacy.from),\n to: detectToNode(legacy.to),\n type: String(type),\n payload: restPayload,\n timestamp: Date.now(),\n }\n }\n\n // Legacy: openclawToPc subtype\n if (legacy.message && legacy.message.subtype === 'openclawToPc') {\n return {\n protocol: 'message-bridge-v1',\n id: legacy.id || generateId(),\n from: detectFromNode(legacy.from),\n to: 'onepcweb',\n type: 'openclawToPc',\n payload: legacy.message.data,\n timestamp: Date.now(),\n }\n }\n\n return null\n}\n\n/**\n * Detect the source NodeId from legacy message's `from` field.\n */\nfunction detectFromNode(from) {\n if (!from) return 'intelligent'\n if (from.includes('openclaw') || from.includes('claw')) return 'openclaw'\n if (from.includes('intelligent')) return 'intelligent'\n if (from.includes('vantage') || from.includes('onepc')) return 'onepcweb'\n return 'intelligent'\n}\n\n/**\n * Detect the target NodeId from legacy message's `to` field.\n */\nfunction detectToNode(to) {\n if (!to) return 'intelligent'\n if (to.includes('pcWeb') || to.includes('pcMessage')) return 'onepcweb'\n if (to.includes('intelligent')) return 'intelligent'\n if (to.includes('openclaw') || to.includes('claw')) return 'openclaw'\n return 'intelligent'\n}\n\n/**\n * Serialize an Envelope for postMessage transmission.\n */\nexport function serializeEnvelope(envelope) {\n return { ...envelope }\n}\n", "import { createEnvelope, serializeEnvelope } from './envelope'\n\n/**\n * Router manages automatic message forwarding for middle-layer nodes.\n */\nexport class Router {\n constructor(opts = {}) {\n this.routes = []\n this.parentWindow = opts.parentWindow != null ? opts.parentWindow : null\n this.getChildWindow = opts.getChildWindow != null ? opts.getChildWindow : null\n this.debug = opts.debug != null ? opts.debug : false\n }\n\n addRoute(from, to) {\n this.removeRoute(from, to)\n this.routes.push({ from, to })\n this.log('route registered:', `${from} \u2192 ${to}`)\n }\n\n removeRoute(from, to) {\n this.routes = this.routes.filter(\n r => !(r.from === from && r.to === to)\n )\n }\n\n clearRoutes() {\n this.routes = []\n }\n\n getForwardTarget(envelope) {\n const route = this.routes.find(\n r => r.from === envelope.from && r.to === envelope.to\n )\n if (!route) return null\n\n if (envelope.to === 'onepcweb' && this.parentWindow) {\n return this.parentWindow\n }\n if (envelope.from === 'onepcweb' && this.getChildWindow) {\n return this.getChildWindow()\n }\n if (envelope.to !== 'intelligent' && this.parentWindow) {\n return this.parentWindow\n }\n\n return null\n }\n\n forward(envelope) {\n const target = this.getForwardTarget(envelope)\n if (!target) return false\n\n const body = serializeEnvelope(envelope)\n target.postMessage(body, '*')\n this.log('forwarded:', `${envelope.from} \u2192 ${envelope.to} via postMessage`, envelope.type)\n return true\n }\n\n hasRoute(from, to) {\n return this.routes.some(r => r.from === from && r.to === to)\n }\n\n process(envelope) {\n if (this.hasRoute(envelope.from, envelope.to)) {\n return this.forward(envelope)\n }\n return false\n }\n\n log(...args) {\n if (this.debug) {\n console.log('[OnePcBridge-Router]', ...args)\n }\n }\n}\n", "import { createEnvelope, parseEnvelope, serializeEnvelope } from './envelope'\nimport { Router } from './router'\n\n/**\n * OnePcBridge \u2014 unified cross-iframe communication SDK.\n *\n * Usage:\n * // Leaf node (C - openclaw)\n * const bridge = new OnePcBridge({\n * nodeId: 'openclaw',\n * allowedOrigins: ['https://...'],\n * parentWindow: window.parent,\n * })\n * bridge.init()\n * bridge.send('onepcweb', 'menu', { data: '...' })\n *\n * // Middle node (B - intelligent-web)\n * const bridge = new OnePcBridge({\n * nodeId: 'intelligent',\n * allowedOrigins: ['https://...', CHILD_ORIGIN],\n * parentWindow: window.parent,\n * getChildWindow: () => iframeRef.value?.contentWindow,\n * })\n * bridge.addRoute('openclaw', 'onepcweb')\n * bridge.init()\n */\nexport class OnePcBridge {\n constructor(config) {\n this.config = config\n this.handlers = new Map()\n this.router = new Router({\n parentWindow: config.parentWindow,\n getChildWindow: config.getChildWindow,\n debug: config.debug != null ? config.debug : false,\n })\n this.messageHandler = null\n this.initialized = false\n }\n\n init() {\n if (this.initialized) return\n\n this.messageHandler = this.handleMessage.bind(this)\n window.addEventListener('message', this.messageHandler)\n this.initialized = true\n this.log('initialized', this.config.nodeId)\n }\n\n destroy() {\n if (this.messageHandler) {\n window.removeEventListener('message', this.messageHandler)\n this.messageHandler = null\n }\n this.handlers.clear()\n this.initialized = false\n this.log('destroyed')\n }\n\n send(target, type, payload) {\n const envelope = createEnvelope(this.config.nodeId, target, type, payload)\n this.log('send:', `${this.config.nodeId} \u2192 ${target}`, type, payload)\n\n const targetWindow = this.getTargetWindow(target)\n if (targetWindow) {\n targetWindow.postMessage(serializeEnvelope(envelope), '*')\n } else {\n this.warn('no target window for:', target)\n }\n }\n\n on(type, handler) {\n if (!this.handlers.has(type)) {\n this.handlers.set(type, new Set())\n }\n this.handlers.get(type).add(handler)\n\n return () => {\n const set = this.handlers.get(type)\n if (set) {\n set.delete(handler)\n if (set.size === 0) {\n this.handlers.delete(type)\n }\n }\n }\n }\n\n addRoute(from, to) {\n this.router?.addRoute(from, to)\n }\n\n removeRoute(from, to) {\n this.router?.removeRoute(from, to)\n }\n\n // \u2500\u2500\u2500 Private \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n handleMessage(event) {\n if (event.origin && !this.config.allowedOrigins.includes(event.origin)) {\n return\n }\n\n const envelope = parseEnvelope(event.data)\n if (!envelope) return\n\n if (envelope.from === this.config.nodeId && envelope.to === this.config.nodeId) {\n return\n }\n\n if (envelope.to !== this.config.nodeId) {\n if (this.router?.process(envelope)) {\n this.dispatch(envelope)\n return\n }\n return\n }\n\n this.dispatch(envelope)\n }\n\n dispatch(envelope) {\n const typeHandlers = this.handlers.get(envelope.type)\n if (typeHandlers) {\n for (const handler of typeHandlers) {\n try {\n handler(envelope.payload, envelope)\n } catch (err) {\n this.warn('handler error:', envelope.type, err)\n }\n }\n }\n }\n\n getTargetWindow(target) {\n if (this.config.parentWindow && target !== this.config.nodeId) {\n return this.config.parentWindow\n }\n if (this.config.getChildWindow) {\n return this.config.getChildWindow()\n }\n return null\n }\n\n log(...args) {\n if (this.config.debug) {\n console.log(`[OnePcBridge:${this.config.nodeId}]`, ...args)\n }\n }\n\n warn(...args) {\n console.warn(`[OnePcBridge:${this.config.nodeId}]`, ...args)\n }\n}\n"],
5
+ "mappings": "2fAAA,IAAIA,EAAW,EAMf,SAASC,GAAa,CACpB,IAAMC,EAAK,KAAK,IAAI,EAAE,SAAS,EAAE,EAC3BC,GAAO,EAAEH,GAAU,SAAS,EAAE,EACpC,MAAO,MAAME,CAAE,IAAIC,CAAG,EACxB,CAKO,SAASC,EAAeC,EAAMC,EAAIC,EAAMC,EAAS,CACtD,MAAO,CACL,SAAU,oBACV,GAAIP,EAAW,EACf,KAAAI,EACA,GAAAC,EACA,KAAAC,EACA,QAASC,GAAW,KAAOA,EAAU,KACrC,UAAW,KAAK,IAAI,CACtB,CACF,CAaO,SAASC,EAAcC,EAAK,CACjC,GAAI,CAACA,EAAK,OAAO,KAGjB,GAAIA,EAAI,WAAa,oBACnB,OAAOA,EAIT,IAAMC,EAASD,EACf,GAAIC,EAAO,SAAWA,EAAO,QAAQ,UAAY,UAAW,CAC1D,IAAMC,EAAOD,EAAO,QAAQ,KACxBE,EAEJ,GAAI,OAAOD,GAAS,SAClB,GAAI,CACFC,EAAS,KAAK,MAAMD,CAAI,CAC1B,OAAQE,EAAA,CACN,OAAO,IACT,SACS,OAAOF,GAAS,SACzBC,EAASD,MAET,Q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K,SAAL,MAAAA,EAAa,SAASF,EAAMC,EAC9B,CAEA,YAAYD,EAAMC,EAAI,CA3FxB,IAAAC,GA4FIA,EAAA,KAAK,SAAL,MAAAA,EAAa,YAAYF,EAAMC,EACjC,CAIA,cAAcE,EAAO,CAjGvB,IAAAD,EAkGI,GAAIC,EAAM,QAAU,CAAC,KAAK,OAAO,eAAe,SAASA,EAAM,MAAM,EACnE,OAGF,IAAMT,EAAWU,EAAcD,EAAM,IAAI,EACzC,GAAKT,GAED,EAAAA,EAAS,OAAS,KAAK,OAAO,QAAUA,EAAS,KAAO,KAAK,OAAO,QAIxE,IAAIA,EAAS,KAAO,KAAK,OAAO,OAAQ,CACtC,IAAIQ,EAAA,KAAK,SAAL,MAAAA,EAAa,QAAQR,GAAW,CAClC,KAAK,SAASA,CAAQ,EACtB,MACF,CACA,MACF,CAEA,KAAK,SAASA,CAAQ,EACxB,CAEA,SAASA,EAAU,CACjB,IAAMW,EAAe,KAAK,SAAS,IAAIX,EAAS,IAAI,EACpD,GAAIW,EACF,QAAWP,KAAWO,EACpB,GAAI,CACFP,EAAQJ,EAAS,QAASA,CAAQ,CACpC,OAASY,EAAK,CACZ,KAAK,KAAK,iBAAkBZ,EAAS,KAAMY,CAAG,CAChD,CAGN,CAEA,gBAAgBf,EAAQ,CACtB,OAAI,KAAK,OAAO,cAAgBA,IAAW,KAAK,OAAO,OAC9C,KAAK,OAAO,aAEjB,KAAK,OAAO,eACP,KAAK,OAAO,eAAe,EAE7B,IACT,CAEA,OAAOgB,EAAM,CACP,KAAK,OAAO,OACd,QAAQ,IAAI,gBAAgB,KAAK,OAAO,MAAM,IAAK,GAAGA,CAAI,CAE9D,CAEA,QAAQA,EAAM,CACZ,QAAQ,KAAK,gBAAgB,KAAK,OAAO,MAAM,IAAK,GAAGA,CAAI,CAC7D,CACF",
6
+ "names": ["_counter", "generateId", "ts", "seq", "createEnvelope", "from", "to", "type", "payload", "parseEnvelope", "raw", "legacy", "data", "parsed", "e", "_a", "restPayload", "__objRest", "detectFromNode", "detectToNode", "serializeEnvelope", "envelope", "__spreadValues", "Router", "opts", "from", "to", "r", "envelope", "target", "body", "serializeEnvelope", "args", "OnePcBridge", "config", "Router", "target", "type", "payload", "envelope", "createEnvelope", "targetWindow", "serializeEnvelope", "handler", "set", "from", "to", "_a", "event", "parseEnvelope", "typeHandlers", "err", "args"]
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhyi64/message-bridge",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Unified cross-iframe communication SDK for nested iframe architecture (onepcweb → intelligent-web → openclaw)",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
@@ -31,7 +31,7 @@ export class OnePcBridge {
31
31
  this.router = new Router({
32
32
  parentWindow: config.parentWindow,
33
33
  getChildWindow: config.getChildWindow,
34
- debug: config.debug ?? false,
34
+ debug: config.debug != null ? config.debug : false,
35
35
  })
36
36
  this.messageHandler = null
37
37
  this.initialized = false
package/src/envelope.js CHANGED
@@ -20,7 +20,7 @@ export function createEnvelope(from, to, type, payload) {
20
20
  from,
21
21
  to,
22
22
  type,
23
- payload: payload ?? null,
23
+ payload: payload != null ? payload : null,
24
24
  timestamp: Date.now(),
25
25
  }
26
26
  }
package/src/router.js CHANGED
@@ -6,9 +6,9 @@ import { createEnvelope, serializeEnvelope } from './envelope'
6
6
  export class Router {
7
7
  constructor(opts = {}) {
8
8
  this.routes = []
9
- this.parentWindow = opts.parentWindow ?? null
10
- this.getChildWindow = opts.getChildWindow ?? null
11
- this.debug = opts.debug ?? false
9
+ this.parentWindow = opts.parentWindow != null ? opts.parentWindow : null
10
+ this.getChildWindow = opts.getChildWindow != null ? opts.getChildWindow : null
11
+ this.debug = opts.debug != null ? opts.debug : false
12
12
  }
13
13
 
14
14
  addRoute(from, to) {