创建的事sip.js 版本0.21.2 呼叫成功后听不到对方声音,对方可以听到我的声音 本人小白刚接触这些,希望大佬能够提个处理方向
<script setup>
import { reactive } from 'vue'
import { UserAgent, Inviter, SessionState } from 'sip.js'
const transportOptions = {
server: "ws://192.168.0.9:5066",
traceSip: true,
keepAliveInterval: 600// SIP Websocket 服务器的 Websocket URL
}
const uri = UserAgent.makeURI("sip:1002@192.168.0.9:5060")
const userAgentOptions = {
authorizationPassword: '123456', // 分机密码
authorizationUsername: '1002', // 分机号
transportOptions,
uri,
}
let inviter = reactive()
const but1 = () => {
registerer.register() // 注册,向服务器进行身份验证并接收消息
// userAgent defined elsewhere
userAgent.start().then(() => {
const target = UserAgent.makeURI("sip:1001@192.168.0.9:5060")
inviter = new Inviter(userAgent, target, {
sessionDescriptionHandlerOptions: {
constraints: { audio: true, video: false }
}
})
inviter.invite();
inviter.stateChange.addListener((state) => {
switch (state) {
case SessionState.Initial: console.log(' 初始状态') // 最初
break;
case SessionState.Establishing:
let remoteVideo = document.getElementById('remoteVideo');
let localVideo = document.getElementById('localVideo');
var pc = inviter.sessionDescriptionHandler.peerConnection;
var remoteStream;
console.log(pc);
console.log('成功=======================================');
if (pc.getReceivers) {
remoteStream = new window.MediaStream();
pc.getReceivers().forEach((receiver) => {
// console.log(receiver)
var track = receiver.track;
console.log(track);
if (track & track.kind === "video") {
remoteStream.addTrack(track);
}
});
} else {
remoteStream = pc.getRemoteStreams()[0];
}
remoteVideo.srcObject = remoteStream;
console.log(remoteVideo.srcObject);
console.log("1-------------------------------------------");
var localStream_1;
if (pc.getSenders) {
localStream_1 = new window.MediaStream();
pc.getSenders().forEach((sender) => {
var track = sender.track;
console.log(track);
if (track && track.kind === "video") {
localStream_1.addTrack(track);
}
});
} else {
localStream_1 = pc.getLocalStreams()[0];
}
localVideo.srcObject = localStream_1;
console.log(localVideo.srcObject);
break;
case SessionState.Established: console.log('呼叫已建立') // 确立
break;
case SessionState.Terminating: console.log('正在结束呼叫') // 终止
case SessionState.Terminated: console.log('呼叫已结束') // 结束
break;
default:
throw console.log(`Unknown session state.`)
}
})
})
}
const but11 = () => {
let sessionall = inviter
if (!sessionall) {
} else if (sessionall.startTime) { // Connected
sessionall.bye();
} else if (sessionall.reject) { // Incoming
sessionall.reject();
} else if (sessionall.cancel) { // Outbound
sessionall.cancel();
}
}
</script>
相似问题