MCPcopy Index your code
hub / github.com/modelscope/FunASR / WebSocketConnectMethod

Function WebSocketConnectMethod

runtime/html5/static/wsconnecter.js:7–119  ·  view source on GitHub ↗
( config )

Source from the content-addressed store, hash-verified

5/* 2021-2023 by zhaoming,mali aihealthx.com */
6
7function WebSocketConnectMethod( config ) { //定义socket连接方法类
8
9
10 var speechSokt;
11 var connKeeperID;
12
13 var msgHandle = config.msgHandle;
14 var stateHandle = config.stateHandle;
15
16 this.wsStart = function () {
17 var Uri = document.getElementById('wssip').value; //"wss://111.205.137.58:5821/wss/" //设置wss asr online接口地址 如 wss://X.X.X.X:port/wss/
18 if(Uri.match(/wss:\S*|ws:\S*/))
19 {
20 console.log("Uri"+Uri);
21 }
22 else
23 {
24 alert("请检查wss地址正确性");
25 return 0;
26 }
27
28 if ( 'WebSocket' in window ) {
29 speechSokt = new WebSocket( Uri ); // 定义socket连接对象
30 speechSokt.onopen = function(e){onOpen(e);}; // 定义响应函数
31 speechSokt.onclose = function(e){
32 console.log("onclose ws!");
33 //speechSokt.close();
34 onClose(e);
35 };
36 speechSokt.onmessage = function(e){onMessage(e);};
37 speechSokt.onerror = function(e){onError(e);};
38 return 1;
39 }
40 else {
41 alert('当前浏览器不支持 WebSocket');
42 return 0;
43 }
44 };
45
46 // 定义停止与发送函数
47 this.wsStop = function () {
48 if(speechSokt != undefined) {
49 console.log("stop ws!");
50 speechSokt.close();
51 }
52 };
53
54 this.wsSend = function ( oneData ) {
55
56 if(speechSokt == undefined) return;
57 if ( speechSokt.readyState === 1 ) { // 0:CONNECTING, 1:OPEN, 2:CLOSING, 3:CLOSED
58
59 speechSokt.send( oneData );
60
61
62 }
63 };
64

Callers

nothing calls this directly

Calls 6

onOpenFunction · 0.70
onCloseFunction · 0.70
onMessageFunction · 0.70
onErrorFunction · 0.70
logMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…