File tree Expand file tree Collapse file tree 1 file changed +23
-7
lines changed
django_plotly_dash/templates/django_plotly_dash Expand file tree Collapse file tree 1 file changed +23
-7
lines changed Original file line number Diff line number Diff line change 11{%load staticfiles%}
22< script src ="{%static "channels /js/websocketbridge.js"%}"> </ script >
33< script >
4- const wsb = new channels . WebSocketBridge ( ) ;
5- wsb . connect ( "{{url}}" ) ;
6- wsb . listen ( function ( action , stream ) {
7- console . log ( "WSB inbound" ) ;
8- console . log ( action ) ;
9- console . log ( stream ) ;
10- } ) ;
4+ if ( ! window . dpd_wsb ) {
5+ const wsb = new channels . WebSocketBridge ( ) ;
6+ wsb . connect ( "{{url}}" ) ;
7+ var dpd_wsb = {
8+ wsb : wsb ,
9+ callbacks : [ ] ,
10+ add_callback : function ( cb ) { this . callbacks . push ( cb ) ; } ,
11+ send :function ( message ) { this . wsb . send ( message ) ; }
12+ } ;
13+ wsb . listen ( function ( action , stream ) {
14+ for ( var i in dpd_wsb . callbacks ) {
15+ dpd_wsb . callbacks [ i ] ( action , stream ) ;
16+ }
17+ } ) ;
18+ window . dpd_wsb = dpd_wsb ;
19+ var lcb = function ( action , stream ) {
20+ console . log ( "WSB inbound YYYYY" ) ;
21+ console . log ( action ) ;
22+ console . log ( stream ) ;
23+ } ;
24+ dpd_wsb . add_callback ( lcb ) ;
25+ dpd_wsb . add_callback ( lcb ) ;
26+ }
1127</ script >
You can’t perform that action at this time.
0 commit comments