From 428246cbe2f199246e3e2bbe9d1b39afef95e68e Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Fri, 9 Jun 2017 01:16:39 +0700 Subject: [PATCH] Make it work without iframe --- client/coral-embed-stream/src/index.js | 27 ++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/client/coral-embed-stream/src/index.js b/client/coral-embed-stream/src/index.js index 821399488..16c510c29 100644 --- a/client/coral-embed-stream/src/index.js +++ b/client/coral-embed-stream/src/index.js @@ -19,14 +19,29 @@ loadPluginsTranslations(); injectPluginsReducers(); injectReducers(reducers); +function inIframe() { + try { + return window.self !== window.top; + } catch (e) { + return true; + } +} + +function init(config = {}) { + store.dispatch(addExternalConfig(config)); + store.dispatch(checkLogin()); +} + // Don't run this in the popup. if (!window.opener) { - pym.sendMessage('getConfig'); - - pym.onMessage('config', (config) => { - store.dispatch(addExternalConfig(JSON.parse(config))); - store.dispatch(checkLogin()); - }); + if (inIframe()) { + pym.sendMessage('getConfig'); + pym.onMessage('config', (config) => { + init(JSON.parse(config)); + }); + } else { + init(); + } } render(