@ -63,14 +63,14 @@ const KeypadSimplesIP = (function () {
//RECEBENDO CHAMADA
let otherNumber = "Indefinido" ;
UASimplesIP . simplesipEvento . on ( "incomingcall" , function ( callerNumber ) {
if ( otherNumber === "Indefinido" ) {
if ( otherNumber ) {
otherNumber = callerNumber ;
}
stateCurrent . setStateCall ( "incomingcall" ) ;
} ) ;
//FAZENDO CHAMADA
UASimplesIP . simplesipEvento . on ( "outgoingcall" , function ( callerNumber ) {
if ( otherNumber === "Indefinido" ) {
if ( otherNumber ) {
otherNumber = callerNumber ;
}
stateCurrent . setStateCall ( "outgoingcall" ) ;
@ -83,6 +83,9 @@ const KeypadSimplesIP = (function () {
UASimplesIP . simplesipEvento . on ( "confirmedEnded" , function ( ) {
stateCurrent . setStateCall ( "home" ) ;
} ) ;
UASimplesIP . simplesipEvento . on ( "home" , function ( ) {
stateCurrent . setStateCall ( "home" ) ;
} ) ;
//==================================================================
const simplesipCreateContainer = ( themeMode ) => {
@ -376,26 +379,63 @@ const KeypadSimplesIP = (function () {
simplesipInCall . classList . add ( "simplesipInCall" ) ;
simplesipInCall . classList . add ( themeMode ) ;
simplesipInCall . id = "simplesipInCall" ;
simplesipCreateDisplay ( container , themeMode ) ;
simplesipCreateTimer ( simplesipInCall ) ;
//Adiciona o numero que ligou ao display
const display = document . getElementById ( "display" ) ;
display . style . marginTop = 30 + "px" ;
const bnEndCall = createButtonEndCall ( handleEndCall ) ;
const bnMute = createButtonMute ( handleMute ) ;
const bnKeypad = createButtonKeypad ( handleKeypad ) ;
const bnTransfer = createButtonTransfer ( handleTransfer ) ;
const keyPadIncall = createKeypadIncall ( ) ;
//Configura outro display pra mostrar com quem está falando
const displayOtherNumber = document . createElement ( "div" ) ;
const userIcon = document . createElement ( "img" ) ;
userIcon . src = userImg ;
userIcon . width = 20 ;
userIcon . height = 20 ;
displayOtherNumber . appendChild ( userIcon ) ;
displayOtherNumber . classList . add ( "displayOtherNumber" ) ;
displayOtherNumber . id = "displayOtherNumber" ;
displayOtherNumber . appendChild ( userIcon ) ;
const otherNumberText = document . createElement ( "span" ) ;
otherNumberText . textContent = otherNumber ;
displayOtherNumber . appendChild ( otherNumberText ) ;
//Cria display que mostra todas as opções da chamada
const displayInCall = document . createElement ( "div" ) ;
displayInCall . classList . add ( "displayInCall" ) ;
displayInCall . id = "displayInCall" ;
display . textContent = otherNumber ;
displayInCall . appendChild ( bnMute ) ;
displayInCall . appendChild ( bnKeypad ) ;
displayInCall . appendChild ( bnTransfer ) ;
displayInCall . appendChild ( bnEndCall ) ;
simplesipCreateDisplayContainer ( container , themeMode ) ;
const display = document . getElementById ( "displayContainer" ) ;
simplesipInCall . appendChild ( displayOtherNumber ) ;
simplesipCreateTimer ( simplesipInCall ) ;
simplesipInCall . appendChild ( keyPadIncall ) ;
simplesipInCall . appendChild ( displayInCall ) ;
container . appendChild ( simplesipInCall ) ;
//classe adicionada para adaptar o display durante a ligação
display . classList . add ( "incallDisplay" ) ;
} ;
const createKeypadIncall = ( ) => {
const keyPadIncall = document . createElement ( "div" ) ;
keyPadIncall . classList . add ( "keyPadIncall" ) ;
keyPadIncall . id = "keyPadIncall" ;
simplesipButtons . forEach ( ( element ) => {
const simplesipButton = document . createElement ( "button" ) ;
simplesipButton . textContent = element ;
simplesipButton . classList . add ( "simplesip-bn" ) ;
simplesipButton . addEventListener ( "click" , ( ) => handleClick ( element ) ) ;
keyPadIncall . appendChild ( simplesipButton ) ;
} ) ;
return keyPadIncall ;
} ;
const createButtonKeypad = ( event ) => {
@ -564,8 +604,18 @@ const KeypadSimplesIP = (function () {
stateCurrent . setStateCall ( "home" ) ;
}
let keypadVisible = false ;
function handleKeypad ( ) {
UASimplesIP . simplesipEvento . emit ( "" ) ;
if ( keypadVisible ) {
document . getElementById ( "keyPadIncall" ) . style . visibility = "hidden" ;
keypadVisible = false ;
document . removeEventListener ( "keydown" , handleKeyPress ) ;
} else {
document . getElementById ( "keyPadIncall" ) . style . visibility = "visible" ;
keypadVisible = true ;
document . addEventListener ( "keydown" , handleKeyPress ) ;
}
}
function handleTransfer ( ) {
@ -634,6 +684,9 @@ const KeypadSimplesIP = (function () {
if ( display . innerText . length <= maxLength ) {
display . append ( buttonValue ) ;
if ( stateCurrent . getStateCall ( ) === "incall" ) {
UASimplesIP . simplesipEvento . emit ( "sendDTMF" , buttonValue ) ;
}
}
//chama funcao para verificar se tem texto e exibir botao clear
haveTextAndClearDisplay ( display ) ;
@ -987,12 +1040,15 @@ const KeypadSimplesIP = (function () {
const keyPress = event . key ;
if ( /[0-9 * #]/ . test ( keyPress ) ) {
if ( display . innerText . length <= maxLength ) {
if ( stateCurrent . getStateCall ( ) === "incall" ) {
UASimplesIP . simplesipEvento . emit ( "sendDTMF" , keyPress ) ;
}
display . append ( keyPress ) ;
}
//chama funcao para verificar se tem texto e exibir botao clear
} else if ( keyPress === "Backspace" ) {
clearDisplay ( ) ;
} else if ( keyPress === "Enter" ) {
} else if ( keyPress === "Enter" && stateCurrent . getStateCall ( ) === "home" ) {
handleCall ( ) ;
}
haveTextAndClearDisplay ( display ) ;
@ -1008,6 +1064,9 @@ const KeypadSimplesIP = (function () {
configuration . SENHA = localStorage . getItem ( "senha" ) || "" ;
} ;
const userImg =
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAYAAAA7MK6iAAAACXBIWXMAAAsTAAALEwEAmpwYAAABKklEQVR4nO2UMU7DQBBFLQpSQgmihivASRCHIFzBHTQIxDV8gLX+W8N2ECpHHAAaBFQgFBTKoCUOogjyGjYJoHzpN/ZKb//M7CTJXL9RxpiWpD2gA7xU7lhr2/7fRKBFUawBXWDwhUt/JirUGNOqgX7AoybXsLyDQO9GAwOXoWBJF9HAknoNwL1oYMLL/O6ZJAae/36PrbXtmUy1Gb7jMuQdZ1m2mExgc5VT3Vwj+TS+lL6PfuAqn/tv0ZPONVWlaboAbEk6AM4k3Ut69QbugFNgX9KmP/tjYJ7nq8CRpIcGC8Rf6tA5t9IY6JxbBk4k9Zvu6U8X6Es6ttYuBUGttRvAzXeBY3wNrNeCJV1FhI7crQVXwxIVLOk2JPGOpKeI4EdgO6jPc/0rvQHiiVTDrTdPvAAAAABJRU5ErkJggg==" ;
const transferImg =
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAYAAAA7MK6iAAAACXBIWXMAAAsTAAALEwEAmpwYAAABEElEQVR4nO3WPYrCQBjG8T/CVvb2VnsAC0EvYL1WewPFM4i1HkCUxYOslR+FYMQP7LyAaKWVH81KIMVgnPD6TiRb+MA0IT8eZnhJBt5JOCmgBqyAM7ADusDHq30P+HuwcsJilS9b0AVIC0rVfmGBQ+FuVT5rQf6qC0rVvhoBi4JitW9b0F440WrfvwMjoAF8Ckqd/MZATWFZLH5rwO+I9/ydzICM0odyNGAJe6bBO+u7cqkP5WrAvPF8HDGtnsD/3+KD8Kg8y1FLfSjS4ZjEPVwbA7aega7+1/EDovbtpD6ZlYjpLQiK1T6b1G/Rz9wCB8ii9l+OVx8n/+N42VP7VDAoS+AUXE87T15vXfw7xJYbEKIIsmQ9hbAAAAAASUVORK5CYII=" ;