Skip to content

Commit bb72fe7

Browse files
committed
feat: support using provided websockets in overlay websocket
1 parent 534c1ba commit bb72fe7

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

js/sigplot.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2442,8 +2442,13 @@
24422442
*/
24432443

24442444
overlay_websocket: function(wsurl, overrides, layerOptions) {
2445-
m.log.debug("Overlay websocket: " + wsurl);
2446-
var ws = new WebSocket(wsurl, "plot-data");
2445+
if (typeof wsurl === "string") {
2446+
m.log.debug("Overlay websocket: " + wsurl);
2447+
var ws = new WebSocket(wsurl, "plot-data");
2448+
} else {
2449+
m.log.debug("Using provided websocket");
2450+
var ws = wsurl;
2451+
}
24472452
ws.binaryType = "arraybuffer";
24482453

24492454
var plot = this;
@@ -2456,16 +2461,16 @@
24562461

24572462
var layer_n = this.overlay_bluefile(hcb, layerOptions);
24582463

2459-
ws.onopen = function(evt) {};
2464+
ws.addEventListener("open", function(evt) {});
24602465

2461-
ws.onmessage = (function(theSocket) {
2466+
ws.addEventListener("message", (function(theSocket) {
24622467
return function(evt) {
24632468
if (evt.data instanceof ArrayBuffer) {
24642469
var data = hcb.createArray(evt.data);
24652470
plot.push(layer_n, data);
24662471
} else if (typeof evt.data === "string") {
24672472
var Gx = plot._Gx;
2468-
var hdr = Gx.lyr[layer_n].hcb;
2473+
var hdr = plot.get_layer(layer_n).hcb;
24692474
if (!hdr) {
24702475
m.log.warning("Couldn't find header for layer " + layer_n);
24712476
}
@@ -2474,7 +2479,7 @@
24742479
plot.push(layer_n, [], newHdr);
24752480
}
24762481
};
2477-
})(ws);
2482+
})(ws));
24782483

24792484
return layer_n;
24802485
},

0 commit comments

Comments
 (0)