constructor()

in lib/websandbox.ts [75:104]


  constructor(localApi: API, options: Partial<SandboxOptions>) {
    this.validateOptions(options);
    this.options = {...BaseOptions, ...options};
    this.iframe = this.createIframe();

    this.promise = new Promise(resolve => {
      this.connection = new Connection(
        this.iframe.contentWindow!.postMessage.bind(this.iframe.contentWindow),
        listener => {
          const sourceCheckListener = (event: MessageEvent) => {
            if (event.source !== this.iframe.contentWindow) {
              return;
            }
            return listener(event);
          };
          window.addEventListener('message', sourceCheckListener);
          this.removeMessageListener = () => window.removeEventListener('message', sourceCheckListener);
        },
        {allowedSenderOrigin: 'null'}
      );

      this.connection.setServiceMethods({
        iframeInitialized: () => {
          return this.connection!
            .setLocalApi(localApi)
            .then(() => resolve(this));
        }
      });
    });
  }