2019-01-24 13:40:36 +00:00
|
|
|
/**
|
|
|
|
* Single call window management
|
|
|
|
*
|
|
|
|
* @author Pierre HUBERT
|
|
|
|
*/
|
|
|
|
|
|
|
|
ComunicWeb.components.calls.callWindow = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize a call
|
|
|
|
*
|
|
|
|
* @param {Object} info Information about the call to initialize
|
|
|
|
*/
|
|
|
|
initCall: function(info){
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize call object
|
|
|
|
*/
|
|
|
|
var call = {
|
|
|
|
info: info,
|
|
|
|
open: true,
|
2019-01-24 13:50:03 +00:00
|
|
|
window: {},
|
|
|
|
streams: {}
|
2019-01-24 13:40:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//We have to begin to draw conversation UI
|
|
|
|
var callContainer = createElem2({
|
|
|
|
appendTo: byId("callsTarget") ? byId("callsTarget") : byId("wrapper"), //If call target is not found, add call in page wrapper
|
|
|
|
type: "div",
|
|
|
|
class: "call-window"
|
|
|
|
});
|
|
|
|
call.window.container = callContainer;
|
|
|
|
|
|
|
|
|
|
|
|
//Create loading message area
|
|
|
|
call.window.loadingMessageContainer = createElem2({
|
|
|
|
appendTo: callContainer,
|
|
|
|
type: "div",
|
|
|
|
class: "loading-message-container",
|
|
|
|
innerHTML: "<i class='fa fa-clock-o'></i>"
|
|
|
|
});
|
|
|
|
|
2019-01-24 13:50:03 +00:00
|
|
|
call.window.loadingMessageContent = createElem2({
|
2019-01-24 13:40:36 +00:00
|
|
|
appendTo: call.window.loadingMessageContainer,
|
|
|
|
type: "div",
|
|
|
|
class: "message",
|
|
|
|
innerHTML: "Loading..."
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set loading message visiblity
|
|
|
|
*
|
|
|
|
* @param {Boolean} visible TRUE to make it visible / FALSE else
|
|
|
|
*/
|
|
|
|
call.setLoadingMessageVisibility = function(visible){
|
|
|
|
call.window.loadingMessageContainer.style.display = visible ? "flex" : "none";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update call loading message
|
|
|
|
*
|
|
|
|
* @param {String} message The new message to show to the
|
|
|
|
* users
|
|
|
|
*/
|
|
|
|
call.setLoadingMessage = function(message){
|
2019-01-24 13:50:03 +00:00
|
|
|
call.window.loadingMessageContent.innerHTML = message;
|
2019-01-24 13:40:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//Add toolbar
|
|
|
|
call.window.toolbar = createElem2({
|
|
|
|
appendTo: callContainer,
|
|
|
|
type: "div",
|
|
|
|
class: "call-toolbar",
|
|
|
|
innerHTML: "<i class='fa fa-phone'>"
|
|
|
|
});
|
|
|
|
|
|
|
|
//Call title
|
|
|
|
call.window.title = createElem2({
|
|
|
|
appendTo: call.window.toolbar,
|
|
|
|
type: "div",
|
|
|
|
class: "call-title",
|
|
|
|
innerHTML: "Loading..."
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the title of the call
|
|
|
|
*/
|
|
|
|
call.setTitle = function(title){
|
|
|
|
call.window.title.innerHTML = title;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Add close button
|
|
|
|
call.window.closeButton = createElem2({
|
|
|
|
appendTo: call.window.toolbar,
|
|
|
|
type: "button",
|
|
|
|
class: "btn btn-box-tool close-btn",
|
|
|
|
innerHTML: "<i class='fa fa-times'></i>"
|
|
|
|
});
|
|
|
|
|
2019-01-24 13:50:03 +00:00
|
|
|
//Make close button lives
|
|
|
|
call.close = function(){
|
|
|
|
call.open = false;
|
|
|
|
callContainer.remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
call.window.closeButton.addEventListener("click", function(){
|
|
|
|
call.close();
|
|
|
|
});
|
|
|
|
|
2019-01-24 13:40:36 +00:00
|
|
|
|
|
|
|
//Get information about related conversation to get the name of the call
|
2019-01-25 09:13:30 +00:00
|
|
|
ComunicWeb.components.conversations.utils.getNameForID(info.conversation_id, function(name){
|
2019-01-24 13:40:36 +00:00
|
|
|
|
2019-01-25 09:13:30 +00:00
|
|
|
if(!name)
|
2019-01-24 13:40:36 +00:00
|
|
|
return notify("Could not get information about related conversation!", "danger");
|
|
|
|
|
2019-01-25 09:13:30 +00:00
|
|
|
call.setTitle(name);
|
2019-01-24 13:40:36 +00:00
|
|
|
|
2019-01-25 09:13:30 +00:00
|
|
|
});
|
2019-01-24 13:40:36 +00:00
|
|
|
|
|
|
|
//Load user media
|
|
|
|
call.setLoadingMessage("Waiting for your microphone and camera...");
|
2019-01-24 13:50:03 +00:00
|
|
|
|
|
|
|
ComunicWeb.components.calls.userMedia.get().then(function(stream){
|
|
|
|
|
|
|
|
//Mark as connecting
|
|
|
|
call.setLoadingMessage("Connecting...");
|
|
|
|
|
|
|
|
call.streams.local = stream;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}).catch(function(e){
|
|
|
|
console.error("Get user media error: ", e);
|
|
|
|
call.setLoadingMessageVisibility(false);
|
|
|
|
return notify("Could not get your microphone and camera!", "danger");
|
|
|
|
});
|
2019-01-24 13:40:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|