Skip to content

Commit 7a909e4

Browse files
committed
add queue system
1 parent 319f9fe commit 7a909e4

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/classes/CloudConnection.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ class CloudConnection {
99
session: Session;
1010
server: string;
1111
connection: WebSocket;
12+
open: boolean = false;
13+
private queue: Array<{
14+
user: string;
15+
method: string;
16+
name: string;
17+
value: string | number;
18+
project_id: number;
19+
}> = [];
1220
variables: object = {};
1321
disconnected: boolean = false;
1422
constructor({
@@ -28,6 +36,7 @@ class CloudConnection {
2836
}
2937

3038
private connect() {
39+
this.open = false;
3140
this.connection = new WebSocket(this.server, {
3241
headers: {
3342
Cookie: this.session.cookieSet,
@@ -44,11 +53,16 @@ class CloudConnection {
4453
}
4554
});
4655
this.connection.on("open", () => {
56+
this.open = true;
4757
this.send({
4858
method: "handshake",
4959
user: this.session.sessionJSON.user.username,
5060
project_id: this.id.toString()
5161
});
62+
// handle queue
63+
for (let item of this.queue) {
64+
this.send(item);
65+
}
5266
});
5367
this.connection.on("error", (err) => {
5468
throw err;
@@ -75,6 +89,16 @@ class CloudConnection {
7589
? variable.substring(2)
7690
: variable;
7791
this.variables[`☁ ${varname}`] = value;
92+
if (!this.open) {
93+
this.queue.push({
94+
user: this.session.sessionJSON.user.username,
95+
method: "set",
96+
name: `☁ ${varname}`,
97+
value: value.toString(),
98+
project_id: this.id
99+
});
100+
return;
101+
}
78102
this.send({
79103
user: this.session.sessionJSON.user.username,
80104
method: "set",

0 commit comments

Comments
 (0)