File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ < html >
2+ < head >
3+ < script >
4+ const baseUrl = 'ws://localhost:8783/ws' ;
5+
6+ let agentInit = false ;
7+ agentWs = new WebSocket ( `${ baseUrl } /agent` ) ;
8+ agentWs . addEventListener ( 'error' , console . error ) ;
9+ agentWs . addEventListener ( 'close' , ( ) => console . log ( 'agent close' ) ) ;
10+ agentWs . addEventListener ( 'message' , ( m ) => {
11+ if ( ! agentInit ) {
12+ agentInit = true ;
13+ const agentInfo = JSON . parse ( m . data ) ;
14+ console . log ( 'Agent connected:' , agentInfo ) ;
15+ console . log ( 'Connect remote using:' ) ;
16+ console . log ( `remoteWs.send('{ "id": "${ agentInfo . id } " }');` ) ;
17+ return ;
18+ }
19+
20+ console . log ( 'agent:' , m . data ) ;
21+ } ) ;
22+ agentWs . addEventListener ( 'open' , ( ) => {
23+ agentWs . send ( JSON . stringify ( {
24+ meta : {
25+ platform : 'linux' ,
26+ version : '1.2.3'
27+ }
28+ } ) ) ;
29+ } ) ;
30+
31+ remoteWs = new WebSocket ( `${ baseUrl } /remote` ) ;
32+ remoteWs . addEventListener ( 'error' , console . error ) ;
33+ remoteWs . addEventListener ( 'close' , ( ) => console . log ( 'remote close' ) ) ;
34+ remoteWs . addEventListener ( 'message' , ( m ) => console . log ( 'remote:' , m . data ) ) ;
35+ </ script >
36+ </ head >
37+ < body > </ body >
38+ </ html >
You can’t perform that action at this time.
0 commit comments