| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 | /**
 * Implements API class that communicates with external api class
 * and provides interface to access Jitsi Meet features by external
 * applications that embed Jitsi Meet
 */
var APIConnector = (function () {
    function APIConnector() { }
    /**
     * List of the available commands.
     * @type {{
     *              displayName: inputDisplayNameHandler,
     *              muteAudio: toggleAudio,
     *              muteVideo: toggleVideo,
     *              filmStrip: toggleFilmStrip
     *          }}
     */
    var commands =
    {
        displayName: VideoLayout.inputDisplayNameHandler,
        muteAudio: toggleAudio,
        muteVideo: toggleVideo,
        filmStrip: BottomToolbar.toggleFilmStrip
    };
    /**
     * Check whether the API should be enabled or not.
     * @returns {boolean}
     */
    APIConnector.isEnabled = function () {
        var hash = location.hash;
        if(hash && hash.indexOf("external") > -1 && window.postMessage)
            return true;
        return false;
    };
    /**
     * Initializes the APIConnector. Setups message event listeners that will
     * receive information from external applications that embed Jitsi Meet.
     * It also sends a message to the external application that APIConnector
     * is initialized.
     */
    APIConnector.init = function () {
        if (window.addEventListener)
        {
            window.addEventListener('message',
                APIConnector.processMessage, false);
        }
        else
        {
            window.attachEvent('onmessage', APIConnector.processMessage);
        }
        APIConnector.sendMessage({loaded: true});
    };
    /**
     * Sends message to the external application.
     * @param object
     */
    APIConnector.sendMessage = function (object) {
        window.parent.postMessage(JSON.stringify(object), "*");
    };
    /**
     * Processes a message event from the external application
     * @param event the message event
     */
    APIConnector.processMessage = function(event)
    {
        var message;
        try {
            message = JSON.parse(event.data);
        } catch (e) {}
        for(var key in message)
        {
            if(commands[key])
                commands[key].apply(null, message[key]);
        }
    };
    /**
     * Removes the listeners.
     */
    APIConnector.dispose = function () {
        if(window.removeEventListener)
        {
            window.removeEventListener("message",
                APIConnector.processMessage, false);
        }
        else
        {
            window.detachEvent('onmessage', APIConnector.processMessage);
        }
    };
    return APIConnector;
})();
 |