Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make handle_binary compliant with the KernelMessage.IMessage spec #505

Merged
merged 2 commits into from
Dec 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/mpl_widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,12 @@ export class MPLCanvasModel extends DOMWidgetModel {
this.send_draw_message();
}

handle_binary(msg: any, dataviews: any) {
handle_binary(msg: any, buffers: (ArrayBuffer | ArrayBufferView)[]) {
const url_creator = window.URL || window.webkitURL;

const buffer = new Uint8Array(dataviews[0].buffer);
const buffer = new Uint8Array(
ArrayBuffer.isView(buffers[0]) ? buffers[0].buffer : buffers[0]
);
const blob = new Blob([buffer], { type: 'image/png' });
const image_url = url_creator.createObjectURL(blob);

Expand All @@ -263,7 +265,7 @@ export class MPLCanvasModel extends DOMWidgetModel {
// button to toggle?
}

on_comm_message(evt: any, dataviews: any) {
on_comm_message(evt: any, buffers: (ArrayBuffer | ArrayBufferView)[]) {
const msg = JSON.parse(evt.data);
const msg_type = msg['type'];
let callback;
Expand All @@ -281,7 +283,7 @@ export class MPLCanvasModel extends DOMWidgetModel {
}

if (callback) {
callback(msg, dataviews);
callback(msg, buffers);
}
}

Expand Down