Browse Source

inserido ouvintes para eventos, eventos personalizados para melhorar a UX do usuario, transmissao de voz funcionando parcialmente

master
Matheo Bonucia 6 months ago
parent
commit
d2909d7fb9
  1. 18
      keypad.js
  2. 60
      simplesipsdk.js

18
keypad.js

@ -57,11 +57,21 @@ const KeypadSimplesIP = (function () {
});
//==================================================================
//RECEBENDO CHAMADA
let incommingNumber = "Indefinido";
UASimplesIP.simplesipEvento.on("incomingcall", function (callerNumber) {
incommingNumber = callerNumber;
stateCurrent.setStateCall("incomingcall");
});
UASimplesIP.simplesipEvento.on("outgoingcall", function () {
stateCurrent.setStateCall("outgoingcall");
});
UASimplesIP.simplesipEvento.on("incall", function () {
stateCurrent.setStateCall("incall");
});
const simplesipCreateContainer = () => {
let simplesipContainer = document.querySelector(".simplesipContainer");
@ -245,25 +255,23 @@ const KeypadSimplesIP = (function () {
if (numberCall) {
storedNumberCall = numberCall;
}
stateCurrent.setStateCall("outgoingcall");
UASimplesIP.realizaUmaChamada(numberCall);
};
function handleEndCall() {
UASimplesIP.encerraChamada();
UASimplesIP.simplesipEvento.emit("ended");
restartTimer();
storedNumberCall = "";
stateCurrent.setStateCall("home");
}
function handleAcceptCall() {
UASimplesIP.aceitarChamada();
UASimplesIP.simplesipEvento.emit("accepted");
startTimer();
stateCurrent.setStateCall("incall");
}
function handleRejectCall() {
UASimplesIP.rejeitarChamada();
UASimplesIP.simplesipEvento.emit("rejected");
stateCurrent.setStateCall("home");
restartTimer();
}

60
simplesipsdk.js

@ -151,19 +151,20 @@ const UASimplesIP = (function () {
session = null;
isIncomingCall = false;
};
session.on("ended", completeSession);
session.on("failed", completeSession);
session.on("accepted", (accepted) => {
console.log(accepted);
eventoSip.on("failed", completeSession);
eventoSip.on("ended", () => {
if (session) {
session.terminate();
}
});
session.on("confirmed", function (confirmed) {
console.log(
"confirmed ::::::::::::::::::::::::::::::::::::::::::::::::::::",
confirmed
);
eventoSip.emit("incall");
const remoteStreams = session.connection.getRemoteStreams()[0];
remoteAudio.srcObject = remoteStreams;
});
session.on("icecandidate", function (event) {
if (
event.candidate.type === "srflx" &&
@ -174,23 +175,38 @@ const UASimplesIP = (function () {
}
});
session.on("addstream", function (e) {
incomingCallAudio.pause();
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.on("rejected", () => {
incomingCallAudio.pause();
if (session) {
session.terminate();
}
});
eventoSip.on("accepted", () => {
session.answer();
incomingCallAudio.pause();
});
}
//REALIZANDO UMA CHAMADA
if (session.direction === "outgoing") {
console.log("::::::::::::::::::::::chamada realizada");
eventoSip.emit("outgoingcall");
}
if (session.direction === "progress") {
eventoSip.emit("incall");
console.log("::::::::::::::::::::::chamada em progresso");
}
// //CHAMADA EM ANDAMENTO
// if (session.direction === "progress") {
// incomingCallAudio.pause();
// eventoSip.emit("incall");
// console.log("::::::::::::::::::::::chamada em progresso");
// }
});
phone.start();
}
@ -229,24 +245,6 @@ const UASimplesIP = (function () {
ativaDebug(value);
},
encerraChamada: () => {
if (session) {
session.terminate();
}
},
aceitarChamada: () => {
if (session) {
session.accept();
}
},
rejeitarChamada: () => {
if (session) {
session.reject();
}
},
estouRegistradonoPBX: () => {
console.log("estouRegistradonoPBX ::: " + phone.isRegistered());
},

Loading…
Cancel
Save