@@ -15,17 +15,31 @@ var isopen = false
15
15
16
16
console . log ( 'START OF GLOWCOMM' )
17
17
18
- export function createWebsocket ( msg ) {
18
+ export function createWebsocket ( msg , serviceUrl ) {
19
19
if ( msg . content . data . wsport !== undefined ) {
20
20
// 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" ;
25
39
26
40
// Handle incoming websocket message callback
27
41
ws . onmessage = function ( evt ) {
28
- console . log ( "WebSocket Message Received: " + evt . data )
42
+ console . log ( "WebSocket Message Received: " + evt . data )
29
43
} ;
30
44
31
45
// Close Websocket callback
0 commit comments