From b63e73ae4f5df9d4ed9fb0bee12ac2cc09d7f523 Mon Sep 17 00:00:00 2001
From: zhaomingwork <zhaomingwork@qq.com>
Date: 星期五, 19 五月 2023 14:30:13 +0800
Subject: [PATCH] add asr wss address input to html

---
 funasr/runtime/html5/static/wsconnecter.js |   17 +++++++-
 funasr/runtime/html5/readme.md             |    7 +--
 funasr/runtime/html5/static/index.html     |    9 +++-
 funasr/runtime/html5/readme_cn.md          |    8 +--
 funasr/runtime/html5/static/main.js        |   25 +++++++++---
 5 files changed, 46 insertions(+), 20 deletions(-)

diff --git a/funasr/runtime/html5/readme.md b/funasr/runtime/html5/readme.md
index 5dd462b..e60d588 100644
--- a/funasr/runtime/html5/readme.md
+++ b/funasr/runtime/html5/readme.md
@@ -41,13 +41,12 @@
 ```shell
 python ws_server_online.py  --port 5921
 ```
-## 3.modify asr address in wsconnecter.js according to your environment
-asr address in wsconnecter.js must be wss, just like
-var Uri = "wss://xxx:xxx/" 
 
-## 4.open browser to access html5 demo
+## 3.open browser to access html5 demo
 https://youraddress:port/static/index.html
 
+## 4.modify asr address in html according to your environment
+asr address in index.html must be wss
 
 
 
diff --git a/funasr/runtime/html5/readme_cn.md b/funasr/runtime/html5/readme_cn.md
index d7fb1aa..5037697 100644
--- a/funasr/runtime/html5/readme_cn.md
+++ b/funasr/runtime/html5/readme_cn.md
@@ -41,14 +41,12 @@
 ```shell
 python ws_server_online.py  --port 5921
 ```
-## 3.淇敼wsconnecter.js閲宎sr鎺ュ彛鍦板潃
-wsconnecter.js閲岄厤缃畂nline asr鏈嶅姟鍦板潃璺緞锛岃繖閲岄厤缃殑鏄痺ss绔彛
-var Uri = "wss://xxx:xxx/" 
 
-## 4.娴忚鍣ㄦ墦寮�鍦板潃娴嬭瘯
+## 3.娴忚鍣ㄦ墦寮�鍦板潃娴嬭瘯,璇锋牴鎹疄闄卛p濉啓
 https://127.0.0.1:1337/static/index.html
 
-
+## 4.淇敼缃戦〉閲宎sr鎺ュ彛鍦板潃
+鐩存帴缃戦〉閲屼慨鏀瑰悗锛岀偣鍑诲紑濮嬪嵆鍙娇鐢ㄣ�傛敞鎰廻5鏈嶅姟鍜宎sr鏈嶅姟闇�瑕佸湪鍚屼竴涓湇鍔″櫒涓婏紝鍚﹀垯瀛樺湪璺ㄥ煙闂銆�
 
 
 ## 鑷鐢熸垚璇佷功
diff --git a/funasr/runtime/html5/static/index.html b/funasr/runtime/html5/static/index.html
index 1cdc7d7..c0aae05 100644
--- a/funasr/runtime/html5/static/index.html
+++ b/funasr/runtime/html5/static/index.html
@@ -13,10 +13,15 @@
 
 		 
 
-
+        <h1>FunAsr H5 Demo</h1>
 		<div class="div_class_topArea">
-      
+            
 			<div class="div_class_recordControl">
+				asr鏈嶅姟鍣ㄥ湴鍧�(蹇呭~):
+				<br>
+				<input id="wssip" type="text" style=" width: 100%;height:100%" value="wss://127.0.0.1:5921/"/>
+				<br>
+				<br>
 				璇煶璇嗗埆缁撴灉鏄剧ず锛�
 				<br>
 				
diff --git a/funasr/runtime/html5/static/main.js b/funasr/runtime/html5/static/main.js
index 5f6bb10..eaa257a 100644
--- a/funasr/runtime/html5/static/main.js
+++ b/funasr/runtime/html5/static/main.js
@@ -32,7 +32,11 @@
  
 var rec_text=""
 var info_div = document.getElementById('info_div');
- 
+
+var now_ipaddress=window.location.href;
+now_ipaddress=now_ipaddress.replace("https://","wss://");   
+now_ipaddress=now_ipaddress.replace("static/index.html","");   
+document.getElementById('wssip').value=now_ipaddress;
 
 // 璇煶璇嗗埆缁撴灉; 瀵筳sonMsg鏁版嵁瑙f瀽,灏嗚瘑鍒粨鏋滈檮鍔犲埌缂栬緫妗嗕腑
 function getJsonMessage( jsonMsg ) {
@@ -59,23 +63,30 @@
 	} else if ( connState === 2 ) {
 		stop();
 		console.log( 'connecttion error' );
-		setTimeout(function(){btnStart.disabled = true;info_div.innerHTML='connecttion error';}, 4000 );
+		 
+		alert("杩炴帴鍦板潃"+document.getElementById('wssip').value+"澶辫触,璇锋鏌sr鍦板潃鍜岀鍙o紝骞剁‘淇漢5鏈嶅姟鍜宎sr鏈嶅姟鍦ㄥ悓涓�涓煙鍐呫�傛垨鎹釜娴忚鍣ㄨ瘯璇曘��");
+		btnStart.disabled = true;
+		info_div.innerHTML='璇风偣鍑诲紑濮�';
 	}
 }
 
 
 // 璇嗗埆鍚姩銆佸仠姝€�佹竻绌烘搷浣�
 function start() {
-	info_div.innerHTML="姝e湪杩炴帴asr鏈嶅姟鍣紝璇风瓑寰�...";
+	
 	// 娓呴櫎鏄剧ず
 	clear();
 	//鎺т欢鐘舵�佹洿鏂�
  	    
-	isRec = true;
-	btnStart.disabled = true;
-	btnStop.disabled = false;
+
 	//鍚姩杩炴帴
-	wsconnecter.wsStart();
+	var ret=wsconnecter.wsStart();
+	if(ret==1){
+		isRec = true;
+		btnStart.disabled = true;
+		btnStop.disabled = false;
+	    info_div.innerHTML="姝e湪杩炴帴asr鏈嶅姟鍣紝璇风瓑寰�...";
+	}
 }
 
  
diff --git a/funasr/runtime/html5/static/wsconnecter.js b/funasr/runtime/html5/static/wsconnecter.js
index 594652d..82d751b 100644
--- a/funasr/runtime/html5/static/wsconnecter.js
+++ b/funasr/runtime/html5/static/wsconnecter.js
@@ -5,7 +5,8 @@
 /* 2021-2023 by zhaoming,mali aihealthx.com */
 
 function WebSocketConnectMethod( config ) { //瀹氫箟socket杩炴帴鏂规硶绫�
-    var Uri = "wss://30.220.136.139:5921/"  //	var Uri = "wss://30.221.177.46:5921/" //璁剧疆wss asr online鎺ュ彛鍦板潃 濡� wss://X.X.X.X:port/wss/
+
+	
 	var speechSokt;
 	var connKeeperID;
 	
@@ -13,16 +14,28 @@
 	var stateHandle = config.stateHandle;
 			  
 	this.wsStart = function () {
-		
+		var Uri = document.getElementById('wssip').value; //"wss://111.205.137.58:5821/wss/" //璁剧疆wss asr online鎺ュ彛鍦板潃 濡� wss://X.X.X.X:port/wss/
+ 
+		if(Uri.match(/wss:\S*/))
+		{
+			console.log("Uri"+Uri);
+		}
+		else
+		{
+			alert("璇锋鏌ss鍦板潃姝g‘鎬�");
+			return 0;
+		}
 		if ( 'WebSocket' in window ) {
 			speechSokt = new WebSocket( Uri ); // 瀹氫箟socket杩炴帴瀵硅薄
 			speechSokt.onopen = function(e){onOpen(e);}; // 瀹氫箟鍝嶅簲鍑芥暟
 			speechSokt.onclose = function(e){onClose(e);};
 			speechSokt.onmessage = function(e){onMessage(e);};
 			speechSokt.onerror = function(e){onError(e);};
+			return 1;
 		}
 		else {
 			alert('褰撳墠娴忚鍣ㄤ笉鏀寔 WebSocket');
+			return 0;
 		}
 	};
 	

--
Gitblit v1.9.1