Skip to content

Commit ea8a8aa

Browse files
authored
Fix #385 (#387)
1 parent 3887e39 commit ea8a8aa

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

django_plotly_dash/static/channels/js/websocketbridge.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,15 @@ var ReconnectingWebsocket = function (url, protocols, options) {
180180
}
181181
};
182182
this.send = function (data) {
183-
ws.send(data);
183+
if (ws.readyState == WebSocket.OPEN){
184+
ws.send(data);
185+
} else {
186+
// The websocket is not ready, so delay and try again
187+
// See: https://github.com/GibbsConsulting/django-plotly-dash/issues/385
188+
setTimeout(() => {
189+
this.send(data);
190+
}, 100);
191+
}
184192
};
185193
this.addEventListener = function (type, listener, options) {
186194
if (Array.isArray(listeners[type])) {
@@ -396,4 +404,4 @@ var WebSocketBridge = function () {
396404
exports.WebSocketBridge = WebSocketBridge;
397405

398406
},{"reconnecting-websocket":1}]},{},[2])(2)
399-
});
407+
});

0 commit comments

Comments
 (0)