{"size": 967, "ext": "js", "max_stars_repo_path": "client/app/comm/transmitter.js", "max_stars_repo_name": "boristomic/emarsys-integration-js", "max_stars_repo_stars_event_min_datetime": "2016-02-02T16:52:47.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-05T09:58:32.000Z", "max_issues_repo_path": "client/app/comm/transmitter.js", "max_issues_repo_name": "boristomic/emarsys-integration-js", "max_issues_repo_issues_event_min_datetime": "2017-01-12T10:13:30.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-05T14:41:24.000Z", "max_forks_repo_path": "client/app/comm/transmitter.js", "max_forks_repo_name": "boristomic/emarsys-integration-js", "max_forks_repo_forks_event_min_datetime": "2015-12-01T12:59:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-17T19:48:09.000Z"}
{"max_stars_count": 2, "max_issues_count": 17, "max_forks_count": 26, "avg_line_length": 30.21875, "max_line_length": 111, "alphanum_fraction": 0.7145811789}
'use strict';

const ServiceTransmitter = require('emarsys-integration-client').comm.Transmitter;

class Transmitter extends ServiceTransmitter {

  sendMessage(message, integrationInstanceId) {
    console.log('Method integration.sendMessage() is deprecated. Use integration.messageToService() instead.');
    this.messageToService(message, integrationInstanceId);
  }

  messageToEmarsys(eventName, data) {
    this.global.postMessage(
      JSON.stringify(
        this.setMessageSource(
          this.compileMessage(eventName, data))), '*');
  }

  messageToService(eventName, data, targetInstanceId) {
    const integrationInstance = this.global.$('#integration-' + targetInstanceId);
    if (integrationInstance && integrationInstance.length) {
      integrationInstance[0].contentWindow.postMessage(
        JSON.stringify(
          this.setMessageSource(
            this.compileMessage(eventName, data))), '*');
    }
  }

}

module.exports = Transmitter;
