define(['./windowChannel', './runtime'], (WindowChannel, Runtime) => {
    'use strict';

    class Integration {
        constructor({ rootWindow }) {
            this.rootWindow = rootWindow;
            this.container = rootWindow.document.body;
            // channelId, frameId, hostId, parentHost
            this.hostParams = this.getParamsFromIFrame();
            this.hostChannelId = this.hostParams.channelId;

            // The original params from the plugin (taken from the url)
            this.pluginParams = this.hostParams.params;

            this.authorized = null;

            // this is the channel for this window.
            // this.channel = new WindowChannel.Channel({
            //     window: this.rootWindow,
            //     host: document.location.origin
            //     // recieveFor: [this.id],
            //     // clientId: this.iframe.id,
            //     // hostId: this.id
            // });

            // this.performanceMonitoringListener = null;

            // // This is the channel for the window containing this iframe.
            // this.hostChannel = new WindowChannel.Channel({
            //     window: this.rootWindow.parent,
            //     host: this.hostParams.parentHost,
            //     channelId: this.hostParams.channelId
            // });

            this.channel = new WindowChannel.BidirectionalWindowChannel({
                on: this.rootWindow,
                host: document.location.origin,
                to: this.hostChannelId
            });
        }

        getParamsFromIFrame() {
            if (!this.rootWindow.frameElement.hasAttribute('data-params')) {
                throw new Error('No params found in window!!');
            }
            return JSON.parse(decodeURIComponent(this.rootWindow.frameElement.getAttribute('data-params')));
        }

        start() {
            this.channel.start();

            this.channel.on('start', (payload) => {
                const { token, username, config, realname, email } = payload;
                if (token) {
                    this.authorization = { token, username, realname, email };
                } else {
                    this.authorization = null;
                }
                this.token = token;
                this.username = username;
                this.config = config;
                this.authorized = token ? true : false;

                this.runtime = new Runtime({ config, token, username, realname, email });
            });

            window.document.addEventListener('click', () => {
                this.channel.send('clicked', {});
            });

            // Sending 'ready' with our channel id and host name allows the
            // enclosing app (window) to send us messages on our very own channel.
            // We could just use the host's channel, have all sends and receives
            // on the same channel, with control via the channel id. However, there is a risk
            // the the channels will listen on for the same message ... unlikely though.
            // Still, it would be odd for one window to listen for messages on another...
            this.channel.send('ready', {
                channelId: this.channel.id,
                channelHost: this.channel.host
            });
        }

        stop() {}
    }

    return Integration;
});

@@ -1947,24 +1947,50 @@
 yload) =%3E %7B%0A
+                try %7B%0A    
             
@@ -2067,24 +2067,28 @@
             
+ 
+   
 if (token) %7B
@@ -2084,24 +2084,28 @@
 f (token) %7B%0A
+    
             
@@ -2187,16 +2187,20 @@
         
+  
+  
 %7D else %7B
@@ -2200,16 +2200,20 @@
  else %7B%0A
+    
         
@@ -2259,34 +2259,42 @@
                 
+   
+ 
 %7D%0A
+    
                 
@@ -2313,16 +2313,20 @@
  token;%0A
+    
         
@@ -2367,32 +2367,36 @@
                 
+    
 this.config = co
@@ -2401,16 +2401,20 @@
 config;%0A
+    
         
@@ -2474,24 +2474,28 @@
             
+ 
+   
 this.runtime
@@ -2552,24 +2552,243 @@
 , email %7D);%0A
+                %7D catch (ex) %7B%0A                    this.channel.send('start-error', %7B%0A                        message: ex.message%0A                    %7D);%0A                %7D%0A%0A                this.channel.send('started');%0A
             

fix inegration; ensure started and start-error are sent after handling start.