Created
February 12, 2024 20:30
-
-
Save leonetosoft/2fa75e698fc94e2fba9e384ed059de30 to your computer and use it in GitHub Desktop.
Aproach 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Inclua a biblioteca JsSIP no seu projeto --> | |
<script src="https://cdn.jsdelivr.net/npm/jssip/dist/jssip.min.js"></script> | |
<script> | |
JsSIP.debug.enable('JsSIP:*'); | |
// Substitua 'seu-endereco-ws' e 'sua-porta-ws' pelos detalhes do seu servidor WebSocket | |
const socket = new JsSIP.WebSocketInterface('ws://192.168.73.142:8088/ws/'); | |
// Configurações do usuário SIP | |
const config = { | |
sockets: [socket], | |
uri: 'sip:[email protected]', | |
authorizationUser: '1003', | |
password: '****##', | |
register : false, | |
traceSip: true, | |
log: { | |
level : 0, | |
} | |
}; | |
// Crie a instância do usuário SIP | |
const userAgent = new JsSIP.UA(config); | |
// Eventos SIP | |
userAgent.on('connected', () => { | |
console.log('Conectado ao servidor SIP.'); | |
}); | |
userAgent.on('disconnected', () => { | |
console.log('Desconectado do servidor SIP.'); | |
}); | |
userAgent.on("registrationFailed", (err) => { | |
console.log("EVENT: registrationFailed",err); | |
}); | |
userAgent.on("message", () => { | |
console.log("EVENT: message"); | |
}); | |
// Exemplo de como fazer uma chamada | |
function fazerChamada(destino) { | |
const options = { | |
mediaConstraints: { audio: true, video: false }, | |
}; | |
const session = userAgent.call(destino, options); | |
// Lógica para lidar com a sessão da chamada | |
} | |
// Exemplo de como responder a uma chamada | |
function atenderChamada(session) { | |
const options = { | |
mediaConstraints: { audio: true, video: false }, | |
}; | |
session.answer(options); | |
// Lógica para lidar com a chamada atendida | |
} | |
// Exemplo de como encerrar uma chamada | |
function encerrarChamada(session) { | |
session.terminate(); | |
// Lógica para lidar com a chamada encerrada | |
} | |
console.log("teste") | |
userAgent.start(); | |
userAgent.register(); | |
userAgent.on("message", onMessage); | |
function onMessage(message) { | |
alert(message.body); | |
} | |
setTimeout(() => { | |
fazerChamada("sip:[email protected]")}, 10000) | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment