/*!
 * Copyright 2014 Apereo Foundation (AF) Licensed under the
 * Educational Community License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License. You may
 * obtain a copy of the License at
 *
 *     http://opensource.org/licenses/ECL-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an "AS IS"
 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */

define(['jquery', 'oae.core', 'postis', 'JitsiMeetExternalAPI'], function ($, oae, postis, JitsiMeetExternalAPI) {

    return function (uid, showSettings, widgetData) {

        // getting meetingId to use as room id
        var meetingId = _.last(widgetData.id.split(':'));

        // The widget container
        var $rootel = $('#' + uid);

        // Variable used to cache the jitsi api
        var api = null;

        // Variable user to cache the current user
        var user = null;

        /**
         * Set up the user name instead of the default "me"
         */
        var setUpUserName = function () {

            oae.api.user.getMe(function (err, me) {
                if (err) {
                    throw new Error(err.code, err.msg);
                }

                user = me;
                api.executeCommand('displayName', [user.displayName]);
            });

        };

        /**
         * Toggle the video chat
         */
        var toggleChat = function () {
            api.executeCommand('toggleChat', []);
        };

        /**
         * Toggle the video contact list
         */
        var toggleContactList = function () {
            api.executeCommand('toggleContactList', []);
        };

        /**
         * Set up the room options
         */
        var setUpRoomOptions = function () {
            setUpUserName();

            if (widgetData.chat === true) {
                toggleChat();
            }
            if (widgetData.contactList === true) {
                toggleContactList();
            }
        };

        /**
         * Render the meeting room.
         */
        var renderMeeting = function () {

            var domain = oae.api.config.getValue('oae-jitsi', 'server', 'host');
            var room = meetingId;
            var width = 700;
            var height = 700;
            var container = document.querySelector('#meeting-jitsi-room');

            // we're not allowing HTTP
            api = new JitsiMeetExternalAPI(domain, room, width, height, container, null, null, false);

            setUpRoomOptions();

        };

        renderMeeting();
    };
});

@@ -17,9 +17,9 @@
  201
-4
+7
  Ape
@@ -855,15 +855,8 @@
 d = 
-_.last(
 widg
@@ -869,18 +869,26 @@
 .id.
-split(':')
+replace(/%5C:/g, '-'
 );%0A%0A

Set meetingId to include tenant alias