-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebsockets.27f3fd03da7c.js
32 lines (26 loc) · 1014 Bytes
/
websockets.27f3fd03da7c.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class CeleryWebSocketProgressBar extends CeleryProgressBar {
constructor(progressUrl, options) {
super(progressUrl, options);
}
async connect() {
var ProgressSocket = new WebSocket((location.protocol === 'https:' ? 'wss' : 'ws') + '://' +
window.location.host + this.progressUrl);
ProgressSocket.onopen = function (event) {
ProgressSocket.send(JSON.stringify({'type': 'check_task_completion'}));
};
const bar = this;
ProgressSocket.onmessage = function (event) {
let data;
try {
data = JSON.parse(event.data);
} catch (parsingError) {
bar.onDataError(bar.progressBarElement, bar.progressBarMessageElement, "Parsing Error")
throw parsingError;
}
const complete = bar.onData(data);
if (complete === true || complete === undefined) {
ProgressSocket.close();
}
};
}
}