"use strict";

System.register([], function (_export, _context) {
    "use strict";

    return {
        setters: [],
        execute: function () {
            const __SystemJSRewritingHack = {};
            _recorder_._src_client_messaging_js = _recorder_._src_client_messaging_js || {};
            Object.defineProperty(_recorder_._src_client_messaging_js, "postMessage", {
                get() {
                    return postMessage;
                },

                set(thisIsVererySecretVariableName) {
                    _export("postMessage", postMessage = thisIsVererySecretVariableName);

                    return true;
                },

                enumerable: true,
                configurable: true
            });
            window.addEventListener('error', function (error) {
                console.log("Error:", error);
            });

            /**
             * Send a message to the ServiceWorker and waits for an answer
             * @param message
             * @returns {Promise} A Promise resolving with the answer from the ServiceWorker
             */
            function postMessage(message) {
                // TODO: what about rejecting the Promise onerror
                return new Promise(function (resolve, reject) {
                    var channel = new MessageChannel();
                    channel.port1.onmessage = resolve;

                    navigator.serviceWorker.controller.postMessage(message, [channel.port2]);
                });
            }

            _export("postMessage", postMessage);
        }
    };
});