Estou tentando implementar sip.js em meu repositório vue.js.
`
import sipModal from './sipModal.vue'
export default {
template: '#sipDialler',
name: 'sip-dialler',
data () {
return {
session: '',
ua: '',
hangupType: 'NOCALL',
inputNumber: '',
onCall: false,
callIncoming: false,
audioConstraints: {
audio: true,
video: false
},
mediaStream: ''
}
},
computed: {
media () {
const audio = document.getElementById('remoteAudio')
const audio2 = document.getElementById('localAudio')
return {
stream: this.audioConstraints,
render: {
remote: audio,
local: audio2
}
}
}
},
components: {
'sip-modal': sipModal
},
created () {
this.registerUserAgent()
},
methods: {
registerUserAgent () {
// eslint-disable-next-line
this.ua = new SIP.UA({
uri: '******.callwise.net',
wsServers: 'wss://sip.callwise.net:443',
traceSip: true,
authorizationUser: '******',
password: '********'
})
this.onRegistered()
this.onUnregistered()
this.onInvite()
},
onRegistered () {
this.ua.on('registered', function () {
// eslint-disable-next-line
SIP.WebRTC.isSupported()
// eslint-disable-next-line
SIP.WebRTC.getUserMedia(this.audioConstraints, function (stream) {
console.log(stream)
this.mediaStream = stream
}, function (e) {
console.error(e)
})
})
},
onUnregistered () {
this.ua.on('unregistered', function () {
console.log('unregistered')
})
},
onInvite () {
this.ua.on('invite', function (incoming) {
console.log('receiving call')
this.session = incoming
this.callIncoming = true
})
},
onFailed () {
this.session.on('failed', function (response, cause) {
this.callIncoming = false
})
},
makeCall () {
this.session = this.ua.invite('sip:' + this.inputNumber + '********.callwise.net', this.media)
},
answerCall () {
this.session.accept(this.media)
this.callIncoming = false
},
rejectCall () {
this.session.reject({statusCode: '486', reasonPhrase: 'Busy Here'})
},
deleteInput () {
this.inputNumber = this.inputNumber.slice(0, -1)
},
addHash () {
this.inputNumber += '#'
},
addAsterisk () {
this.inputNumber += '*'
}
}
}
`
When using that code I get ---> TypeError: Failed to execute 'getUserMedia' on 'Navigator': At least one of audio and video must be requested
at sip-0.7.5.js:10447
at Promise (
at Object.promisifiedMethod [as getUserMedia] (sip-0.7.5.js:10442)
at UA.eval (eval at 186 (0.9df3722….hot-update.js:7),
at UA.EventEmitter.emit (sip-0.7.5.js:112)
at RegisterContext.EventEmitter.emit (sip-0.7.5.js:112)
at RegisterContext.receiveResponse (sip-0.7.5.js:3477)
at RequestSender.receiveResponse (sip-0.7.5.js:3758)
at NonInviteClientTransaction.receiveResponse (sip-0.7.5.js:7615)
at Transport.onMessage (sip-0.7.5.js:8526)
(anonymous) @ sipDialler.vue?36c1:114
If I remove the bit:
SIP.WebRTC.getUserMedia(this.audioConstraints, function (stream) {
console.log(stream)
this.mediaStream = stream
}, function (e) {
console.error(e)
})
})
I don't get any errors and I'm able to make calls, the person I'm calling to can hear me on the mobile-phone but I'm not ables to hear the person I'm calling on my speakers.
Any ideas why is that happening?
Você não deve precisar ligar para getUserMedia
você mesmo. O manipulador de mídia padrão fará isso por você.
Ei Eric, obrigado pela sua resposta. Como eu disse em meu primeiro problema, quando removo a linha de código:
SIP.WebRTC.getUserMedia(this.audioConstraints, function (stream) { console.log(stream) this.mediaStream = stream }, function (e) { console.error(e) }) })
O erro para de aparecer e consigo fazer chamadas do meu site. No entanto, a pessoa para quem estou ligando pode me ouvir de seu celular, mas não consigo ouvir a pessoa para quem estou ligando nos alto-falantes do computador. Isso significa que o aplicativo acessa meu microfone, mas não meus alto-falantes. Alguma ideia de por que isso acontece?
Obrigado.
Em primeiro lugar, você pode confirmar se o áudio remoto está sendo anexado ao elemento de áudio no DOM? Confirme também se ele é reproduzido e não pausado.
Se for esse o caso, eu faria o SIP.js funcionar fora do vue.js primeiro. Em seguida, integre-o ao vue. Não há realmente nada em vue que deva afetar o SIP.js afaik.
Obrigado Eric, finalmente fiz funcionar, mudei meu método computado de
calculado: {
media () {
const audio = document.getElementById('remoteAudio')
const audio2 = document.getElementById('localAudio')
return {
stream: this.audioConstraints,
render: {
remote: audio,
local: audio2
}
}
}
},
Para:
options () {
const audio = document.getElementById('remoteAudio')
const audio2 = document.getElementById('localAudio')
return {
media: {
constraints: {
audio: true,
video: false
},
render: {
remote: audio,
local: audio2
}
}
}
},
E chamar this.options em vez de this.media e parece funcionar.
Muito obrigado pela ajuda, encerro o problema.
@ Juli0GT
Oi,
Você poderia compartilhar o resto do exemplo de seu código de trabalho?
Estou lutando para fazer funcionar também e você poderia me ajudar muito.
Obrigado
Comentários muito úteis
@ Juli0GT
Oi,
Você poderia compartilhar o resto do exemplo de seu código de trabalho?
Estou lutando para fazer funcionar também e você poderia me ajudar muito.
Obrigado