1
- define ( [ "nbextensions/vpython_libraries/plotly.min" ,
1
+ define ( [ "base/js/utils" ,
2
+ "nbextensions/vpython_libraries/plotly.min" ,
2
3
"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 ) {
4
5
5
6
var comm
6
7
var ws = null
@@ -20,11 +21,30 @@ IPython.notebook.kernel.comm_manager.register_target('glow',
20
21
comm . on_close ( function ( msg ) { console . log ( "glow comm channel closed" ) } ) ;
21
22
22
23
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" ;
28
48
29
49
// Handle incoming websocket message callback
30
50
ws . onmessage = function ( evt ) {
@@ -992,4 +1012,4 @@ function handle_attrs(dattrs) {
992
1012
}
993
1013
console . log ( "END OF GLOWCOMM" )
994
1014
995
- } ) ;
1015
+ } ) ;
0 commit comments