File tree Expand file tree Collapse file tree 2 files changed +14
-6
lines changed Expand file tree Collapse file tree 2 files changed +14
-6
lines changed Original file line number Diff line number Diff line change 11from channels .generic .websocket import WebsocketConsumer
22
3+ import json
4+
35class MessageConsumer (WebsocketConsumer ):
46 def connect (self ):
57 self .accept ()
68 def disconnect (self , close_code ):
79 pass
810 def receive (self , text_data ):
911 print ("Got incoming" )
12+ message = json .loads (text_data )
1013 print (text_data )
11- self .send ("Thanks for [%s]" % text_data )
14+ self .send (json .dumps ({'message' :"Thanks for [%s]" % text_data }))
15+ self .send (json .dumps ({'original_message' :message }))
Original file line number Diff line number Diff line change 11<!DOCTYPE HTML>
22< html >
3+ {%load staticfiles%}
34{%load plotly_dash%}
45< title > Simple stuff</ title >
56< body >
1617 {%plotly_app name="Ex2"%}
1718 </ div >
1819</ body >
20+ < script src ="{%static "channels /js/websocketbridge.js"%}"> </ script >
1921< script >
20- var socket = new WebSocket ( "ws://" + window . location . host + "/ws/channel" ) ;
21- socket . onmessage = function ( e ) {
22- console . log ( "Got ws inbound message" ) ;
23- console . log ( e ) ;
24- } ;
22+ const wsb = new channels . WebSocketBridge ( ) ;
23+ wsb . connect ( "/ws/channel" ) ;
24+ wsb . listen ( function ( action , stream ) {
25+ console . log ( "WSB inbound" ) ;
26+ console . log ( action ) ;
27+ console . log ( stream ) ;
28+ } ) ;
2529</ script >
2630</ html >
You can’t perform that action at this time.
0 commit comments