From fbb61549bf96e9e0910b676a5524b0760d29c4be Mon Sep 17 00:00:00 2001
From: WXL (wul) <wl_5969728@163.com>
Date: 星期二, 07 四月 2026 15:16:54 +0800
Subject: [PATCH] 测试完成

---
 public/demotel.html |  203 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 203 insertions(+), 0 deletions(-)

diff --git a/public/demotel.html b/public/demotel.html
new file mode 100644
index 0000000..4a748ea
--- /dev/null
+++ b/public/demotel.html
@@ -0,0 +1,203 @@
+锘�<!DOCTYPE html>
+<html>
+<head>
+    <meta charset="utf-8" />
+    <title>SIP鐢佃瘽Demo</title>
+    <meta http-equiv="Pragma" content="no-cache">
+    <meta http-equiv="Expires" content="-1">
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    <meta http-equiv="cache-control" content="no-store">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
+    <script language="javascript" type="text/javascript" src="./jssip-3.10.0.js"></script>
+</head>
+<body style="background-color:darkgray;">
+    
+    
+
+    <table border="1" cellspacing="0" bordercolor="gray" style="width:auto;">
+        <tr>
+            <td style="text-align:center;width:120px;">
+                <span> 鏈嶅姟鍣ㄥ湴鍧�:</span>
+            </td>
+            <td style="text-align: center; width: 250px;">
+                <input id="tbServer" type="text" style="width:200px;text-align:left;" value="192.168.1.96" />
+            </td>
+        </tr>
+        <tr>
+            <td style="text-align:center;width:120px;">
+                <span> 鍒嗘満鍙�:</span>
+            </td>
+            <td style="text-align: center; width: 250px;">
+                <input id="tbExtension" type="text" style="width:200px;text-align:left;" value="8005" />
+            </td>
+        </tr>
+        <tr>
+            <td style="text-align:center;width:120px;">
+                <span> 瀵嗙爜:</span>
+            </td>
+            <td style="text-align: center; width: 250px;">
+                <input id="tbPassword" type="text" style="width:200px;text-align:left;" value="8005" />
+            </td>
+        </tr>
+        <tr>
+            <td style="text-align:center;width:120px;" colspan="2">
+                <button onclick="f_register()">娉ㄥ唽</button>
+            </td>            
+        </tr>
+        <tr>
+            <td style="text-align:center;width:120px;">
+                <span> 鍛煎彨鍙风爜:</span>
+            </td>
+            <td style="text-align: center; width: 250px;">
+                <input id="tbPhoneNo" type="text" style="width:200px;text-align:left;" value="013958077789" />
+            </td>
+        </tr>
+        <tr>
+            <td style="text-align:center;width:120px;" colspan="2">
+                <button onclick="f_makecall()">杞鎷�</button>            
+                <button onclick="f_hangup()">鎸傛柇</button>
+            </td>
+        </tr>
+    </table>
+
+
+    <script type="text/javascript">
+        var cur_session = undefined;
+        var ua = null;
+
+        String.prototype.Right = function (i) {
+            return this.slice(this.length - i, this.length);
+        };
+        Date.prototype.Format = function (fmt) { //author: meizz
+            var o = {
+                "M+": this.getMonth() + 1, //鏈堜唤
+                "d+": this.getDate(), //鏃�
+                "h+": this.getHours(), //灏忔椂
+                "m+": this.getMinutes(), //鍒�
+                "s+": this.getSeconds(), //绉�
+                "q+": Math.floor((this.getMonth() + 3) / 3), //瀛e害
+                "S": ('00' + this.getMilliseconds()).Right(3)    //姣
+            };
+            if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
+            for (var k in o)
+                if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
+            return fmt;
+        };
+
+        function logger_info(message, ...optionalParams) {
+            console.log("[" + new Date().Format("yyyy-MM-dd hh:mm:ss.S") + "]" + message, optionalParams);
+        }
+
+        function f_register() {
+
+            var server = document.getElementById('tbServer').value;
+            var username = document.getElementById('tbExtension').value;
+            var passwd = document.getElementById('tbPassword').value;
+
+            var uristr = 'sip:' + username;
+            if (uristr.indexOf('@') < 1)
+                uristr = uristr + '@' + server;
+            //
+            logger_info(`寮�濮嬫敞鍐屽埌鏈嶅姟鍣�:${server},鍒嗘満鍙�:${username}...`);
+            var socket = new JsSIP.WebSocketInterface('wss://' + server +':7443');
+            var configuration = {
+                sockets: [socket],
+                uri: uristr,
+                password: passwd,
+                display_name: username,
+                iceServers: [
+                    { urls: '' }
+                ]
+            };
+
+            ua = new JsSIP.UA(configuration);
+
+            ua.on('registered', function (e) { logger_info("娉ㄥ唽鎴愬姛銆�", e); });
+            ua.on('unregistered', function (e) { logger_info('鍙栨秷娉ㄥ唽銆�', e); });
+            ua.on('registrationFailed', function (e) { logger_info('娉ㄥ唽澶辫触鐨勩��', e); });
+            ua.on('newRTCSession', function (e) {
+                logger_info('newRTCSession', e);
+                //
+                cur_session = e.session;
+                cur_session.on("accepted", function (e) { logger_info("鍛煎彨宸叉帴閫氥��", e); });
+                cur_session.on("ended", function (e) { logger_info("鍛煎彨缁撴潫銆�", e); });
+
+                cur_session.oniceconnectionstatechange = function () {
+                    if (cur_session.connection.iceConnectionState === 'completed') {
+                        // 鑾峰彇鏈湴SDP
+                        const localSdp = cur_session.connection.localDescription;
+
+                        // 淇敼SDP锛堣繖閲屼互淇敼闊抽缂栬В鐮佸櫒浼樺厛绾т负渚嬶級
+                        const sdp = localSdp.sdp;
+                        const modifiedSdp = sdp.replace(/m=audio (\d+) RTP\/AVP (\d+) (.*)/g, (match, port, payloadTypes, formats) => {
+                            // 鍋囪鎴戜滑鎯冲皢PCMU缂栬В鐮佸櫒鐨勪紭鍏堢骇鎻愰珮
+                            const preferredPayloadType = '0'; // PCMU鐨刾ayload type
+                            const preferredFormat = formats.split(' ').find(format => format.startsWith(preferredPayloadType));
+                            if (preferredFormat) {
+                                const newFormats = formats.split(' ').filter(format => format !== preferredFormat).concat(preferredFormat);
+                                return `m=audio ${port} RTP/AVP ${newFormats.join(' ')}`;
+                            }
+                            return match;
+                        });
+
+                        // 鍒涘缓鏂扮殑RTCSessionDescription瀵硅薄
+                        const newDescription = new RTCSessionDescription({
+                            type: localSdp.type,
+                            sdp: modifiedSdp
+                        });
+
+                        // 璁剧疆淇敼鍚庣殑SDP
+                        cur_session.connection.setLocalDescription(newDescription).catch(error => {
+                            logger_info('Failed to set local description:', error);
+                        });
+                    }
+                }
+                //
+                if (e.originator == "remote")
+                    e.session.answer();
+            });
+            ua.start();
+        }
+
+        function f_hangup() {
+            if (cur_session != undefined) {
+                cur_session.terminate();
+                cur_session = undefined;
+            }
+        }
+
+        function f_makecall() {
+            if (ua == undefined)
+                return;
+            //
+            var eventHandlers = {
+                'progress': function (e) {
+                    logger_info('call is in progress', e);
+                },
+                'failed': function (e) {
+                    logger_info('call failed with cause: ', e);
+                },
+                'ended': function (e) {
+                    logger_info('鍛煎彨缁撴潫锛屾寕鏈哄師鍥�: ', e);
+                },
+                'confirmed': function (e) {
+                    logger_info('call confirmed', e);
+                }
+            };
+
+            var options = {
+                'eventHandlers': eventHandlers,
+                'mediaConstraints': { 'audio': true, 'video': false },
+                sessionTimersExpires: 1800
+            };
+
+            var server = document.getElementById('tbServer').value;
+            var phone = document.getElementById('tbPhoneNo').value;
+            logger_info("寮�濮嬪懠鍙彿鐮侊細", phone);
+            cur_session = ua.call('sip:' + phone + '@' + server, options);
+
+        }
+
+    </script>
+</body>
+</html>

--
Gitblit v1.9.3