@@ -295,10 +295,10 @@ def remove_web_socket(self, web_socket):
295
295
self .web_sockets .remove (web_socket )
296
296
297
297
def refresh_all (self ):
298
- if len ( self .web_sockets ) :
298
+ if self .web_sockets :
299
299
diff = self .canvas .get_diff_image ()
300
300
for s in self .web_sockets :
301
- s .send_image (diff )
301
+ s .send_diff_image (diff )
302
302
303
303
def send_event (self , event_type , ** kwargs ):
304
304
for s in self .web_sockets :
@@ -488,6 +488,13 @@ def on_message(self, message):
488
488
if message ['type' ] == 'supports_binary' :
489
489
self .supports_binary = message ['value' ]
490
490
elif message ['type' ] == 'ack' :
491
+ # Network latency tends to decrease if traffic is
492
+ # flowing in both directions. Therefore, the browser
493
+ # sends back an "ack" message after each image frame
494
+ # is received. This could also be used as a simple
495
+ # sanity check in the future, but for now the
496
+ # performance increase is enough to justify it, even
497
+ # if the server does nothing with it.
491
498
pass
492
499
else :
493
500
canvas = Gcf .get_fig_manager (self .fignum ).canvas
@@ -498,7 +505,7 @@ def send_event(self, event_type, **kwargs):
498
505
payload .update (kwargs )
499
506
self .write_message (json .dumps (payload ))
500
507
501
- def send_image (self , diff ):
508
+ def send_diff_image (self , diff ):
502
509
if self .supports_binary :
503
510
self .write_message (diff , binary = True )
504
511
else :
0 commit comments