nichongjia-2007
2023-06-30 012903e42ec890ab5c50137beb365c3d94e731d1
funasr/runtime/html5/static/wsconnecter.js
@@ -15,8 +15,7 @@
           
   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*/))
      if(Uri.match(/wss:\S*|ws:\S*/))
      {
         console.log("Uri"+Uri);
      }
@@ -25,12 +24,13 @@
         alert("请检查wss地址正确性");
         return 0;
      }
      if ( 'WebSocket' in window ) {
         speechSokt = new WebSocket( Uri ); // 定义socket连接对象
         speechSokt.onopen = function(e){onOpen(e);}; // 定义响应函数
         speechSokt.onclose = function(e){
             console.log("onclose ws!");
             speechSokt.close();
             //speechSokt.close();
            onClose(e);
            };
         speechSokt.onmessage = function(e){onMessage(e);};
@@ -51,16 +51,13 @@
      }
   };
   
   this.wsSend = function ( oneData,stop ) {
   this.wsSend = function ( oneData ) {
 
      if(speechSokt == undefined) return;
      if ( speechSokt.readyState === 1 ) { // 0:CONNECTING, 1:OPEN, 2:CLOSING, 3:CLOSED
 
         speechSokt.send( oneData );
         if(stop){
            setTimeout(speechSokt.close(), 3000 );
 
         }
         
      }
   };
@@ -80,6 +77,7 @@
      speechSokt.send( JSON.stringify(request) );
      console.log("连接成功");
      stateHandle(0);
   }
   
   function onClose( e ) {
@@ -92,9 +90,11 @@
   }
   
   function onError( e ) {
      info_div.innerHTML="连接"+e;
      console.log(e);
      stateHandle(2);
   }