@@ -9,7 +9,8 @@ const cbstate = {
9
9
getApplicationState : async ( ) : Promise < ApplicationState > => {
10
10
return new Promise ( ( resolve , reject ) => {
11
11
cbws . getWebsocket . send ( JSON . stringify ( {
12
- "type" : "getAppState" ,
12
+ "type" : "projectStateEvent" ,
13
+ "action" : "getAppState" ,
13
14
14
15
} ) ) ;
15
16
cbws . getWebsocket . on ( 'message' , ( data : string ) => {
@@ -63,7 +64,48 @@ const cbstate = {
63
64
}
64
65
} ) ;
65
66
} ) ;
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
+ } ) ;
66
106
}
107
+
108
+
67
109
} ;
68
110
69
111
export default cbstate ;
0 commit comments