@@ -168,12 +168,31 @@ module openflow {
168168 }
169169 init ( ) {
170170 this . getJSON ( "/config" , async ( error : any , data : any ) => {
171- if ( location . protocol == 'https:' && data . wshost . startsWith ( "ws://" ) ) {
172- data . wshost = data . wshost . replace ( "ws://" , "wss://" ) ;
171+ var parser = document . createElement ( 'a' ) ;
172+ parser . href = data . wshost ;
173+ parser . protocol ; // => "http:"
174+ parser . hostname ; // => "example.com"
175+ parser . port ; // => "3000"
176+ parser . pathname ; // => "/pathname/"
177+ parser . search ; // => "?search=test"
178+ parser . hash ; // => "#hash"
179+ parser . host ; // => "example.com:3000"
180+ console . log ( location . protocol ) ;
181+ console . log ( parser . protocol ) ;
182+ console . log ( data . wshost ) ;
183+ if ( location . protocol == 'https:' && data . wshost == "ws:" ) {
184+ data . wshost = "wss://" + parser . hostname ;
185+ if ( parser . port != "80" ) {
186+ data . wshost = "wss://" + parser . hostname + parser . port ;
187+ }
173188 }
174- if ( location . protocol == 'http:' && data . wshost . startsWith ( "wss://" ) ) {
175- data . wshost = data . wshost . replace ( "wss://" , "ws://" ) ;
189+ if ( location . protocol == 'http:' && data . wshost == "wss:" ) {
190+ data . wshost = "ws://" + parser . hostname ;
191+ if ( parser . port != "443" ) {
192+ data . wshost = "ws://" + parser . hostname + parser . port ;
193+ }
176194 }
195+ console . log ( data . wshost ) ;
177196 console . debug ( "WebSocketClient::onopen: connecting to " + data . wshost ) ;
178197 this . _socketObject = new ReconnectingWebSocket ( data . wshost ) ;
179198 this . _socketObject . onopen = ( this . onopen ) . bind ( this ) ;
0 commit comments