| | |
| | | this.ua.start(); |
| | | |
| | | // 事件监听 |
| | | // 事件监听 |
| | | this.ua.on("registered", () => { |
| | | this.isRegistered = true; |
| | | this.registrationTime = Date.now(); // 记录注册成功时间 |
| | | console.log(this.registrationTime, "注册时间"); |
| | | |
| | | this.updateStatus("registered", "已注册"); |
| | | }); |
| | | |
| | |
| | | |
| | | this.ua.on("unregistered", () => { |
| | | this.isRegistered = false; |
| | | let registrationTime = Date.now(); // 记录注销成功时间 |
| | | console.log(registrationTime, "注销时间"); |
| | | this.updateStatus("disconnected", "已注销"); |
| | | }); |
| | | this.ua.on("disconnected", () => |
| | |
| | | throw error; |
| | | } |
| | | } |
| | | // 新增方法:检查是否可以呼叫 |
| | | // 新增方法:检查是否可以呼叫 |
| | | canMakeCall(minDelay = 2000) { |
| | | if (!this.isRegistered) { |
| | | return { canCall: false, reason: "SIP未注册,无法呼叫" }; |
| | |
| | | const remaining = minDelay - timeSinceRegistration; |
| | | return { |
| | | canCall: false, |
| | | reason: `注册成功,请等待 ${Math.ceil(remaining / 1000)} 秒后再呼叫` |
| | | reason: `注册成功,请等待 ${Math.ceil(remaining / 1000)} 秒后再呼叫`, |
| | | }; |
| | | } |
| | | |
| | |
| | | }; |
| | | |
| | | this.currentSession = this.ua.call( |
| | | `sip:${targetNumber}@192.169.129.198`, |
| | | `sip:${targetNumber}@1192.170.66.107`, |
| | | options |
| | | ); |
| | | |
| | |
| | | errorMessage = "会话参数不满足服务器要求"; |
| | | break; |
| | | default: |
| | | errorMessage = `呼叫失败: ${e.cause || e.message}`; |
| | | errorMessage = `呼叫失败3: ${e.cause || e.message}`; |
| | | } |
| | | |
| | | this.updateCallStatus("failed55", errorMessage); |