@classcad/client 0.0.0-stage → 3.0.0-beta.20261119090857

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/README.md +20 -2
  2. package/bin/buerli-classcad.cjs +23 -0
  3. package/build/cjs/BuerliCadFacade.js +718 -0
  4. package/build/cjs/cclass/utils/assembly.js +687 -0
  5. package/build/cjs/cclass/utils/base.js +136 -0
  6. package/build/cjs/cclass/utils/index.js +99 -0
  7. package/build/cjs/cclass/utils/part.js +153 -0
  8. package/build/cjs/classcadEngine.js +33 -0
  9. package/build/cjs/createApi.js +71 -0
  10. package/build/cjs/createUnwrappedApi.js +43 -0
  11. package/build/cjs/facade.js +103 -0
  12. package/build/cjs/globals.js +157 -0
  13. package/build/cjs/index.js +102 -0
  14. package/build/cjs/io/AwvNodeClient.js +290 -0
  15. package/build/cjs/io/SocketIOClient.js +339 -0
  16. package/build/cjs/io/Transaction.js +134 -0
  17. package/build/cjs/io/WASMClient.js +433 -0
  18. package/build/cjs/io/WSClient.js +646 -0
  19. package/build/cjs/io/engineKey.js +202 -0
  20. package/build/cjs/re-export.js +35 -0
  21. package/build/cjs/session/host.js +479 -0
  22. package/build/cjs/session/identity.js +38 -0
  23. package/build/cjs/session/selection.js +283 -0
  24. package/build/cjs/session/share.js +229 -0
  25. package/build/cjs/session/types.js +23 -0
  26. package/build/cjs/test/SocketIOClient.spec.js +178 -0
  27. package/build/cjs/types/ComClient.js +10 -0
  28. package/build/cjs/utils/createRecursiveBufferGeometry.js +55 -0
  29. package/build/cjs/utils/createRecursiveScene.js +140 -0
  30. package/build/cjs/utils/getDifferentColoredMeshesFromEntity.js +24 -0
  31. package/build/cjs/utils/index.js +20 -0
  32. package/build/cjs/utils/polyline.js +65 -0
  33. package/build/cjs/utils/waitForSelect.js +29 -0
  34. package/build/esm/BuerliCadFacade.js +714 -0
  35. package/build/esm/cclass/utils/assembly.js +665 -0
  36. package/build/esm/cclass/utils/base.js +127 -0
  37. package/build/esm/cclass/utils/index.js +62 -0
  38. package/build/esm/cclass/utils/part.js +144 -0
  39. package/build/esm/classcadEngine.js +30 -0
  40. package/build/esm/createApi.js +66 -0
  41. package/build/esm/createUnwrappedApi.js +39 -0
  42. package/build/esm/facade.js +98 -0
  43. package/build/esm/globals.js +150 -0
  44. package/build/esm/index.js +80 -0
  45. package/build/esm/io/AwvNodeClient.js +286 -0
  46. package/build/esm/io/SocketIOClient.js +332 -0
  47. package/build/esm/io/Transaction.js +130 -0
  48. package/build/esm/io/WASMClient.js +429 -0
  49. package/build/esm/io/WSClient.js +642 -0
  50. package/build/esm/io/engineKey.js +196 -0
  51. package/build/esm/re-export.js +3 -0
  52. package/build/esm/session/host.js +474 -0
  53. package/build/esm/session/identity.js +34 -0
  54. package/build/esm/session/selection.js +277 -0
  55. package/build/esm/session/share.js +221 -0
  56. package/build/esm/session/types.js +20 -0
  57. package/build/esm/test/SocketIOClient.spec.js +178 -0
  58. package/build/esm/types/ComClient.js +7 -0
  59. package/build/esm/utils/createRecursiveBufferGeometry.js +51 -0
  60. package/build/esm/utils/createRecursiveScene.js +136 -0
  61. package/build/esm/utils/getDifferentColoredMeshesFromEntity.js +20 -0
  62. package/build/esm/utils/index.js +4 -0
  63. package/build/esm/utils/polyline.js +60 -0
  64. package/build/esm/utils/waitForSelect.js +23 -0
  65. package/build/types/BuerliCadFacade.d.ts +410 -0
  66. package/build/types/cclass/utils/assembly.d.ts +180 -0
  67. package/build/types/cclass/utils/base.d.ts +55 -0
  68. package/build/types/cclass/utils/index.d.ts +46 -0
  69. package/build/types/cclass/utils/part.d.ts +46 -0
  70. package/build/types/classcadEngine.d.ts +40 -0
  71. package/build/types/createApi.d.ts +65 -0
  72. package/build/types/createUnwrappedApi.d.ts +36 -0
  73. package/build/types/facade.d.ts +9 -0
  74. package/build/types/globals.d.ts +79 -0
  75. package/build/types/index.d.ts +82 -0
  76. package/build/types/io/AwvNodeClient.d.ts +182 -0
  77. package/build/types/io/SocketIOClient.d.ts +84 -0
  78. package/build/types/io/Transaction.d.ts +56 -0
  79. package/build/types/io/WASMClient.d.ts +239 -0
  80. package/build/types/io/WSClient.d.ts +242 -0
  81. package/build/types/io/engineKey.d.ts +137 -0
  82. package/build/types/re-export.d.ts +6 -0
  83. package/build/types/session/host.d.ts +108 -0
  84. package/build/types/session/identity.d.ts +46 -0
  85. package/build/types/session/selection.d.ts +164 -0
  86. package/build/types/session/share.d.ts +131 -0
  87. package/build/types/session/types.d.ts +113 -0
  88. package/build/types/test/SocketIOClient.spec.d.ts +0 -0
  89. package/build/types/types/ComClient.d.ts +307 -0
  90. package/build/types/utils/createRecursiveBufferGeometry.d.ts +8 -0
  91. package/build/types/utils/createRecursiveScene.d.ts +24 -0
  92. package/build/types/utils/getDifferentColoredMeshesFromEntity.d.ts +14 -0
  93. package/build/types/utils/index.d.ts +4 -0
  94. package/build/types/utils/polyline.d.ts +43 -0
  95. package/build/types/utils/waitForSelect.d.ts +4 -0
  96. package/doc/api/advanced/connection.md +488 -0
  97. package/doc/api/clients.md +2045 -0
  98. package/doc/api/engine-keys.md +230 -0
  99. package/doc/api/index.md +58 -0
  100. package/doc/api/modeling.md +682 -0
  101. package/doc/api/other.md +33 -0
  102. package/doc/api/session-sharing.md +706 -0
  103. package/package.json +59 -4
  104. package/test/classcadEngine.test.cjs +44 -0
  105. package/test/connect.test.cjs +81 -0
  106. package/test/engineKey.test.cjs +80 -0
  107. package/test/onClient.test.cjs +82 -0
  108. package/typedoc.json +8 -0
@@ -0,0 +1,332 @@
1
+ import { getDrawing } from '@classcad/sdkjs';
2
+ import io from 'socket.io-client';
3
+ import { BuerliCadFacade } from '../BuerliCadFacade';
4
+ import { MessageLevel } from '../re-export';
5
+ import { AwvNodeClient } from './AwvNodeClient';
6
+ import { Transaction } from './Transaction';
7
+ const noop = () => { };
8
+ /**
9
+ * The Socket.IO events of the ClassCAD server's protocol.
10
+ *
11
+ * @internal
12
+ */
13
+ export var SocketIOEvent;
14
+ (function (SocketIOEvent) {
15
+ SocketIOEvent["CONNECT"] = "connect";
16
+ SocketIOEvent["INIT"] = "init";
17
+ SocketIOEvent["PERMISSION"] = "permission";
18
+ SocketIOEvent["CONNECT_ERROR"] = "connect_error";
19
+ SocketIOEvent["CONNECT_TIMEOUT"] = "connect_timeout";
20
+ SocketIOEvent["SEND"] = "send";
21
+ SocketIOEvent["BINARY"] = "binary";
22
+ SocketIOEvent["JSON"] = "json";
23
+ SocketIOEvent["UNDO"] = "undo";
24
+ SocketIOEvent["REDO"] = "redo";
25
+ })(SocketIOEvent || (SocketIOEvent = {}));
26
+ /**
27
+ * Connects buerli to a ClassCAD server (`classcad-socketio`) over Socket.IO.
28
+ *
29
+ * The server runs the engine and keeps the drawing's undo history, so `undo`, `redo` and `undoable` requests work
30
+ * with this client. It cannot share its session (`shareKind` is null). When the connection drops and comes back, the
31
+ * client reconnects the drawing, recalculates it and emits `reconnect`.
32
+ *
33
+ * Its events (`connected`, `conn_error`, …) and the members all clients share are on {@link AwvNodeClient}.
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * import { init, SocketIOClient } from '@classcad/client'
38
+ *
39
+ * // The ClassCAD server (classcad-socketio); a connection that drops is picked up again
40
+ * init(drawingId => {
41
+ * const client = new SocketIOClient('ws://localhost:9091', drawingId)
42
+ * client.on('conn_error', () => notify('The connection to ClassCAD is lost'))
43
+ * client.on('reconnect', () => notify('Connected again; the model was recalculated'))
44
+ * return client
45
+ * })
46
+ * ```
47
+ * @category Clients
48
+ */
49
+ export class SocketIOClient extends AwvNodeClient {
50
+ /**
51
+ * @param url - The server's address, e.g. `ws://localhost:9091`.
52
+ * @param drawingId - The drawing the client serves (the factory given to {@link init} is called with it).
53
+ */
54
+ constructor(url, drawingId) {
55
+ super();
56
+ this.url = url;
57
+ this._transactions = new Map();
58
+ this.setDrawingId(drawingId);
59
+ }
60
+ /**
61
+ * Opens the connection, registers the drawing with the server and loads its structure tree. Rejects on a
62
+ * connection error or timeout.
63
+ */
64
+ connect() {
65
+ return new Promise(async (resolve, reject) => {
66
+ try {
67
+ this._socket = io(this.url, { transports: ['websocket', 'polling'] });
68
+ this._socket.once(SocketIOEvent.CONNECT, () => {
69
+ var _a;
70
+ (_a = this._socket) === null || _a === void 0 ? void 0 : _a.emit(SocketIOEvent.INIT, { id: this._drawingId });
71
+ });
72
+ this._socket.once(SocketIOEvent.PERMISSION, (data) => {
73
+ this._version = data.version;
74
+ // Connection is not valid until fetchTree is executed
75
+ // fetchTree has to be called right after the connection has been established
76
+ BuerliCadFacade.utils
77
+ .fetchTree(this._drawingId)
78
+ .then(() => {
79
+ this.emit('connected', this, true);
80
+ this.syncState();
81
+ resolve(this);
82
+ })
83
+ .catch(e => console.error(e));
84
+ });
85
+ this._socket.on('disconnect', (reason) => {
86
+ // https://socket.io/docs/v4/client-api/#event-disconnect
87
+ // This should prevent deliberate disconnects from triggering the reconnect logic
88
+ if (
89
+ // The server did not send a PING within the pingInterval + pingTimeout range
90
+ reason === 'ping timeout' ||
91
+ // The connection was closed (example: the user has lost connection, or the network was changed from WiFi to 4G)
92
+ reason === 'transport close' ||
93
+ // The connection has encountered an error (example: the server was killed during a HTTP long-polling cycle)
94
+ reason === 'transport error') {
95
+ this.emit('conn_error', this, reason);
96
+ }
97
+ this.syncState();
98
+ });
99
+ this._socket.io.on('reconnect', async () => {
100
+ // https://socket.io/docs/v4/client-socket-instance/#events
101
+ await BuerliCadFacade.utils.reconnect(this._drawingId);
102
+ getDrawing(this._drawingId).api.cad.clearPending();
103
+ this.emit('reconnect', this);
104
+ });
105
+ this._socket.io.on('error', (reason) => {
106
+ // Baseline websocket errors
107
+ this.syncState();
108
+ this.emit('conn_error', this, reason);
109
+ reject(reason);
110
+ });
111
+ this._socket.on(SocketIOEvent.CONNECT_ERROR, (reason) => {
112
+ this.syncState();
113
+ this.emit('conn_error', this, reason);
114
+ reject(reason);
115
+ });
116
+ this._socket.on(SocketIOEvent.CONNECT_TIMEOUT, (reason) => {
117
+ this.syncState();
118
+ this.emit('conn_timeout', this, reason);
119
+ reject(reason);
120
+ });
121
+ let current;
122
+ this._socket.on(SocketIOEvent.BINARY, (data, fn) => {
123
+ if (!this._version) {
124
+ this.ack();
125
+ } // Backward compatible ack
126
+ if (current) {
127
+ current.handleData(new Uint8Array(data));
128
+ }
129
+ if (fn) {
130
+ fn('ack');
131
+ } // Newer awv3-node 8.x.x ack
132
+ });
133
+ this._socket.on(SocketIOEvent.JSON, (data, fn) => {
134
+ if (!this._version) {
135
+ this.ack();
136
+ } // Backward compatible ack
137
+ if (data.from === 'BeginFrame') {
138
+ current = this._transactions.get(data.transactionID);
139
+ }
140
+ if (current) {
141
+ current.handleData(data);
142
+ }
143
+ if (current && data.from === 'EndFrame' && data.transactionID === current.transactionID) {
144
+ this._transactions.delete(current.transactionID);
145
+ current = undefined;
146
+ }
147
+ if (fn) {
148
+ fn('ack');
149
+ } // Newer awv3-node 8.x.x ack
150
+ });
151
+ this._socket.on(SocketIOEvent.UNDO, (args) => {
152
+ // TODO: Remove conditional branch if (args.stack !== undefined), if we're sure no old
153
+ // classcad-node packages are used anymore. This conditional branch is only used to avoid
154
+ // that captionMap will be overfilled and never deleted. If args.stack === undefined we know, that an
155
+ // old classcad-node package is used.
156
+ if (args.stack !== undefined) {
157
+ const captionMap = getDrawing(this._drawingId).cad.states.captionMap;
158
+ const tempCaptionMap = {};
159
+ if (args.id) {
160
+ // Add current state to caption map with key = args.id
161
+ // If it was an instance change and the state was stored automatically, no caption is available then,
162
+ // we will use 'Instance changed' for caption value
163
+ const caption = args.id.includes('instanceChange')
164
+ ? 'Instance changed'
165
+ : captionMap[args.id].caption;
166
+ tempCaptionMap[args.id] = { caption: caption, stateName: args.current, undoable: args.undoable };
167
+ // Iterate over all others and add existing ones also to the map
168
+ for (const key in captionMap) {
169
+ if (key !== args.id) {
170
+ if (args.stack.includes(captionMap[key].stateName) || captionMap[key].stateName === '') {
171
+ tempCaptionMap[key] = captionMap[key];
172
+ }
173
+ }
174
+ }
175
+ getDrawing(this._drawingId).api.cad.setStates(Number.parseInt(args.current), args.stack, tempCaptionMap);
176
+ }
177
+ else {
178
+ getDrawing(this._drawingId).api.cad.setStates(Number.parseInt(args.current), args.stack, captionMap);
179
+ }
180
+ }
181
+ else {
182
+ getDrawing(this._drawingId).api.cad.setStates(0, args.stack, {});
183
+ }
184
+ });
185
+ }
186
+ catch (error) {
187
+ reject(error);
188
+ }
189
+ });
190
+ }
191
+ /** Closes the connection to the server. */
192
+ disconnect() {
193
+ return new Promise(async (resolve, reject) => {
194
+ try {
195
+ this._socket && this._socket.close();
196
+ resolve(this);
197
+ }
198
+ catch (error) {
199
+ reject(error);
200
+ }
201
+ });
202
+ }
203
+ /**
204
+ * Sends `command` to the server as the event `name` and resolves to the reply once all its frames have arrived.
205
+ * Structure patches and graphic go into the drawing on the way. Rejects with the reply when it carries an error.
206
+ *
207
+ * @param name - The server's event: `send` for requests, `undo`, `redo`.
208
+ * @param command - The request.
209
+ */
210
+ requestByName(name, command) {
211
+ // TODO: handle request by request, and wait with next request until current finished.
212
+ return new Promise((resolve, reject) => {
213
+ var _a;
214
+ const tr = new Transaction();
215
+ try {
216
+ tr.on('result', value => {
217
+ if (value.command === 'Result' && value.from === 'GetTree') {
218
+ getDrawing(this._drawingId).api.structure.set(value.result);
219
+ }
220
+ })
221
+ .on('patches', patches => {
222
+ getDrawing(this._drawingId).api.structure.applyPatches(patches);
223
+ })
224
+ .on('blob', blob => {
225
+ getDrawing(this._drawingId).api.graphic.addPackages([blob.data]);
226
+ })
227
+ .on('error', error => {
228
+ // Nothing to do
229
+ })
230
+ .on('finished', (data) => {
231
+ var _a, _b, _c, _d, _e, _f;
232
+ // Transform the "old" ClassCAD response to the new ClassCAD response format introduced by api.v1.
233
+ // There is always only one result expected per command!
234
+ const result = (_a = data.results[0]) === null || _a === void 0 ? void 0 : _a.result;
235
+ let jobResult = result;
236
+ if (typeof ((_c = (_b = data.results[0]) === null || _b === void 0 ? void 0 : _b.result) === null || _c === void 0 ? void 0 : _c.result) !== 'undefined') {
237
+ jobResult = (_e = (_d = data.results[0]) === null || _d === void 0 ? void 0 : _d.result) === null || _e === void 0 ? void 0 : _e.result;
238
+ }
239
+ const streamData = (result === null || result === void 0 ? void 0 : result.streamData) || ((_f = data.results[0]) === null || _f === void 0 ? void 0 : _f.streamData);
240
+ const messages = (result === null || result === void 0 ? void 0 : result.messages) || data.messages || [];
241
+ const oldErrors = (result === null || result === void 0 ? void 0 : result.errors) || data.errors;
242
+ if (oldErrors) {
243
+ for (const oldError of oldErrors) {
244
+ let level = MessageLevel.info;
245
+ // errorState --> 0:eCCNoError, 1:eCCErrorWarning, 2:eCCErrorGoOn, 3:eCCErrorStop
246
+ switch (oldError.errorState) {
247
+ case 1:
248
+ level = MessageLevel.warning;
249
+ break;
250
+ case 2:
251
+ case 3:
252
+ case 4:
253
+ level = MessageLevel.error;
254
+ break;
255
+ default:
256
+ break;
257
+ }
258
+ messages.push({ code: oldError.errorCode, message: oldError.errorMessage, level, api: '' }); // TODO: remove api from
259
+ }
260
+ }
261
+ let maxLevel = undefined;
262
+ for (const message of messages) {
263
+ if (!maxLevel || message.level > maxLevel) {
264
+ maxLevel = message.level;
265
+ }
266
+ }
267
+ const sr = { result: jobResult, maxLevel, messages, streamData };
268
+ const hadError = typeof sr.maxLevel !== 'undefined' && sr.maxLevel >= MessageLevel.error;
269
+ if (hadError) {
270
+ reject(sr);
271
+ }
272
+ else {
273
+ resolve(sr);
274
+ }
275
+ });
276
+ this._transactions.set(tr.transactionID, tr);
277
+ // this.emit("requestStarted", this);
278
+ // If undoable flag is set, save current command with transactionId to the caption map
279
+ // After response from classcad-node state name will also be added to caption map
280
+ if ((_a = command === null || command === void 0 ? void 0 : command.options) === null || _a === void 0 ? void 0 : _a.undoable) {
281
+ if (command === null || command === void 0 ? void 0 : command.task) {
282
+ const tempCaptionMap = {};
283
+ const captionMap = getDrawing(this._drawingId).cad.states.captionMap;
284
+ // Add new caption with empty state name to the temp map, correct state name will be added later
285
+ tempCaptionMap[tr.transactionID] = { stateName: '', caption: Object.keys(command === null || command === void 0 ? void 0 : command.task[0])[0] };
286
+ // Add existing elements of caption map to the temporary map
287
+ for (const key in captionMap) {
288
+ tempCaptionMap[key] = captionMap[key];
289
+ }
290
+ getDrawing(this._drawingId).api.cad.setCaptionMap(tempCaptionMap);
291
+ }
292
+ }
293
+ this._socket && this._socket.emit(name, tr.transactionID, command);
294
+ }
295
+ catch (error) {
296
+ reject(error);
297
+ }
298
+ });
299
+ }
300
+ request(command) {
301
+ return this.requestByName(SocketIOEvent.SEND, command);
302
+ }
303
+ /**
304
+ * Steps back in the drawing's undo history on the server: to `options.state` when given.
305
+ *
306
+ * @param options - The state to go back to, and options for the server.
307
+ */
308
+ undo(options) {
309
+ // Using command object in redo actually not necessary, but we can use
310
+ // RequestOptions for undo options and have a clean structure, like common requests
311
+ return this.requestByName(SocketIOEvent.UNDO, { command: '', options });
312
+ }
313
+ /**
314
+ * Steps forward in the drawing's undo history on the server: to `options.state` when given.
315
+ *
316
+ * @param options - The state to go forward to, and options for the server.
317
+ */
318
+ redo(options) {
319
+ // Using command object in redo actually not necessary, but we can use
320
+ // RequestOptions for redo options and have a clean structure, like common requests
321
+ return this.requestByName(SocketIOEvent.REDO, { command: '', options });
322
+ }
323
+ ack() {
324
+ this._socket ? this._socket.emit('received') : noop();
325
+ }
326
+ syncState() {
327
+ var _a, _b, _c, _d, _e, _f;
328
+ const dr = getDrawing(this._drawingId);
329
+ (_b = (_a = dr === null || dr === void 0 ? void 0 : dr.api) === null || _a === void 0 ? void 0 : _a.cad) === null || _b === void 0 ? void 0 : _b.setActive(Boolean((_c = this._socket) === null || _c === void 0 ? void 0 : _c.active));
330
+ (_e = (_d = dr === null || dr === void 0 ? void 0 : dr.api) === null || _d === void 0 ? void 0 : _d.cad) === null || _e === void 0 ? void 0 : _e.setConnected(Boolean((_f = this._socket) === null || _f === void 0 ? void 0 : _f.connected));
331
+ }
332
+ }
@@ -0,0 +1,130 @@
1
+ import { decode } from 'base64-arraybuffer';
2
+ import { EventEmitter } from 'events';
3
+ import { inflate } from 'pako';
4
+ import { v4 as uuidv4 } from 'uuid';
5
+ export class Transaction extends EventEmitter {
6
+ constructor(transactionID = uuidv4()) {
7
+ super();
8
+ this.transactionID = transactionID;
9
+ // Bytes processed (compressed)
10
+ this.bytes = 0;
11
+ // Bytes processed (uncompressed)
12
+ this.bytesUncompressed = 0;
13
+ // Parsing time
14
+ this.time = 0;
15
+ // The results
16
+ this.results = [];
17
+ // The patches
18
+ this.patches = [];
19
+ // The blobs
20
+ this.blobs = [];
21
+ // The errors
22
+ this.errors = [];
23
+ // The messages
24
+ this.messages = [];
25
+ }
26
+ handleData(data) {
27
+ // TODO: Why double negation --> Ask Paul
28
+ if (data.type === 'Buffer' && !!data.data) {
29
+ // Node Buffer
30
+ data = Uint8Array.from(data.data);
31
+ }
32
+ if (data instanceof Uint8Array) {
33
+ // Wrap binary data into json Blob
34
+ data = {
35
+ command: 'Blob',
36
+ type: 'Binary',
37
+ data,
38
+ };
39
+ }
40
+ if (typeof data === 'string' || data instanceof String) {
41
+ // Plain text package
42
+ const length = data.length;
43
+ data = JSON.parse(data);
44
+ this.bytes += length;
45
+ if (data.command !== 'Blob') {
46
+ this.bytesUncompressed += length;
47
+ }
48
+ }
49
+ if (Array.isArray(data)) {
50
+ // TODO: Why array, possible? Ask Paul.
51
+ // Collection of commands
52
+ data.forEach(item => this.handleItem(item));
53
+ }
54
+ else {
55
+ this.handleItem(data);
56
+ }
57
+ }
58
+ handleItem(object) {
59
+ if (object.from === 'EndFrame' && object.transactionID === this.transactionID) {
60
+ this.emit('finished', {
61
+ results: this.results,
62
+ patches: this.patches,
63
+ blobs: this.blobs,
64
+ errors: this.errors,
65
+ messages: this.messages,
66
+ });
67
+ }
68
+ else if (object.command === 'Endpoint') {
69
+ // TODO: What is an EndPoint? Ask Paul.
70
+ // Scaled endpoints
71
+ const res = Object.assign(Object.assign({}, object), { command: 'Result', from: 'ip' }); // TODO: ???
72
+ this.results.push(res);
73
+ this.emit('result', res);
74
+ }
75
+ else if (object.command === 'Blob') {
76
+ let stream = object.data;
77
+ // TimeMeasMap.get().startTimeMeas(`unpack-${this.transactionID}`);
78
+ if (!(stream instanceof Uint8Array)) {
79
+ stream = decode(stream);
80
+ }
81
+ const blob = {
82
+ command: 'Blob',
83
+ type: 'Binary',
84
+ data: JSON.parse(inflate(stream, { raw: true, to: 'string' })),
85
+ size: stream.length,
86
+ };
87
+ // TimeMeasMap.get().stopTimeMeas(`unpack-${this.transactionID}`);
88
+ this.blobs.push(blob);
89
+ this.emit('blob', blob);
90
+ }
91
+ else if (object.command === 'Result' && object.from !== 'BeginFrame' && object.from !== 'EndFrame') {
92
+ try {
93
+ if (typeof object.result === 'string') {
94
+ const json = JSON.parse(object.result);
95
+ object.result = json;
96
+ }
97
+ }
98
+ catch (e) { }
99
+ let inflatedStreams;
100
+ const inputStreams = object.streamData;
101
+ if (inputStreams) {
102
+ inflatedStreams = {};
103
+ Object.getOwnPropertyNames(inputStreams).forEach(key => {
104
+ let stream = inputStreams[key];
105
+ if (!(stream instanceof Uint8Array)) {
106
+ stream = decode(stream);
107
+ }
108
+ inflatedStreams[key] = inflate(stream, { raw: true });
109
+ });
110
+ }
111
+ const res = Object.assign(Object.assign({}, object), { command: 'Result', streamData: inflatedStreams });
112
+ this.results.push(res);
113
+ this.emit('result', res);
114
+ }
115
+ else if (object.command === 'Patch') {
116
+ this.patches = [...this.patches, ...object.ops];
117
+ this.emit('patches', object.ops);
118
+ }
119
+ else if (object.command === 'ErrorMessage') {
120
+ // ClassCAD error messages
121
+ this.errors.push(object.attributes);
122
+ this.emit('error', object.attributes);
123
+ }
124
+ else if (object.command === 'InfoMessage') {
125
+ // ClassCAD info messages
126
+ this.messages.push(object.attributes);
127
+ this.emit('message', object.attributes);
128
+ }
129
+ }
130
+ }