Browse Source

inserido funcionalidades dos botoes mute e unmute, inserido tambem nos displays o numero com quem esta conversando e outros tratamento de fluxo de uma ligacao

master
Matheo Bonucia 6 months ago
parent
commit
3532320c7f
  1. 33
      keypad.js
  2. 8
      keypad_style.css
  3. 65
      simplesipsdk.js

33
keypad.js

File diff suppressed because one or more lines are too long

8
keypad_style.css

@ -43,7 +43,7 @@
justify-content: center;
flex-direction: column;
align-items: center;
background-color: transparent;
background-color: white;
transition: height 0.5s ease-in-out; /* Adicione uma transição suave para a opacidade */
pointer-events: auto; /* Mantém os eventos de mouse ativos quando visível */
}
@ -56,7 +56,7 @@
font-size: 14px;
max-height: 30px;
padding: 2px 4px;
background-color: rgba(195, 195, 195, 0.056);
background-color: white;
border-radius: 8px 8px 0 0;
cursor: pointer;
}
@ -221,7 +221,7 @@
border: none;
text-align: center;
line-height: 8px;
background-color: transparent;
background-color: white;
}
.bn-minimize img {
@ -276,7 +276,7 @@
min-height: 40px;
font-size: 30px;
width: 100%;
background-color: transparent;
background-color: white;
display: flex;
flex-direction: row;
justify-content: center;

65
simplesipsdk.js

@ -36,20 +36,6 @@ const UASimplesIP = (function () {
}
});
function extrairNome(displayName) {
// Expressão regular para extrair o nome entre aspas
const regex = /"([^"]+)"/;
// Executa a expressão regular na string de displayName
const match = regex.exec(displayName);
// Se houver correspondência, retorna o primeiro grupo capturado (o nome)
if (match && match.length > 1) {
return match[1];
} else {
// Se não houver correspondência, retorna null ou uma string vazia, dependendo do seu caso
return null;
}
}
class EventEmitter {
constructor() {
this.events = {};
@ -97,6 +83,8 @@ const UASimplesIP = (function () {
}
const _Autenticacao = new Autenticacao();
var localAudio = new window.Audio();
localAudio.autoplay = true;
const incomingCallAudio = new window.Audio(
"https://cdn.pixabay.com/download/audio/2021/08/04/audio_bb630cc098.mp3?filename=short-success-sound-glockenspiel-treasure-video-game-6346.mp3"
@ -142,9 +130,7 @@ const UASimplesIP = (function () {
eventoSip.on("endCall", () => {
if (session && session.isEstablished()) {
eventoSip.emit("confirmedEnded");
console.log(
":::::::::::::::::::::::evento emitido::::::::::::::::::::::"
);
console.log();
session.terminate();
}
});
@ -152,16 +138,12 @@ const UASimplesIP = (function () {
eventoSip.on("evento", (payload) => {
console.log(payload);
});
eventoSip.on("mute", function () {
console.log("MUTADO:::::::::::::::");
session.mute();
});
eventoSip.on("unmute", function () {
if (session && session.isEstablished() && session.isMuted()) {
session.unmute();
}
session.unmute();
});
session.on("failed", () => {});
@ -170,11 +152,26 @@ const UASimplesIP = (function () {
});
session.on("confirmed", function (confirmed) {
// Verifica se session.connection está definido
if (
session.connection &&
session.connection.getRemoteStreams().length > 0
) {
const remoteStreams = session.connection.getRemoteStreams()[0];
remoteAudio.srcObject = remoteStreams;
}
// Verifica se session.connection está definido e se existem streams locais
if (
session.connection &&
session.connection.getLocalStreams().length > 0
) {
const localStreams = session.connection.getLocalStreams()[0];
localAudio.srcObject = localStreams;
}
eventoSip.emit("incall");
const remoteStreams = session.connection.getRemoteStreams()[0];
remoteAudio.srcObject = remoteStreams;
});
session.on("icecandidate", function (event) {
if (
event.candidate.type === "srflx" &&
@ -184,16 +181,19 @@ const UASimplesIP = (function () {
event.ready();
}
});
session.on("addstream", function (e) {
remoteAudio.src = window.URL.createObjectURL(e.stream);
// Verifica se session.connection está definido
if (session.connection) {
remoteAudio.src = window.URL.createObjectURL(e.stream);
}
});
//RECEBENDO UMA CHAMADA
if (session.direction === "incoming") {
incomingCallAudio.play();
console.log("::::::::::::::::::::::chamada recebida");
isIncomingCall = true;
eventoSip.emit("incomingcall", extrairNome(session.remote_identity));
eventoSip.emit("incomingcall", session.remote_identity.uri.user);
eventoSip.on("rejected", () => {
if (session && session.isInProgress()) {
@ -215,15 +215,8 @@ const UASimplesIP = (function () {
}
//REALIZANDO UMA CHAMADA
if (session.direction === "outgoing") {
console.log("::::::::::::::::::::::chamada realizada");
eventoSip.emit("outgoingcall");
eventoSip.emit("outgoingcall", session.remote_identity.uri.user);
}
// //CHAMADA EM ANDAMENTO
// if (session.direction === "progress") {
// incomingCallAudio.pause();
// eventoSip.emit("incall");
// console.log("::::::::::::::::::::::chamada em progresso");
// }
});
phone.start();
}

Loading…
Cancel
Save