File tree 3 files changed +26
-12
lines changed 3 files changed +26
-12
lines changed Original file line number Diff line number Diff line change @@ -197,11 +197,14 @@ def send_json(self, content):
197
197
self .comm .send ({'data' : json .dumps (content )})
198
198
199
199
def send_binary (self , blob ):
200
- # The comm is ascii, so we always send the image in base64
201
- # encoded data URL form.
202
- data = b64encode (blob ).decode ('ascii' )
203
- data_uri = "data:image/png;base64,{0}" .format (data )
204
- self .comm .send ({'data' : data_uri })
200
+ if self .supports_binary :
201
+ self .comm .send ({'blob' : 'image/png' }, buffers = [blob ])
202
+ else :
203
+ # The comm is ASCII, so we send the image in base64 encoded data
204
+ # URL form.
205
+ data = b64encode (blob ).decode ('ascii' )
206
+ data_uri = "data:image/png;base64,{0}" .format (data )
207
+ self .comm .send ({'data' : data_uri })
205
208
206
209
def on_message (self , message ):
207
210
# The 'supports_binary' message is relevant to the
Original file line number Diff line number Diff line change @@ -499,11 +499,14 @@ mpl.figure.prototype.updated_canvas_event = function () {
499
499
mpl . figure . prototype . _make_on_message_function = function ( fig ) {
500
500
return function socket_on_message ( evt ) {
501
501
if ( evt . data instanceof Blob ) {
502
- /* FIXME: We get "Resource interpreted as Image but
503
- * transferred with MIME type text/plain:" errors on
504
- * Chrome. But how to set the MIME type? It doesn't seem
505
- * to be part of the websocket stream */
506
- evt . data . type = 'image/png' ;
502
+ var img = evt . data ;
503
+ if ( img . type !== 'image/png' ) {
504
+ /* FIXME: We get "Resource interpreted as Image but
505
+ * transferred with MIME type text/plain:" errors on
506
+ * Chrome. But how to set the MIME type? It doesn't seem
507
+ * to be part of the websocket stream */
508
+ img . type = 'image/png' ;
509
+ }
507
510
508
511
/* Free the memory for the previous frames */
509
512
if ( fig . imageObj . src ) {
@@ -513,7 +516,7 @@ mpl.figure.prototype._make_on_message_function = function (fig) {
513
516
}
514
517
515
518
fig . imageObj . src = ( window . URL || window . webkitURL ) . createObjectURL (
516
- evt . data
519
+ img
517
520
) ;
518
521
fig . updated_canvas_event ( ) ;
519
522
fig . waiting = false ;
Original file line number Diff line number Diff line change @@ -6,6 +6,8 @@ var comm_websocket_adapter = function (comm) {
6
6
// socket, so there is still some room for performance tuning.
7
7
var ws = { } ;
8
8
9
+ ws . binaryType = comm . kernel . ws . binaryType ;
10
+
9
11
ws . close = function ( ) {
10
12
comm . close ( ) ;
11
13
} ;
@@ -16,8 +18,14 @@ var comm_websocket_adapter = function (comm) {
16
18
// Register the callback with on_msg.
17
19
comm . on_msg ( function ( msg ) {
18
20
//console.log('receiving', msg['content']['data'], msg);
21
+ var data = msg [ 'content' ] [ 'data' ] ;
22
+ if ( data [ 'blob' ] !== undefined ) {
23
+ data = {
24
+ data : new Blob ( msg [ 'buffers' ] , { type : data [ 'blob' ] } ) ,
25
+ } ;
26
+ }
19
27
// Pass the mpl event to the overridden (by mpl) onmessage function.
20
- ws . onmessage ( msg [ 'content' ] [ ' data' ] ) ;
28
+ ws . onmessage ( data ) ;
21
29
} ) ;
22
30
return ws ;
23
31
} ;
You can’t perform that action at this time.
0 commit comments