55 const liveReloadCheck = document . getElementById ( 'liveReloadCheck' ) ;
66 const noProxyCheckBox = document . getElementById ( 'noProxyCheckBox' ) ;
77 const actualServerAddress = document . getElementById ( 'actualServer' ) ;
8- const liveServerAddress = document . getElementById ( 'liveServer ' ) ;
8+ const liveServerPort = document . getElementById ( 'liveServerPort ' ) ;
99 const submitBtn = document . getElementById ( 'submitBtn' ) ;
10+ const liveServerConnBtn = document . getElementById ( 'liveServerConnBtn' ) ;
1011
1112 const serverSetupDiv = document . getElementById ( 'serverSetup' ) ;
1213
1516 isEnable : liveReloadCheck . checked ,
1617 proxySetup : ! noProxyCheckBox . checked ,
1718 actualUrl : actualServerAddress . value || '' ,
18- liveServerUrl : liveServerAddress . value || ''
19+ // liveServerUrl: `http://127.0.0.1:${liveServerPort.value}`,
20+ liveServerPort : liveServerPort . value
1921 }
2022
2123 chrome . runtime . sendMessage ( {
4345 liveReloadCheck . checked = data . isEnable || false ;
4446 noProxyCheckBox . checked = ! data . proxySetup ;
4547 actualServerAddress . value = data . actualUrl || '' ;
46- liveServerAddress . value = data . liveServerUrl || '' ;
48+ liveServerPort . value = data . liveServerPort || 5500 ;
4749 serverSetupDiv . className = noProxyCheckBox . checked ? 'show' : 'hide' ;
4850 } ) ;
4951 } ) ;
5456 submitBtn . disabled = true ;
5557 }
5658
57- liveServerAddress . onkeyup = actualServerAddress . onkeyup = ( ) => {
59+ liveServerPort . onkeyup = actualServerAddress . onkeyup = ( ) => {
5860 submitBtn . disabled = false ;
5961 submitBtn . classList . add ( 'btn-highlight' ) ;
62+ liveServerConnBtn . innerText = 'Test Connection' ;
63+ liveServerConnBtn . classList . remove ( 'connected' ) ;
64+ liveServerConnBtn . classList . remove ( 'not-connected' ) ;
6065 }
6166
67+ liveServerConnBtn . onclick = ( ) => {
68+ const ws = new WebSocket ( `ws://127.0.0.1:${ liveServerPort . value } /ws` )
69+ ws . onerror = ( ) => {
70+ liveServerConnBtn . classList . remove ( 'connected' ) ;
71+ liveServerConnBtn . classList . add ( 'not-connected' ) ;
72+ liveServerConnBtn . innerText = "Not Connected"
73+ console . log ( 'not connected' ) ;
74+ }
75+ ws . onmessage = ( ) => {
76+ liveServerConnBtn . classList . add ( 'connected' ) ;
77+ liveServerConnBtn . classList . remove ( 'not-connected' ) ;
78+ liveServerConnBtn . innerText = "Connected"
79+ console . log ( 'connected' ) ;
80+ ws . close ( ) ;
81+ }
82+ } ;
83+
6284
6385} ) ( ) ;
0 commit comments