diff --git a/api_connector.js b/api_connector.js deleted file mode 100644 index 8281b1eb5..000000000 --- a/api_connector.js +++ /dev/null @@ -1,202 +0,0 @@ -/** - * 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: UI.inputDisplayNameHandler, - muteAudio: toggleAudio, - muteVideo: toggleVideo, - toggleFilmStrip: UI.toggleFilmStrip, - toggleChat: UI.toggleChat, - toggleContactList: UI.toggleContactList - }; - - - /** - * Maps the supported events and their status - * (true it the event is enabled and false if it is disabled) - * @type {{ - * incomingMessage: boolean, - * outgoingMessage: boolean, - * displayNameChange: boolean, - * participantJoined: boolean, - * participantLeft: boolean - * }} - */ - var events = - { - incomingMessage: false, - outgoingMessage:false, - displayNameChange: false, - participantJoined: false, - participantLeft: false - }; - - /** - * 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({type: "system", 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) {} - - if(!message.type) - return; - switch (message.type) - { - case "command": - APIConnector.processCommand(message); - break; - case "event": - APIConnector.processEvent(message); - break; - default: - console.error("Unknown type of the message"); - return; - } - - }; - - /** - * Processes commands from external applicaiton. - * @param message the object with the command - */ - APIConnector.processCommand = function (message) - { - if(message.action != "execute") - { - console.error("Unknown action of the message"); - return; - } - for(var key in message) - { - if(commands[key]) - commands[key].apply(null, message[key]); - } - }; - - /** - * Processes events objects from external applications - * @param event the event - */ - APIConnector.processEvent = function (event) { - if(!event.action) - { - console.error("Event with no action is received."); - return; - } - - switch(event.action) - { - case "add": - for(var i = 0; i < event.events.length; i++) - { - events[event.events[i]] = true; - } - break; - case "remove": - for(var i = 0; i < event.events.length; i++) - { - events[event.events[i]] = false; - } - break; - default: - console.error("Unknown action for event."); - } - - }; - - /** - * Checks whether the event is enabled ot not. - * @param name the name of the event. - * @returns {*} - */ - APIConnector.isEventEnabled = function (name) { - return events[name]; - }; - - /** - * Sends event object to the external application that has been subscribed - * for that event. - * @param name the name event - * @param object data associated with the event - */ - APIConnector.triggerEvent = function (name, object) { - APIConnector.sendMessage({ - type: "event", action: "result", event: name, result: object}); - }; - - /** - * Removes the listeners. - */ - APIConnector.dispose = function () { - if(window.removeEventListener) - { - window.removeEventListener("message", - APIConnector.processMessage, false); - } - else - { - window.detachEvent('onmessage', APIConnector.processMessage); - } - - }; - - return APIConnector; -})(); \ No newline at end of file diff --git a/app.js b/app.js index f9f0428b2..501102bd0 100644 --- a/app.js +++ b/app.js @@ -732,8 +732,8 @@ function isAudioMuted() $(document).ready(function () { - if(APIConnector.isEnabled()) - APIConnector.init(); + if(API.isEnabled()) + API.init(); UI.start(); statistics.start(); @@ -771,8 +771,8 @@ $(window).bind('beforeunload', function () { }); } disposeConference(true); - if(APIConnector.isEnabled()) - APIConnector.dispose(); + if(API.isEnabled()) + API.dispose(); }); function disposeConference(onUnload) { diff --git a/index.html b/index.html index a8cbeb8a4..57c1d0f5e 100644 --- a/index.html +++ b/index.html @@ -31,19 +31,19 @@ - + + - diff --git a/libs/modules/API.bundle.js b/libs/modules/API.bundle.js new file mode 100644 index 000000000..ca7317bc4 --- /dev/null +++ b/libs/modules/API.bundle.js @@ -0,0 +1,207 @@ +!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.API=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o -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. + */ + init: function () { + if (window.addEventListener) + { + window.addEventListener('message', + processMessage, false); + } + else + { + window.attachEvent('onmessage', processMessage); + } + sendMessage({type: "system", loaded: true}); + }, + /** + * Checks whether the event is enabled ot not. + * @param name the name of the event. + * @returns {*} + */ + isEventEnabled: function (name) { + return events[name]; + }, + + /** + * Sends event object to the external application that has been subscribed + * for that event. + * @param name the name event + * @param object data associated with the event + */ + triggerEvent: function (name, object) { + if(this.isEnabled() && this.isEventEnabled(name)) + sendMessage({ + type: "event", action: "result", event: name, result: object}); + }, + + /** + * Removes the listeners. + */ + dispose: function () { + if(window.removeEventListener) + { + window.removeEventListener("message", + processMessage, false); + } + else + { + window.detachEvent('onmessage', processMessage); + } + + } + + +}; + +module.exports = API; +},{}]},{},[1])(1) +}); \ No newline at end of file diff --git a/libs/modules/UI.bundle.js b/libs/modules/UI.bundle.js index 26f4b2156..532372636 100644 --- a/libs/modules/UI.bundle.js +++ b/libs/modules/UI.bundle.js @@ -461,12 +461,6 @@ UI.onMucEntered = function (jid, id, displayName) { // Add Peer's container VideoLayout.ensurePeerContainerExists(jid,id); - - if(APIConnector.isEnabled() && - APIConnector.isEventEnabled("participantJoined")) - { - APIConnector.triggerEvent("participantJoined",{jid: jid}); - } }; UI.onMucPresenceStatus = function ( jid, info) { @@ -552,17 +546,37 @@ UI.generateRoomName = function() { UI.connectionIndicatorShowMore = function(id) { return VideoLayout.connectionIndicators[id].showMore(); -} +}; UI.showToolbar = function () { return ToolbarToggler.showToolbar(); -} +}; UI.dockToolbar = function (isDock) { return ToolbarToggler.dockToolbar(isDock); -} +}; +function dump(elem, filename) { + elem = elem.parentNode; + elem.download = filename || 'meetlog.json'; + elem.href = 'data:application/json;charset=utf-8,\n'; + var data = {}; + if (connection.jingle) { + data = connection.jingle.populateData(); + } + var metadata = {}; + metadata.time = new Date(); + metadata.url = window.location.href; + metadata.ua = navigator.userAgent; + if (connection.logger) { + metadata.xmpp = connection.logger.log; + } + data.metadata = metadata; + elem.href += encodeURIComponent(JSON.stringify(data, null, ' ')); + return false; +} + module.exports = UI; @@ -1683,10 +1697,10 @@ var PanelToggler = (function(my) { var videospaceWidth = window.innerWidth - panelSize[0]; var videospaceHeight = window.innerHeight; var videoSize - = getVideoSize(null, null, videospaceWidth, videospaceHeight); + = VideoLayout.getVideoSize(null, null, videospaceWidth, videospaceHeight); var videoWidth = videoSize[0]; var videoHeight = videoSize[1]; - var videoPosition = getVideoPosition(videoWidth, + var videoPosition = VideoLayout.getVideoPosition(videoWidth, videoHeight, videospaceWidth, videospaceHeight); @@ -1908,8 +1922,7 @@ var PanelToggler = (function(my) { module.exports = PanelToggler; },{"../toolbars/ToolbarToggler":16,"../videolayout/VideoLayout":23,"./chat/Chat":8,"./contactlist/ContactList":12,"./settings/Settings":13,"./settings/SettingsMenu":14}],8:[function(require,module,exports){ -/* global $, Util, connection, nickname:true, getVideoSize, -getVideoPosition, showToolbar */ +/* global $, Util, connection, nickname:true, showToolbar */ var Replacement = require("./Replacement"); var CommandsProcessor = require("./Commands"); var ToolbarToggler = require("../../toolbars/ToolbarToggler"); @@ -4180,10 +4193,6 @@ var largeVideoState = { newSrc: '' }; -// By default we use camera -var getVideoSize = getCameraVideoSize; -var getVideoPosition = getCameraVideoPosition; - var defaultLocalDisplayName = "Me"; /** @@ -4571,6 +4580,10 @@ function createModeratorIndicatorElement(parentElement) { var VideoLayout = (function (my) { my.connectionIndicators = {}; + // By default we use camera + my.getVideoSize = getCameraVideoSize; + my.getVideoPosition = getCameraVideoPosition; + my.isInLastN = function(resource) { return lastNCount < 0 // lastN is disabled, return true || (lastNCount > 0 && lastNEndpointsCache.length == 0) // lastNEndpoints cache not built yet, return true @@ -4856,10 +4869,10 @@ var VideoLayout = (function (my) { // Change the way we'll be measuring and positioning large video - getVideoSize = largeVideoState.isDesktop + VideoLayout.getVideoSize = largeVideoState.isDesktop ? getDesktopVideoSize : getCameraVideoSize; - getVideoPosition = largeVideoState.isDesktop + VideoLayout.getVideoPosition = largeVideoState.isDesktop ? getDesktopVideoPosition : getCameraVideoPosition; @@ -4993,7 +5006,7 @@ var VideoLayout = (function (my) { var videoSpaceWidth = $('#videospace').width(); var videoSpaceHeight = window.innerHeight; - var videoSize = getVideoSize(videoWidth, + var videoSize = VideoLayout.getVideoSize(videoWidth, videoHeight, videoSpaceWidth, videoSpaceHeight); @@ -5001,7 +5014,7 @@ var VideoLayout = (function (my) { var largeVideoWidth = videoSize[0]; var largeVideoHeight = videoSize[1]; - var videoPosition = getVideoPosition(largeVideoWidth, + var videoPosition = VideoLayout.getVideoPosition(largeVideoWidth, largeVideoHeight, videoSpaceWidth, videoSpaceHeight); @@ -5842,13 +5855,10 @@ var VideoLayout = (function (my) { status); } - if(APIConnector.isEnabled() && APIConnector.isEventEnabled("displayNameChange")) - { - if(jid === 'localVideoContainer') - jid = connection.emuc.myroomjid; - if(!name || name != displayName) - APIConnector.triggerEvent("displayNameChange",{jid: jid, displayname: displayName}); - } + if(jid === 'localVideoContainer') + jid = connection.emuc.myroomjid; + if(!name || name != displayName) + API.triggerEvent("displayNameChange",{jid: jid, displayname: displayName}); }); /** diff --git a/modules/API/API.js b/modules/API/API.js new file mode 100644 index 000000000..934841629 --- /dev/null +++ b/modules/API/API.js @@ -0,0 +1,204 @@ +/** + * Implements API class that communicates with external api class + * and provides interface to access Jitsi Meet features by external + * applications that embed Jitsi Meet + */ + + + +/** + * List of the available commands. + * @type {{ + * displayName: inputDisplayNameHandler, + * muteAudio: toggleAudio, + * muteVideo: toggleVideo, + * filmStrip: toggleFilmStrip + * }} + */ +var commands = +{ + displayName: UI.inputDisplayNameHandler, + muteAudio: toggleAudio, + muteVideo: toggleVideo, + toggleFilmStrip: UI.toggleFilmStrip, + toggleChat: UI.toggleChat, + toggleContactList: UI.toggleContactList +}; + + +/** + * Maps the supported events and their status + * (true it the event is enabled and false if it is disabled) + * @type {{ + * incomingMessage: boolean, + * outgoingMessage: boolean, + * displayNameChange: boolean, + * participantJoined: boolean, + * participantLeft: boolean + * }} + */ +var events = +{ + incomingMessage: false, + outgoingMessage:false, + displayNameChange: false, + participantJoined: false, + participantLeft: false +}; + +/** + * Processes commands from external applicaiton. + * @param message the object with the command + */ +function processCommand(message) +{ + if(message.action != "execute") + { + console.error("Unknown action of the message"); + return; + } + for(var key in message) + { + if(commands[key]) + commands[key].apply(null, message[key]); + } +} + +/** + * Processes events objects from external applications + * @param event the event + */ +function processEvent(event) { + if(!event.action) + { + console.error("Event with no action is received."); + return; + } + + var i = 0; + switch(event.action) + { + case "add": + for(; i < event.events.length; i++) + { + events[event.events[i]] = true; + } + break; + case "remove": + for(; i < event.events.length; i++) + { + events[event.events[i]] = false; + } + break; + default: + console.error("Unknown action for event."); + } + +} + +/** + * Sends message to the external application. + * @param object + */ +function sendMessage(object) { + window.parent.postMessage(JSON.stringify(object), "*"); +} + +/** + * Processes a message event from the external application + * @param event the message event + */ +function processMessage(event) +{ + var message; + try { + message = JSON.parse(event.data); + } catch (e) {} + + if(!message.type) + return; + switch (message.type) + { + case "command": + processCommand(message); + break; + case "event": + processEvent(message); + break; + default: + console.error("Unknown type of the message"); + return; + } + +} + +var API = { + /** + * Check whether the API should be enabled or not. + * @returns {boolean} + */ + 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. + */ + init: function () { + if (window.addEventListener) + { + window.addEventListener('message', + processMessage, false); + } + else + { + window.attachEvent('onmessage', processMessage); + } + sendMessage({type: "system", loaded: true}); + }, + /** + * Checks whether the event is enabled ot not. + * @param name the name of the event. + * @returns {*} + */ + isEventEnabled: function (name) { + return events[name]; + }, + + /** + * Sends event object to the external application that has been subscribed + * for that event. + * @param name the name event + * @param object data associated with the event + */ + triggerEvent: function (name, object) { + if(this.isEnabled() && this.isEventEnabled(name)) + sendMessage({ + type: "event", action: "result", event: name, result: object}); + }, + + /** + * Removes the listeners. + */ + dispose: function () { + if(window.removeEventListener) + { + window.removeEventListener("message", + processMessage, false); + } + else + { + window.detachEvent('onmessage', processMessage); + } + + } + + +}; + +module.exports = API; \ No newline at end of file diff --git a/modules/UI/UI.js b/modules/UI/UI.js index 41aeffa4a..c8edf59d3 100644 --- a/modules/UI/UI.js +++ b/modules/UI/UI.js @@ -460,12 +460,6 @@ UI.onMucEntered = function (jid, id, displayName) { // Add Peer's container VideoLayout.ensurePeerContainerExists(jid,id); - - if(APIConnector.isEnabled() && - APIConnector.isEventEnabled("participantJoined")) - { - APIConnector.triggerEvent("participantJoined",{jid: jid}); - } }; UI.onMucPresenceStatus = function ( jid, info) { diff --git a/modules/UI/videolayout/VideoLayout.js b/modules/UI/videolayout/VideoLayout.js index 9fdcc6722..2e8969cf0 100644 --- a/modules/UI/videolayout/VideoLayout.js +++ b/modules/UI/videolayout/VideoLayout.js @@ -1678,13 +1678,10 @@ var VideoLayout = (function (my) { status); } - if(APIConnector.isEnabled() && APIConnector.isEventEnabled("displayNameChange")) - { - if(jid === 'localVideoContainer') - jid = connection.emuc.myroomjid; - if(!name || name != displayName) - APIConnector.triggerEvent("displayNameChange",{jid: jid, displayname: displayName}); - } + if(jid === 'localVideoContainer') + jid = connection.emuc.myroomjid; + if(!name || name != displayName) + API.triggerEvent("displayNameChange",{jid: jid, displayname: displayName}); }); /** diff --git a/muc.js b/muc.js index 1d10f4662..98b347337 100644 --- a/muc.js +++ b/muc.js @@ -199,6 +199,7 @@ Strophe.addConnectionPlugin('emuc', { id = email.text(); } UI.onMucEntered(from, id, member.displayName); + API.triggerEvent("participantJoined",{jid: from}); } } else { // Presence update for existing participant @@ -278,10 +279,7 @@ Strophe.addConnectionPlugin('emuc', { msg.c('nick', {xmlns: 'http://jabber.org/protocol/nick'}).t(nickname).up().up(); } this.connection.send(msg); - if(APIConnector.isEnabled() && APIConnector.isEventEnabled("outgoingMessage")) - { - APIConnector.triggerEvent("outgoingMessage", {"message": body}); - } + API.triggerEvent("outgoingMessage", {"message": body}); }, setSubject: function (subject){ var msg = $msg({to: this.roomjid, type: 'groupchat'}); @@ -316,12 +314,9 @@ Strophe.addConnectionPlugin('emuc', { if (txt) { console.log('chat', nick, txt); UI.updateChatConversation(from, nick, txt); - if(APIConnector.isEnabled() && APIConnector.isEventEnabled("incomingMessage")) - { - if(from != this.myroomjid) - APIConnector.triggerEvent("incomingMessage", - {"from": from, "nick": nick, "message": txt}); - } + if(from != this.myroomjid) + API.triggerEvent("incomingMessage", + {"from": from, "nick": nick, "message": txt}); } return true; }, @@ -537,10 +532,7 @@ Strophe.addConnectionPlugin('emuc', { onParticipantLeft: function (jid) { UI.onMucLeft(jid); - if(APIConnector.isEnabled() && APIConnector.isEventEnabled("participantLeft")) - { - APIConnector.triggerEvent("participantLeft",{jid: jid}); - } + API.triggerEvent("participantLeft",{jid: jid}); delete jid2Ssrc[jid];