{"ast":null,"code":"'use strict';\n\nvar urlUtils = require('./utils/url'),\n eventUtils = require('./utils/event'),\n JSON3 = require('json3'),\n FacadeJS = require('./facade'),\n InfoIframeReceiver = require('./info-iframe-receiver'),\n iframeUtils = require('./utils/iframe'),\n loc = require('./location');\n\nvar debug = function debug() {};\n\nif (process.env.NODE_ENV !== 'production') {\n debug = require('debug')('sockjs-client:iframe-bootstrap');\n}\n\nmodule.exports = function (SockJS, availableTransports) {\n var transportMap = {};\n availableTransports.forEach(function (at) {\n if (at.facadeTransport) {\n transportMap[at.facadeTransport.transportName] = at.facadeTransport;\n }\n }); // hard-coded for the info iframe\n // TODO see if we can make this more dynamic\n\n transportMap[InfoIframeReceiver.transportName] = InfoIframeReceiver;\n var parentOrigin;\n /* eslint-disable camelcase */\n\n SockJS.bootstrap_iframe = function () {\n /* eslint-enable camelcase */\n var facade;\n iframeUtils.currentWindowId = loc.hash.slice(1);\n\n var onMessage = function onMessage(e) {\n if (e.source !== parent) {\n return;\n }\n\n if (typeof parentOrigin === 'undefined') {\n parentOrigin = e.origin;\n }\n\n if (e.origin !== parentOrigin) {\n return;\n }\n\n var iframeMessage;\n\n try {\n iframeMessage = JSON3.parse(e.data);\n } catch (ignored) {\n debug('bad json', e.data);\n return;\n }\n\n if (iframeMessage.windowId !== iframeUtils.currentWindowId) {\n return;\n }\n\n switch (iframeMessage.type) {\n case 's':\n var p;\n\n try {\n p = JSON3.parse(iframeMessage.data);\n } catch (ignored) {\n debug('bad json', iframeMessage.data);\n break;\n }\n\n var version = p[0];\n var transport = p[1];\n var transUrl = p[2];\n var baseUrl = p[3];\n debug(version, transport, transUrl, baseUrl); // change this to semver logic\n\n if (version !== SockJS.version) {\n throw new Error('Incompatible SockJS! Main site uses:' + ' \"' + version + '\", the iframe:' + ' \"' + SockJS.version + '\".');\n }\n\n if (!urlUtils.isOriginEqual(transUrl, loc.href) || !urlUtils.isOriginEqual(baseUrl, loc.href)) {\n throw new Error('Can\\'t connect to different domain from within an ' + 'iframe. (' + loc.href + ', ' + transUrl + ', ' + baseUrl + ')');\n }\n\n facade = new FacadeJS(new transportMap[transport](transUrl, baseUrl));\n break;\n\n case 'm':\n facade._send(iframeMessage.data);\n\n break;\n\n case 'c':\n if (facade) {\n facade._close();\n }\n\n facade = null;\n break;\n }\n };\n\n eventUtils.attachEvent('message', onMessage); // Start\n\n iframeUtils.postMessage('s');\n };\n};","map":null,"metadata":{},"sourceType":"script"}