2015-07-28 21:52:32 +00:00
|
|
|
/* global $, interfaceConfig, APP */
|
2015-06-23 08:00:46 +00:00
|
|
|
var SmallVideo = require("./SmallVideo");
|
|
|
|
var ConnectionIndicator = require("./ConnectionIndicator");
|
|
|
|
var NicknameHandler = require("../util/NicknameHandler");
|
|
|
|
var UIUtil = require("../util/UIUtil");
|
|
|
|
var LargeVideo = require("./LargeVideo");
|
2015-07-10 09:57:20 +00:00
|
|
|
var RTCBrowserType = require("../../RTC/RTCBrowserType");
|
2015-06-23 08:00:46 +00:00
|
|
|
|
2015-07-28 21:52:32 +00:00
|
|
|
function LocalVideo(VideoLayout) {
|
2015-06-23 08:00:46 +00:00
|
|
|
this.videoSpanId = "localVideoContainer";
|
|
|
|
this.container = $("#localVideoContainer").get(0);
|
2015-08-21 14:37:57 +00:00
|
|
|
this.bindHoverHandler();
|
2015-06-23 08:00:46 +00:00
|
|
|
this.VideoLayout = VideoLayout;
|
|
|
|
this.flipX = true;
|
2015-07-15 10:14:34 +00:00
|
|
|
this.isLocal = true;
|
2015-06-23 08:00:46 +00:00
|
|
|
this.peerJid = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
LocalVideo.prototype = Object.create(SmallVideo.prototype);
|
|
|
|
LocalVideo.prototype.constructor = LocalVideo;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates the edit display name button.
|
|
|
|
*
|
2015-07-28 21:52:32 +00:00
|
|
|
* @returns {object} the edit button
|
2015-06-23 08:00:46 +00:00
|
|
|
*/
|
|
|
|
function createEditDisplayNameButton() {
|
|
|
|
var editButton = document.createElement('a');
|
|
|
|
editButton.className = 'displayname';
|
|
|
|
UIUtil.setTooltip(editButton,
|
|
|
|
"videothumbnail.editnickname",
|
|
|
|
"top");
|
|
|
|
editButton.innerHTML = '<i class="fa fa-pencil"></i>';
|
|
|
|
|
|
|
|
return editButton;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the display name for the given video span id.
|
|
|
|
*/
|
|
|
|
LocalVideo.prototype.setDisplayName = function(displayName, key) {
|
|
|
|
if (!this.container) {
|
|
|
|
console.warn(
|
2015-07-28 21:52:32 +00:00
|
|
|
"Unable to set displayName - " + this.videoSpanId +
|
|
|
|
" does not exist");
|
2015-06-23 08:00:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var nameSpan = $('#' + this.videoSpanId + '>span.displayname');
|
2015-07-03 09:34:05 +00:00
|
|
|
var defaultLocalDisplayName = APP.translation.generateTranslationHTML(
|
2015-06-23 08:00:46 +00:00
|
|
|
interfaceConfig.DEFAULT_LOCAL_DISPLAY_NAME);
|
|
|
|
|
2015-07-28 21:52:32 +00:00
|
|
|
var meHTML;
|
2015-06-23 08:00:46 +00:00
|
|
|
// If we already have a display name for this video.
|
|
|
|
if (nameSpan.length > 0) {
|
|
|
|
if (nameSpan.text() !== displayName) {
|
2015-07-28 21:52:32 +00:00
|
|
|
if (displayName && displayName.length > 0) {
|
|
|
|
meHTML = APP.translation.generateTranslationHTML("me");
|
2015-06-23 08:00:46 +00:00
|
|
|
$('#localDisplayName').html(displayName + ' (' + meHTML + ')');
|
2015-07-28 21:52:32 +00:00
|
|
|
} else {
|
2015-06-23 08:00:46 +00:00
|
|
|
$('#localDisplayName').html(defaultLocalDisplayName);
|
2015-07-28 21:52:32 +00:00
|
|
|
}
|
2015-06-23 08:00:46 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
var editButton = createEditDisplayNameButton();
|
|
|
|
|
|
|
|
nameSpan = document.createElement('span');
|
|
|
|
nameSpan.className = 'displayname';
|
|
|
|
$('#' + this.videoSpanId)[0].appendChild(nameSpan);
|
|
|
|
|
|
|
|
|
|
|
|
if (displayName && displayName.length > 0) {
|
2015-07-28 21:52:32 +00:00
|
|
|
meHTML = APP.translation.generateTranslationHTML("me");
|
2015-06-23 08:00:46 +00:00
|
|
|
nameSpan.innerHTML = displayName + meHTML;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nameSpan.innerHTML = defaultLocalDisplayName;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nameSpan.id = 'localDisplayName';
|
|
|
|
this.container.appendChild(editButton);
|
|
|
|
//translates popover of edit button
|
|
|
|
APP.translation.translateElement($("a.displayname"));
|
|
|
|
|
|
|
|
var editableText = document.createElement('input');
|
|
|
|
editableText.className = 'displayname';
|
|
|
|
editableText.type = 'text';
|
|
|
|
editableText.id = 'editDisplayName';
|
|
|
|
|
|
|
|
if (displayName && displayName.length) {
|
|
|
|
editableText.value = displayName;
|
|
|
|
}
|
|
|
|
|
|
|
|
var defaultNickname = APP.translation.translateString(
|
|
|
|
"defaultNickname", {name: "Jane Pink"});
|
|
|
|
editableText.setAttribute('style', 'display:none;');
|
|
|
|
editableText.setAttribute('data-18n',
|
|
|
|
'[placeholder]defaultNickname');
|
|
|
|
editableText.setAttribute("data-i18n-options",
|
|
|
|
JSON.stringify({name: "Jane Pink"}));
|
|
|
|
editableText.setAttribute("placeholder", defaultNickname);
|
|
|
|
|
|
|
|
this.container.appendChild(editableText);
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
$('#localVideoContainer .displayname')
|
|
|
|
.bind("click", function (e) {
|
|
|
|
|
2015-07-28 21:52:32 +00:00
|
|
|
var editDisplayName = $('#editDisplayName');
|
2015-06-23 08:00:46 +00:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
$('#localDisplayName').hide();
|
2015-07-28 21:52:32 +00:00
|
|
|
editDisplayName.show();
|
|
|
|
editDisplayName.focus();
|
|
|
|
editDisplayName.select();
|
2015-06-23 08:00:46 +00:00
|
|
|
|
2015-07-28 21:52:32 +00:00
|
|
|
editDisplayName.one("focusout", function (e) {
|
2015-06-23 08:00:46 +00:00
|
|
|
self.VideoLayout.inputDisplayNameHandler(this.value);
|
|
|
|
});
|
|
|
|
|
2015-07-28 21:52:32 +00:00
|
|
|
editDisplayName.on('keydown', function (e) {
|
2015-06-23 08:00:46 +00:00
|
|
|
if (e.keyCode === 13) {
|
|
|
|
e.preventDefault();
|
|
|
|
self.VideoLayout.inputDisplayNameHandler(this.value);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2015-07-28 21:52:32 +00:00
|
|
|
};
|
2015-06-23 08:00:46 +00:00
|
|
|
|
|
|
|
LocalVideo.prototype.inputDisplayNameHandler = function (name) {
|
|
|
|
NicknameHandler.setNickname(name);
|
|
|
|
|
2015-07-28 21:52:32 +00:00
|
|
|
var localDisplayName = $('#localDisplayName');
|
|
|
|
if (!localDisplayName.is(":visible")) {
|
|
|
|
if (NicknameHandler.getNickname()) {
|
2015-07-03 09:34:05 +00:00
|
|
|
var meHTML = APP.translation.generateTranslationHTML("me");
|
2015-07-28 21:52:32 +00:00
|
|
|
localDisplayName.html(NicknameHandler.getNickname() + " (" +
|
|
|
|
meHTML + ")");
|
|
|
|
} else {
|
2015-07-03 09:34:05 +00:00
|
|
|
var defaultHTML = APP.translation.generateTranslationHTML(
|
2015-06-23 08:00:46 +00:00
|
|
|
interfaceConfig.DEFAULT_LOCAL_DISPLAY_NAME);
|
2015-07-28 21:52:32 +00:00
|
|
|
localDisplayName .html(defaultHTML);
|
2015-06-23 08:00:46 +00:00
|
|
|
}
|
2015-07-28 21:52:32 +00:00
|
|
|
localDisplayName.show();
|
2015-06-23 08:00:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$('#editDisplayName').hide();
|
2015-07-28 21:52:32 +00:00
|
|
|
};
|
2015-06-23 08:00:46 +00:00
|
|
|
|
2015-07-28 21:52:32 +00:00
|
|
|
LocalVideo.prototype.createConnectionIndicator = function() {
|
2015-06-23 08:00:46 +00:00
|
|
|
if(this.connectionIndicator)
|
|
|
|
return;
|
|
|
|
|
2015-07-28 21:52:32 +00:00
|
|
|
this.connectionIndicator = new ConnectionIndicator(this, null);
|
|
|
|
};
|
2015-06-23 08:00:46 +00:00
|
|
|
|
|
|
|
LocalVideo.prototype.changeVideo = function (stream, isMuted) {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
function localVideoClick(event) {
|
2015-07-10 09:57:20 +00:00
|
|
|
// FIXME: with Temasys plugin event arg is not an event, but
|
|
|
|
// the clicked object itself, so we have to skip this call
|
|
|
|
if (event.stopPropagation) {
|
|
|
|
event.stopPropagation();
|
|
|
|
}
|
2015-06-23 08:00:46 +00:00
|
|
|
self.VideoLayout.handleVideoThumbClicked(
|
2015-08-24 09:37:23 +00:00
|
|
|
true,
|
2015-06-23 08:00:46 +00:00
|
|
|
APP.xmpp.myResource());
|
|
|
|
}
|
|
|
|
|
2015-07-28 21:52:32 +00:00
|
|
|
var localVideoContainerSelector = $('#localVideoContainer');
|
|
|
|
localVideoContainerSelector.off('click');
|
|
|
|
localVideoContainerSelector.on('click', localVideoClick);
|
2015-06-23 08:00:46 +00:00
|
|
|
|
2015-07-28 21:52:32 +00:00
|
|
|
if(isMuted) {
|
2015-06-23 08:00:46 +00:00
|
|
|
APP.UI.setVideoMute(true);
|
|
|
|
return;
|
|
|
|
}
|
2015-07-28 21:52:32 +00:00
|
|
|
this.flipX = stream.videoType != "screen";
|
2015-06-23 08:00:46 +00:00
|
|
|
var localVideo = document.createElement('video');
|
|
|
|
localVideo.id = 'localVideo_' +
|
|
|
|
APP.RTC.getStreamID(stream.getOriginalStream());
|
2015-07-10 09:57:20 +00:00
|
|
|
if (!RTCBrowserType.isIExplorer()) {
|
|
|
|
localVideo.autoplay = true;
|
|
|
|
localVideo.volume = 0; // is it required if audio is separated ?
|
|
|
|
}
|
2015-06-23 08:00:46 +00:00
|
|
|
localVideo.oncontextmenu = function () { return false; };
|
|
|
|
|
|
|
|
var localVideoContainer = document.getElementById('localVideoWrapper');
|
2015-08-12 10:13:30 +00:00
|
|
|
// Put the new video always in front
|
|
|
|
UIUtil.prependChild(localVideoContainer, localVideo);
|
2015-06-23 08:00:46 +00:00
|
|
|
|
|
|
|
var localVideoSelector = $('#' + localVideo.id);
|
|
|
|
|
|
|
|
// Add click handler to both video and video wrapper elements in case
|
|
|
|
// there's no video.
|
2015-07-10 09:57:20 +00:00
|
|
|
|
|
|
|
// onclick has to be used with Temasys plugin
|
|
|
|
localVideo.onclick = localVideoClick;
|
2015-06-23 08:00:46 +00:00
|
|
|
|
|
|
|
if (this.flipX) {
|
|
|
|
localVideoSelector.addClass("flipVideoX");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Attach WebRTC stream
|
|
|
|
APP.RTC.attachMediaStream(localVideoSelector, stream.getOriginalStream());
|
|
|
|
|
|
|
|
// Add stream ended handler
|
|
|
|
stream.getOriginalStream().onended = function () {
|
2015-07-10 09:57:20 +00:00
|
|
|
// We have to re-select after attach when Temasys plugin is used,
|
|
|
|
// because <video> element is replaced with <object>
|
|
|
|
localVideo = $('#' + localVideo.id)[0];
|
2015-06-23 08:00:46 +00:00
|
|
|
localVideoContainer.removeChild(localVideo);
|
2015-06-29 14:24:21 +00:00
|
|
|
self.VideoLayout.updateRemovedVideo(APP.xmpp.myResource());
|
2015-06-23 08:00:46 +00:00
|
|
|
};
|
2015-07-20 17:32:04 +00:00
|
|
|
};
|
2015-06-23 08:00:46 +00:00
|
|
|
|
|
|
|
LocalVideo.prototype.joined = function (jid) {
|
|
|
|
this.peerJid = jid;
|
2015-07-20 17:32:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
LocalVideo.prototype.getResourceJid = function () {
|
|
|
|
var myResource = APP.xmpp.myResource();
|
|
|
|
if (!myResource) {
|
|
|
|
console.error("Requested local resource before we're in the MUC");
|
|
|
|
}
|
|
|
|
return myResource;
|
|
|
|
};
|
2015-06-23 08:00:46 +00:00
|
|
|
|
|
|
|
module.exports = LocalVideo;
|