File tree Expand file tree Collapse file tree 2 files changed +7
-5
lines changed Expand file tree Collapse file tree 2 files changed +7
-5
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " ballcat-ui-vue" ,
3
- "version" : " 0.0.6 " ,
3
+ "version" : " 0.0.7 " ,
4
4
"private" : true ,
5
5
"scripts" : {
6
6
"serve" : " vue-cli-service serve" ,
Original file line number Diff line number Diff line change @@ -37,7 +37,9 @@ export default {
37
37
initWebSocket () {
38
38
// ws地址
39
39
const token = Vue .ls .get (ACCESS_TOKEN )
40
- const wsUri = ' ws://127.0.0.1:8080/ws?access_token=' + token
40
+ let url = process .env .VUE_APP_API_BASE_URL ;
41
+ let host = window .location .host ;
42
+ let wsUri = ` ws://${ host}${ url} /ws?access_token=${ token} `
41
43
// 建立连接
42
44
this .webSocket = new WebSocket (wsUri)
43
45
// 连接成功
@@ -88,7 +90,7 @@ export default {
88
90
// 心跳发送后,如果服务器超时未响应则断开,如果响应了会被重置心跳定时器
89
91
heartbeat .pongTimeoutObj = setTimeout (() => {
90
92
webSocket .close ()
91
- }, this .timeout )
93
+ }, heartbeat .timeout )
92
94
} else {
93
95
// 否则重连
94
96
this .reconnect ()
@@ -110,7 +112,7 @@ export default {
110
112
*/
111
113
onError (e ) {
112
114
// 错误
113
- console .log (' WebSocket connection error ( ' + e .reason + ' ) ' )
115
+ console .log (` WebSocket connection error: ${ e . code } ${ e .reason } ${ e . wasClean } ` )
114
116
// 重连
115
117
this .reconnect ()
116
118
},
@@ -120,7 +122,7 @@ export default {
120
122
*/
121
123
onClose (e ) {
122
124
// 关闭
123
- console .log (' WebSocket connection closed ( ' + e .reason + ' ) ' )
125
+ console .log (` WebSocket connection closed: ${ e . code } ${ e .reason } ${ e . wasClean } ` )
124
126
// 重连
125
127
this .reconnect ()
126
128
},
You can’t perform that action at this time.
0 commit comments