@dcl/ecs 7.8.15 → 7.8.16-15996225766.commit-f122eaa

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.
@@ -1,6 +1,7 @@
1
1
  import { Entity } from '../../engine/entity';
2
2
  import type { ComponentDefinition } from '../../engine';
3
3
  import { CrdtMessageType } from '../../serialization/crdt/types';
4
+ export declare const LIVEKIT_MAX_SIZE = 12;
4
5
  /**
5
6
  * @public
6
7
  */
@@ -8,6 +8,8 @@ import { CrdtMessageType } from '../../serialization/crdt/types';
8
8
  import { PutNetworkComponentOperation } from '../../serialization/crdt/network/putComponentNetwork';
9
9
  import { NetworkEntity as defineNetworkEntity, NetworkParent as defineNetworkParent, Transform as defineTransform } from '../../components';
10
10
  import * as networkUtils from '../../serialization/crdt/network/utils';
11
+ // NetworkMessages can only have a MAX_SIZE of 12kb. So we need to send it in chunks.
12
+ export const LIVEKIT_MAX_SIZE = 12;
11
13
  /**
12
14
  * @internal
13
15
  */
@@ -206,8 +208,6 @@ export function crdtSceneSystem(engine, onProcessEntityComponentChange) {
206
208
  // Send CRDT messages to transports
207
209
  const transportBuffer = new ReadWriteByteBuffer();
208
210
  for (const index in transports) {
209
- // NetworkMessages can only have a MAX_SIZE of 13kb. So we need to send it in chunks.
210
- const LIVEKIT_MAX_SIZE = 13;
211
211
  const __NetworkMessagesBuffer = [];
212
212
  const transportIndex = Number(index);
213
213
  const transport = transports[transportIndex];
@@ -218,9 +218,21 @@ export function crdtSceneSystem(engine, onProcessEntityComponentChange) {
218
218
  const buffer = new ReadWriteByteBuffer();
219
219
  // Then we send all the new crdtMessages that the transport needs to process
220
220
  for (const message of crdtMessages) {
221
- if (isNetworkTransport && transportBuffer.toBinary().byteLength / 1024 > LIVEKIT_MAX_SIZE) {
222
- __NetworkMessagesBuffer.push(transportBuffer.toBinary());
223
- transportBuffer.resetBuffer();
221
+ // Check if adding this message would exceed the size limit
222
+ const currentBufferSize = transportBuffer.toBinary().byteLength;
223
+ const messageSize = message.messageBuffer.byteLength;
224
+ if (isNetworkTransport && (currentBufferSize + messageSize) / 1024 > LIVEKIT_MAX_SIZE) {
225
+ // If the current buffer has content, save it as a chunk
226
+ if (currentBufferSize > 0) {
227
+ __NetworkMessagesBuffer.push(transportBuffer.toCopiedBinary());
228
+ transportBuffer.resetBuffer();
229
+ }
230
+ // If the message itself is larger than the limit, we need to handle it specially
231
+ // For now, we'll skip it to prevent infinite loops
232
+ if (messageSize / 1024 > LIVEKIT_MAX_SIZE) {
233
+ console.error(`Message too large (${messageSize} bytes), skipping message for entity ${message.entityId}`);
234
+ continue;
235
+ }
224
236
  }
225
237
  // Avoid echo messages
226
238
  if (message.transportId === transportIndex)
@@ -1,6 +1,7 @@
1
1
  import { Entity } from '../../engine/entity';
2
2
  import type { ComponentDefinition } from '../../engine';
3
3
  import { CrdtMessageType } from '../../serialization/crdt/types';
4
+ export declare const LIVEKIT_MAX_SIZE = 12;
4
5
  /**
5
6
  * @public
6
7
  */
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.crdtSceneSystem = void 0;
26
+ exports.crdtSceneSystem = exports.LIVEKIT_MAX_SIZE = void 0;
27
27
  const entity_1 = require("../../engine/entity");
28
28
  const ByteBuffer_1 = require("../../serialization/ByteBuffer");
29
29
  const crdt_1 = require("../../serialization/crdt");
@@ -34,6 +34,8 @@ const types_1 = require("../../serialization/crdt/types");
34
34
  const putComponentNetwork_1 = require("../../serialization/crdt/network/putComponentNetwork");
35
35
  const components_1 = require("../../components");
36
36
  const networkUtils = __importStar(require("../../serialization/crdt/network/utils"));
37
+ // NetworkMessages can only have a MAX_SIZE of 12kb. So we need to send it in chunks.
38
+ exports.LIVEKIT_MAX_SIZE = 12;
37
39
  /**
38
40
  * @internal
39
41
  */
@@ -232,8 +234,6 @@ function crdtSceneSystem(engine, onProcessEntityComponentChange) {
232
234
  // Send CRDT messages to transports
233
235
  const transportBuffer = new ByteBuffer_1.ReadWriteByteBuffer();
234
236
  for (const index in transports) {
235
- // NetworkMessages can only have a MAX_SIZE of 13kb. So we need to send it in chunks.
236
- const LIVEKIT_MAX_SIZE = 13;
237
237
  const __NetworkMessagesBuffer = [];
238
238
  const transportIndex = Number(index);
239
239
  const transport = transports[transportIndex];
@@ -244,9 +244,21 @@ function crdtSceneSystem(engine, onProcessEntityComponentChange) {
244
244
  const buffer = new ByteBuffer_1.ReadWriteByteBuffer();
245
245
  // Then we send all the new crdtMessages that the transport needs to process
246
246
  for (const message of crdtMessages) {
247
- if (isNetworkTransport && transportBuffer.toBinary().byteLength / 1024 > LIVEKIT_MAX_SIZE) {
248
- __NetworkMessagesBuffer.push(transportBuffer.toBinary());
249
- transportBuffer.resetBuffer();
247
+ // Check if adding this message would exceed the size limit
248
+ const currentBufferSize = transportBuffer.toBinary().byteLength;
249
+ const messageSize = message.messageBuffer.byteLength;
250
+ if (isNetworkTransport && (currentBufferSize + messageSize) / 1024 > exports.LIVEKIT_MAX_SIZE) {
251
+ // If the current buffer has content, save it as a chunk
252
+ if (currentBufferSize > 0) {
253
+ __NetworkMessagesBuffer.push(transportBuffer.toCopiedBinary());
254
+ transportBuffer.resetBuffer();
255
+ }
256
+ // If the message itself is larger than the limit, we need to handle it specially
257
+ // For now, we'll skip it to prevent infinite loops
258
+ if (messageSize / 1024 > exports.LIVEKIT_MAX_SIZE) {
259
+ console.error(`Message too large (${messageSize} bytes), skipping message for entity ${message.entityId}`);
260
+ continue;
261
+ }
250
262
  }
251
263
  // Avoid echo messages
252
264
  if (message.transportId === transportIndex)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dcl/ecs",
3
3
  "description": "Decentraland ECS",
4
- "version": "7.8.15",
4
+ "version": "7.8.16-15996225766.commit-f122eaa",
5
5
  "author": "DCL",
6
6
  "bugs": "https://github.com/decentraland/ecs/issues",
7
7
  "files": [
@@ -33,5 +33,5 @@
33
33
  },
34
34
  "types": "./dist/index.d.ts",
35
35
  "typings": "./dist/index.d.ts",
36
- "commit": "2c7a51eab7d18a487984332013305b2464aff729"
36
+ "commit": "f122eaa2acaaed80db7ee0302e8d60ca7d2337bf"
37
37
  }