Removes some dependancies from functions in app.js.

This commit is contained in:
hristoterezov 2015-01-09 14:19:48 +02:00
parent 1057ff36cd
commit 27502d3fa8
7 changed files with 58 additions and 76 deletions

61
app.js
View File

@ -44,18 +44,6 @@ var flipXLocalVideo = true;
var isFullScreen = false;
var currentVideoWidth = null;
var currentVideoHeight = null;
/**
* Method used to calculate large video size.
* @type {function ()}
*/
var getVideoSize;
/**
* Method used to get large video position.
* @type {function ()}
*/
var getVideoPosition;
/* window.onbeforeunload = closePageWarning; */
var sessionTerminated = false;
@ -624,10 +612,6 @@ function isVideoSrcDesktop(jid) {
return isDesktop;
}
function getConferenceHandler() {
return activecall;
}
/**
* Mutes/unmutes the local video.
*
@ -639,7 +623,7 @@ function getConferenceHandler() {
*/
function setVideoMute(mute, options) {
if (connection && connection.jingle.localVideo) {
var session = getConferenceHandler();
var session = activecall;
if (session) {
session.setVideoMute(
@ -677,7 +661,7 @@ function toggleVideo() {
buttonClick("#video", "icon-camera icon-camera-disabled");
if (connection && connection.jingle.localVideo) {
var session = getConferenceHandler();
var session = activecall;
if (session) {
setVideoMute(!session.isVideoMute());
@ -793,7 +777,7 @@ $(window).bind('beforeunload', function () {
function disposeConference(onUnload) {
UI.onDisposeConference(onUnload);
var handler = getConferenceHandler();
var handler = activecall;
if (handler && handler.peerconnection) {
// FIXME: probably removing streams is not required and close() should
// be enough
@ -809,45 +793,6 @@ function disposeConference(onUnload) {
activecall = null;
}
function dump(elem, filename) {
elem = elem.parentNode;
elem.download = filename || 'meetlog.json';
elem.href = 'data:application/json;charset=utf-8,\n';
var data = populateData();
elem.href += encodeURIComponent(JSON.stringify(data, null, ' '));
return false;
}
/**
* Populates the log data
*/
function populateData() {
var data = {};
if (connection.jingle) {
Object.keys(connection.jingle.sessions).forEach(function (sid) {
var session = connection.jingle.sessions[sid];
if (session.peerconnection && session.peerconnection.updateLog) {
// FIXME: should probably be a .dump call
data["jingle_" + session.sid] = {
updateLog: session.peerconnection.updateLog,
stats: session.peerconnection.stats,
url: window.location.href
};
}
});
}
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;
return data;
}
/**
* Changes the style class of the element given by id.
*/

View File

@ -260,10 +260,9 @@ function newStreamCreated(stream) {
UI.changeLocalVideo(stream, !isUsingScreenStream);
var conferenceHandler = getConferenceHandler();
if (conferenceHandler) {
if (activecall) {
// FIXME: will block switchInProgress on true value in case of exception
conferenceHandler.switchStreams(stream, oldStream, streamSwitchDone);
activecall.switchStreams(stream, oldStream, streamSwitchDone);
} else {
// We are done immediately
console.error("No conference handler");

View File

@ -321,5 +321,24 @@ Strophe.addConnectionPlugin('jingle', {
}
);
// implement push?
},
/**
* Populates the log data
*/
populateData: function () {
var data = {};
Object.keys(this.sessions).forEach(function (sid) {
var session = this.sessions[sid];
if (session.peerconnection && session.peerconnection.updateLog) {
// FIXME: should probably be a .dump call
data["jingle_" + session.sid] = {
updateLog: session.peerconnection.updateLog,
stats: session.peerconnection.stats,
url: window.location.href
};
}
});
return data;
}
});

View File

@ -551,16 +551,36 @@ 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;

View File

@ -29,10 +29,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);

View File

@ -1,5 +1,4 @@
/* 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");

View File

@ -16,10 +16,6 @@ var largeVideoState = {
newSrc: ''
};
// By default we use camera
var getVideoSize = getCameraVideoSize;
var getVideoPosition = getCameraVideoPosition;
var defaultLocalDisplayName = "Me";
/**
@ -407,6 +403,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
@ -692,10 +692,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;
@ -829,7 +829,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);
@ -837,7 +837,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);