1- define ( [ "nbextensions/vpython_libraries/plotly.min" ,
1+ define ( [ "base/js/utils" ,
2+ "nbextensions/vpython_libraries/plotly.min" ,
23 "nbextensions/vpython_libraries/glow.min" ,
3- "nbextensions/vpython_libraries/jquery-ui.custom.min" ] , function ( Plotly ) {
4+ "nbextensions/vpython_libraries/jquery-ui.custom.min" ] , function ( utils , Plotly ) {
45
56var comm
67var ws = null
@@ -20,11 +21,30 @@ IPython.notebook.kernel.comm_manager.register_target('glow',
2021 comm . on_close ( function ( msg ) { console . log ( "glow comm channel closed" ) } ) ;
2122
2223 if ( msg . content . data . wsport !== undefined ) {
23- // create websocket instance
24- var port = msg . content . data . wsport
25- var uri = msg . content . data . wsuri
26- ws = new WebSocket ( "ws://localhost:" + port + uri ) ;
27- ws . binaryType = "arraybuffer" ;
24+ // create websocket instance
25+ var port = msg . content . data . wsport
26+ var uri = msg . content . data . wsuri
27+ var loc = document . location , new_uri , url ;
28+
29+ // Get base URL of current notebook server
30+ var base_url = utils . get_body_data ( 'baseUrl' ) ;
31+ // Construct URL of our proxied service
32+ var service_url = base_url + 'proxy/' + port + uri ;
33+
34+ if ( loc . protocol === "https:" ) {
35+ new_uri = "wss:" ;
36+ } else {
37+ new_uri = "ws:" ;
38+ }
39+ if ( document . location . hostname . includes ( "localhost" ) ) {
40+ url = "ws://localhost:" + port + uri ;
41+ }
42+ else {
43+ new_uri += '//' + document . location . host + service_url ;
44+ url = new_uri
45+ }
46+ ws = new WebSocket ( url ) ;
47+ ws . binaryType = "arraybuffer" ;
2848
2949 // Handle incoming websocket message callback
3050 ws . onmessage = function ( evt ) {
@@ -992,4 +1012,4 @@ function handle_attrs(dattrs) {
9921012}
9931013console . log ( "END OF GLOWCOMM" )
9941014
995- } ) ;
1015+ } ) ;
0 commit comments