@@ -15,17 +15,31 @@ var isopen = false
1515
1616console . log ( 'START OF GLOWCOMM' )
1717
18- export function createWebsocket ( msg ) {
18+ export function createWebsocket ( msg , serviceUrl ) {
1919 if ( msg . content . data . wsport !== undefined ) {
2020 // create websocket instance
21- var port = msg . content . data . wsport
22- var uri = msg . content . data . wsuri
23- ws = new WebSocket ( "ws://localhost:" + port + uri ) ;
24- ws . binaryType = "arraybuffer" ;
21+ var port = msg . content . data . wsport
22+ var uri = msg . content . data . wsuri
23+ var loc = document . location , new_uri , url ;
24+
25+ if ( loc . protocol === "https:" ) {
26+ new_uri = "wss:" ;
27+ } else {
28+ new_uri = "ws:" ;
29+ }
30+ if ( document . location . hostname . includes ( "localhost" ) ) {
31+ url = "ws://localhost:" + port + uri ;
32+ }
33+ else {
34+ new_uri += '//' + document . location . host + service_url + uri ;
35+ url = new_uri
36+ }
37+ ws = new WebSocket ( url ) ;
38+ ws . binaryType = "arraybuffer" ;
2539
2640 // Handle incoming websocket message callback
2741 ws . onmessage = function ( evt ) {
28- console . log ( "WebSocket Message Received: " + evt . data )
42+ console . log ( "WebSocket Message Received: " + evt . data )
2943 } ;
3044
3145 // Close Websocket callback
0 commit comments