Skip to content

Commit c2f0a1b

Browse files
changes
1 parent e5d5ec1 commit c2f0a1b

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ node_modules
33
# modules
44
# index.js
55
# index.d.ts
6+
.codeboltAgents

src/modules/state.ts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ const cbstate = {
99
getApplicationState: async (): Promise<ApplicationState> => {
1010
return new Promise((resolve, reject) => {
1111
cbws.getWebsocket.send(JSON.stringify({
12-
"type": "getAppState",
12+
"type": "projectStateEvent",
13+
"action": "getAppState",
1314

1415
}));
1516
cbws.getWebsocket.on('message', (data: string) => {
@@ -63,7 +64,48 @@ const cbstate = {
6364
}
6465
});
6566
});
67+
},
68+
69+
70+
/**
71+
* Retrieves the current project state from the server via WebSocket.
72+
* @returns {Promise<GetProjectStateResponse>} A promise that resolves with the project's state.
73+
*/
74+
getProjectState: async (): Promise<any> => {
75+
return new Promise((resolve, reject) => {
76+
cbws.getWebsocket.send(JSON.stringify({
77+
"type": "projectStateEvent",
78+
"action": "getProjectState",
79+
}));
80+
cbws.getWebsocket.on('message', (data: string) => {
81+
const response = JSON.parse(data);
82+
if (response.type === "getProjectStateResponse") {
83+
resolve(response); // Resolve the Promise with the response data
84+
}
85+
});
86+
});
87+
},
88+
89+
/**
90+
* Updates the project state on the server via WebSocket.
91+
* @returns {Promise<UpdateProjectStateResponse>} A promise that resolves with the response to the update request.
92+
*/
93+
updateProjectState: async (): Promise<any> => {
94+
return new Promise((resolve, reject) => {
95+
cbws.getWebsocket.send(JSON.stringify({
96+
"type": "projectStateEvent",
97+
"action": "updateProjectState",
98+
}));
99+
cbws.getWebsocket.on('message', (data: string) => {
100+
const response = JSON.parse(data);
101+
if (response.type === "updateProjectStateResponse") {
102+
resolve(response); // Resolve the Promise with the response data
103+
}
104+
});
105+
});
66106
}
107+
108+
67109
};
68110

69111
export default cbstate;

0 commit comments

Comments
 (0)