我正在尝试实现 sipjs 会话。
initializeSip() {
const uri = UserAgent.makeURI('sip:[email protected]'); // Replace with your SIP URI
if (!uri) {
throw new Error('Failed to create URI');
}
const userAgentOptions: UserAgentOptions = {
uri,
transportOptions: {
server: 'ws://127.0.0.1:9090',
},
delegate: {
onInvite: (invitation: Invitation) => {
return this.handleIncomingCall(invitation);
},
},
};
this.userAgent = new UserAgent(userAgentOptions);
const registererOptions: RegistererOptions = {
// Customize registererOptions as needed
};
this.registerer = new Registerer(this.userAgent, registererOptions);
this.userAgent.start().then(() => {
this.registerer.register();
})}
这就是在handleIncomingCall函数中定义accept调用的方式
const acceptCall = () => {
const constraints = {
audio: true,
video: false,
};
navigator.mediaDevices
.getUserMedia(constraints)
.then((localStream) => {
// Attach local stream to an audio element if needed
const localAudio = document.getElementById(
'localAudio'
) as HTMLAudioElement;
if (localAudio) {
localAudio.srcObject = localStream;
}
})
.catch((error) => {
console.error('Error getting user media:', error);
});
const peerConnectionConfig = {
iceServers: [
{
urls: ['stun:stun.l.google.com:19302'],
},
],
iceTransportPolicy: 'all',
bundlePolicy: 'balanced' as RTCBundlePolicy,
rtcpMuxPolicy: 'require' as RTCRtcpMuxPolicy,
};
const options = {
sessionDescriptionHandlerOptions: {
constraints,
peerConnectionConfiguration: peerConnectionConfig,
peerConnectionOptions: {
rtcConfiguration: peerConnectionConfig,
iceGatheringTimeout: 5000,
},
},
};
// Accept the call
// Adding the listener for state changes
invitation
.accept(options)
.then(() => {
console.log('Call accepted successfully');
})
.catch((error) => {
console.error('Failed to accept call:', error);
});
};
我配置了描述,并在接受邀请时将其传递给参数。但即使在我通过之后,我仍然出现以下错误。我尝试了很多方法,但似乎没有任何效果。当我通过冰旗时是否有任何错误?
sip.SessionDescriptionHandler | SessionDescriptionHandler.setDescription 失败 - InvalidAccessError:无效描述,级别 0 没有ice-ufrag 属性
打印到控制台收到的“邀请”并检查它是否包含此属性(搜索行“a=ice-ufrag:”)。当线路丢失时 - 检查服务器设置(已启用 ICE)。