@liveblocks/core 1.3.4 → 1.3.6

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.
package/dist/index.mjs CHANGED
@@ -6,7 +6,7 @@ var __export = (target, all) => {
6
6
 
7
7
  // src/version.ts
8
8
  var PKG_NAME = "@liveblocks/core";
9
- var PKG_VERSION = "1.3.4";
9
+ var PKG_VERSION = "1.3.6";
10
10
  var PKG_FORMAT = "esm";
11
11
 
12
12
  // src/dupe-detection.ts
@@ -4596,7 +4596,7 @@ var DerivedRef = class extends ImmutableRef {
4596
4596
  };
4597
4597
 
4598
4598
  // src/room.ts
4599
- var MAX_MESSAGE_SIZE = 1024 * 1024 - 128;
4599
+ var MAX_SOCKET_MESSAGE_SIZE = 1024 * 1024 - 1024;
4600
4600
  function makeIdFactory(connectionId) {
4601
4601
  let count = 0;
4602
4602
  return () => `${connectionId}:${count++}`;
@@ -4811,17 +4811,35 @@ function createRoom(options, config) {
4811
4811
  ydoc: makeEventSource(),
4812
4812
  comments: makeEventSource()
4813
4813
  };
4814
- function sendMessages(messageOrMessages) {
4815
- const message = JSON.stringify(messageOrMessages);
4816
- if (config.unstable_fallbackToHTTP) {
4817
- const size = new TextEncoder().encode(message).length;
4818
- if (size > MAX_MESSAGE_SIZE && // TODO: support public api key auth in REST API
4819
- managedSocket.authValue?.type === "secret" && config.httpSendEndpoint) {
4814
+ async function httpSend(authTokenOrPublicApiKey, roomId, nonce, messages) {
4815
+ const baseUrl = new URL(config.liveblocksServer);
4816
+ baseUrl.protocol = "https";
4817
+ const url = new URL(
4818
+ `/v2/c/rooms/${encodeURIComponent(roomId)}/send-message`,
4819
+ baseUrl
4820
+ );
4821
+ const fetcher = config.polyfills?.fetch || /* istanbul ignore next */
4822
+ fetch;
4823
+ return fetcher(url.toString(), {
4824
+ method: "POST",
4825
+ headers: {
4826
+ "Content-Type": "application/json",
4827
+ Authorization: `Bearer ${authTokenOrPublicApiKey}`
4828
+ },
4829
+ body: JSON.stringify({ nonce, messages })
4830
+ });
4831
+ }
4832
+ function sendMessages(messages) {
4833
+ const serializedPayload = JSON.stringify(messages);
4834
+ const nonce = context.dynamicSessionInfo.current?.nonce;
4835
+ if (config.unstable_fallbackToHTTP && managedSocket.authValue && nonce) {
4836
+ const size = new TextEncoder().encode(serializedPayload).length;
4837
+ if (size > MAX_SOCKET_MESSAGE_SIZE) {
4820
4838
  void httpSend(
4821
- message,
4822
- managedSocket.authValue.token.raw,
4823
- config.httpSendEndpoint,
4824
- config.polyfills?.fetch
4839
+ managedSocket.authValue.type === "public" ? managedSocket.authValue.publicApiKey : managedSocket.authValue.token.raw,
4840
+ config.roomId,
4841
+ nonce,
4842
+ messages
4825
4843
  ).then((resp) => {
4826
4844
  if (!resp.ok && resp.status === 403) {
4827
4845
  managedSocket.reconnect();
@@ -4833,7 +4851,7 @@ function createRoom(options, config) {
4833
4851
  return;
4834
4852
  }
4835
4853
  }
4836
- managedSocket.send(message);
4854
+ managedSocket.send(serializedPayload);
4837
4855
  }
4838
4856
  const self = new DerivedRef(
4839
4857
  context.staticSessionInfo,
@@ -5133,6 +5151,7 @@ function createRoom(options, config) {
5133
5151
  function onRoomStateMessage(message, batchedUpdatesWrapper) {
5134
5152
  context.dynamicSessionInfo.set({
5135
5153
  actor: message.actor,
5154
+ nonce: message.nonce,
5136
5155
  scopes: message.scopes
5137
5156
  });
5138
5157
  context.idFactory = makeIdFactory(message.actor);
@@ -5777,18 +5796,6 @@ function makeCreateSocketDelegateForRoom(roomId, liveblocksServer, WebSocketPoly
5777
5796
  return new ws(url.toString());
5778
5797
  };
5779
5798
  }
5780
- async function httpSend(message, token, endpoint, fetchPolyfill) {
5781
- const fetcher = fetchPolyfill || /* istanbul ignore next */
5782
- fetch;
5783
- return fetcher(endpoint, {
5784
- method: "POST",
5785
- headers: {
5786
- "Content-Type": "application/json",
5787
- Authorization: `Bearer ${token}`
5788
- },
5789
- body: message
5790
- });
5791
- }
5792
5799
 
5793
5800
  // src/client.ts
5794
5801
  var MIN_THROTTLE = 16;
@@ -5844,10 +5851,6 @@ function createClient(options) {
5844
5851
  enableDebugLogging: clientOptions.enableDebugLogging,
5845
5852
  unstable_batchedUpdates: options2?.unstable_batchedUpdates,
5846
5853
  liveblocksServer: getServerFromClientOptions(clientOptions),
5847
- httpSendEndpoint: buildLiveblocksHttpSendEndpoint(
5848
- clientOptions,
5849
- roomId
5850
- ),
5851
5854
  unstable_fallbackToHTTP: !!clientOptions.unstable_fallbackToHTTP
5852
5855
  }
5853
5856
  );
@@ -5902,14 +5905,6 @@ function getLostConnectionTimeout(value) {
5902
5905
  RECOMMENDED_MIN_LOST_CONNECTION_TIMEOUT
5903
5906
  );
5904
5907
  }
5905
- function buildLiveblocksHttpSendEndpoint(options, roomId) {
5906
- if (options.httpSendEndpoint) {
5907
- return options.httpSendEndpoint.replace("{roomId}", roomId);
5908
- }
5909
- return `https://api.liveblocks.io/v2/rooms/${encodeURIComponent(
5910
- roomId
5911
- )}/send-message`;
5912
- }
5913
5908
 
5914
5909
  // src/crdts/utils.ts
5915
5910
  function toPlainLson(lson) {