15
15
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
17
17
import React , { Fragment , useEffect , useState } from "react" ;
18
- import { IMessageEvent , w3cwebsocket as W3CWebSocket } from "websocket" ;
19
18
import { Box , Button , Grid , PageLayout , Select , Table , TableBody } from "mds" ;
20
19
import { useSelector } from "react-redux" ;
21
20
import { ErrorResponseHandler } from "../../../../common/types" ;
@@ -33,7 +32,7 @@ import LogLine from "./LogLine";
33
32
import PageHeaderWrapper from "../../Common/PageHeaderWrapper/PageHeaderWrapper" ;
34
33
import HelpMenu from "../../HelpMenu" ;
35
34
36
- var c : any = null ;
35
+ var socket : any = null ;
37
36
38
37
const ErrorLogs = ( ) => {
39
38
const dispatch = useAppDispatch ( ) ;
@@ -61,24 +60,24 @@ const ErrorLogs = () => {
61
60
const baseLocation = new URL ( document . baseURI ) ;
62
61
const baseUrl = baseLocation . pathname ;
63
62
64
- c = new W3CWebSocket (
63
+ socket = new WebSocket (
65
64
`${ wsProt } ://${
66
65
url . hostname
67
66
} :${ port } ${ baseUrl } ws/console/?logType=${ logType } &node=${
68
67
selectedNode === "Select node" ? "" : selectedNode
69
68
} `,
70
69
) ;
71
70
let interval : any | null = null ;
72
- if ( c !== null ) {
73
- c . onopen = ( ) => {
71
+ if ( socket !== null ) {
72
+ socket . onopen = ( ) => {
74
73
console . log ( "WebSocket Client Connected" ) ;
75
74
dispatch ( setLogsStarted ( true ) ) ;
76
- c . send ( "ok" ) ;
75
+ socket . send ( "ok" ) ;
77
76
interval = setInterval ( ( ) => {
78
- c . send ( "ok" ) ;
77
+ socket . send ( "ok" ) ;
79
78
} , 10 * 1000 ) ;
80
79
} ;
81
- c . onmessage = ( message : IMessageEvent ) => {
80
+ socket . onmessage = ( message : MessageEvent ) => {
82
81
// console.log(message.data.toString())
83
82
// FORMAT: 00:35:17 UTC 01/01/2021
84
83
@@ -104,13 +103,13 @@ const ErrorLogs = () => {
104
103
dispatch ( logMessageReceived ( m ) ) ;
105
104
}
106
105
} ;
107
- c . onclose = ( ) => {
106
+ socket . onclose = ( ) => {
108
107
clearInterval ( interval ) ;
109
108
console . log ( "connection closed by server" ) ;
110
109
dispatch ( setLogsStarted ( false ) ) ;
111
110
} ;
112
111
return ( ) => {
113
- c . close ( 1000 ) ;
112
+ socket . close ( 1000 ) ;
114
113
clearInterval ( interval ) ;
115
114
console . log ( "closing websockets" ) ;
116
115
dispatch ( setLogsStarted ( false ) ) ;
@@ -119,8 +118,8 @@ const ErrorLogs = () => {
119
118
} ;
120
119
121
120
const stopLogs = ( ) => {
122
- if ( c !== null && c !== undefined ) {
123
- c . close ( 1000 ) ;
121
+ if ( socket !== null && socket !== undefined ) {
122
+ socket . close ( 1000 ) ;
124
123
dispatch ( setLogsStarted ( false ) ) ;
125
124
}
126
125
} ;
0 commit comments