@liveblocks/client 0.15.6 → 0.15.9

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/lib/esm/index.js CHANGED
@@ -1595,6 +1595,18 @@ var __spreadValues$1 = (a, b) => {
1595
1595
  return a;
1596
1596
  };
1597
1597
  var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
1598
+ var __objRest = (source, exclude) => {
1599
+ var target = {};
1600
+ for (var prop in source)
1601
+ if (__hasOwnProp$1.call(source, prop) && exclude.indexOf(prop) < 0)
1602
+ target[prop] = source[prop];
1603
+ if (source != null && __getOwnPropSymbols$1)
1604
+ for (var prop of __getOwnPropSymbols$1(source)) {
1605
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$1.call(source, prop))
1606
+ target[prop] = source[prop];
1607
+ }
1608
+ return target;
1609
+ };
1598
1610
  const BACKOFF_RETRY_DELAYS = [250, 500, 1e3, 2e3, 4e3, 8e3, 1e4];
1599
1611
  const BACKOFF_RETRY_DELAYS_SLOW = [2e3, 3e4, 6e4, 3e5];
1600
1612
  const HEARTBEAT_INTERVAL = 3e4;
@@ -1607,21 +1619,15 @@ function makeIdFactory(connectionId) {
1607
1619
  return () => `${connectionId}:${count++}`;
1608
1620
  }
1609
1621
  function makeOthers(presenceMap) {
1610
- const array = Object.values(presenceMap);
1611
- return {
1612
- get count() {
1613
- return array.length;
1614
- },
1615
- [Symbol.iterator]() {
1616
- return array[Symbol.iterator]();
1617
- },
1618
- map(callback) {
1619
- return array.map(callback);
1620
- },
1621
- toArray() {
1622
- return array;
1623
- }
1624
- };
1622
+ const array = Object.values(presenceMap).map((presence) => {
1623
+ const _a = presence, publicKeys = __objRest(_a, ["_hasReceivedInitialPresence"]);
1624
+ return publicKeys;
1625
+ });
1626
+ const arrayish = Object.assign(array, {
1627
+ count: array.length,
1628
+ toArray: () => array
1629
+ });
1630
+ return Object.freeze(arrayish);
1625
1631
  }
1626
1632
  function makeStateMachine(state, context, mockedEffects) {
1627
1633
  const effects = mockedEffects || {
@@ -2002,17 +2008,22 @@ See v0.13 release notes for more information.
2002
2008
  }
2003
2009
  function onUpdatePresenceMessage(message) {
2004
2010
  const user = state.users[message.actor];
2011
+ if (message.targetActor === void 0 && user != null && !user._hasReceivedInitialPresence) {
2012
+ return void 0;
2013
+ }
2005
2014
  if (user == null) {
2006
2015
  state.users[message.actor] = {
2007
2016
  connectionId: message.actor,
2008
- presence: message.data
2017
+ presence: message.data,
2018
+ _hasReceivedInitialPresence: true
2009
2019
  };
2010
2020
  } else {
2011
2021
  state.users[message.actor] = {
2012
2022
  id: user.id,
2013
2023
  info: user.info,
2014
2024
  connectionId: message.actor,
2015
- presence: __spreadValues$1(__spreadValues$1({}, user.presence), message.data)
2025
+ presence: __spreadValues$1(__spreadValues$1({}, user.presence), message.data),
2026
+ _hasReceivedInitialPresence: true
2016
2027
  };
2017
2028
  }
2018
2029
  return {
@@ -2058,7 +2069,8 @@ See v0.13 release notes for more information.
2058
2069
  state.users[message.actor] = {
2059
2070
  connectionId: message.actor,
2060
2071
  info: message.info,
2061
- id: message.id
2072
+ id: message.id,
2073
+ _hasReceivedInitialPresence: true
2062
2074
  };
2063
2075
  if (state.me) {
2064
2076
  state.buffer.messages.push({
@@ -2093,7 +2105,10 @@ See v0.13 release notes for more information.
2093
2105
  break;
2094
2106
  }
2095
2107
  case ServerMessageType.UpdatePresence: {
2096
- updates.others.push(onUpdatePresenceMessage(subMessage));
2108
+ const othersPresenceUpdate = onUpdatePresenceMessage(subMessage);
2109
+ if (othersPresenceUpdate) {
2110
+ updates.others.push(othersPresenceUpdate);
2111
+ }
2097
2112
  break;
2098
2113
  }
2099
2114
  case ServerMessageType.Event: {
package/lib/esm/index.mjs CHANGED
@@ -1595,6 +1595,18 @@ var __spreadValues$1 = (a, b) => {
1595
1595
  return a;
1596
1596
  };
1597
1597
  var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
1598
+ var __objRest = (source, exclude) => {
1599
+ var target = {};
1600
+ for (var prop in source)
1601
+ if (__hasOwnProp$1.call(source, prop) && exclude.indexOf(prop) < 0)
1602
+ target[prop] = source[prop];
1603
+ if (source != null && __getOwnPropSymbols$1)
1604
+ for (var prop of __getOwnPropSymbols$1(source)) {
1605
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$1.call(source, prop))
1606
+ target[prop] = source[prop];
1607
+ }
1608
+ return target;
1609
+ };
1598
1610
  const BACKOFF_RETRY_DELAYS = [250, 500, 1e3, 2e3, 4e3, 8e3, 1e4];
1599
1611
  const BACKOFF_RETRY_DELAYS_SLOW = [2e3, 3e4, 6e4, 3e5];
1600
1612
  const HEARTBEAT_INTERVAL = 3e4;
@@ -1607,21 +1619,15 @@ function makeIdFactory(connectionId) {
1607
1619
  return () => `${connectionId}:${count++}`;
1608
1620
  }
1609
1621
  function makeOthers(presenceMap) {
1610
- const array = Object.values(presenceMap);
1611
- return {
1612
- get count() {
1613
- return array.length;
1614
- },
1615
- [Symbol.iterator]() {
1616
- return array[Symbol.iterator]();
1617
- },
1618
- map(callback) {
1619
- return array.map(callback);
1620
- },
1621
- toArray() {
1622
- return array;
1623
- }
1624
- };
1622
+ const array = Object.values(presenceMap).map((presence) => {
1623
+ const _a = presence, publicKeys = __objRest(_a, ["_hasReceivedInitialPresence"]);
1624
+ return publicKeys;
1625
+ });
1626
+ const arrayish = Object.assign(array, {
1627
+ count: array.length,
1628
+ toArray: () => array
1629
+ });
1630
+ return Object.freeze(arrayish);
1625
1631
  }
1626
1632
  function makeStateMachine(state, context, mockedEffects) {
1627
1633
  const effects = mockedEffects || {
@@ -2002,17 +2008,22 @@ See v0.13 release notes for more information.
2002
2008
  }
2003
2009
  function onUpdatePresenceMessage(message) {
2004
2010
  const user = state.users[message.actor];
2011
+ if (message.targetActor === void 0 && user != null && !user._hasReceivedInitialPresence) {
2012
+ return void 0;
2013
+ }
2005
2014
  if (user == null) {
2006
2015
  state.users[message.actor] = {
2007
2016
  connectionId: message.actor,
2008
- presence: message.data
2017
+ presence: message.data,
2018
+ _hasReceivedInitialPresence: true
2009
2019
  };
2010
2020
  } else {
2011
2021
  state.users[message.actor] = {
2012
2022
  id: user.id,
2013
2023
  info: user.info,
2014
2024
  connectionId: message.actor,
2015
- presence: __spreadValues$1(__spreadValues$1({}, user.presence), message.data)
2025
+ presence: __spreadValues$1(__spreadValues$1({}, user.presence), message.data),
2026
+ _hasReceivedInitialPresence: true
2016
2027
  };
2017
2028
  }
2018
2029
  return {
@@ -2058,7 +2069,8 @@ See v0.13 release notes for more information.
2058
2069
  state.users[message.actor] = {
2059
2070
  connectionId: message.actor,
2060
2071
  info: message.info,
2061
- id: message.id
2072
+ id: message.id,
2073
+ _hasReceivedInitialPresence: true
2062
2074
  };
2063
2075
  if (state.me) {
2064
2076
  state.buffer.messages.push({
@@ -2093,7 +2105,10 @@ See v0.13 release notes for more information.
2093
2105
  break;
2094
2106
  }
2095
2107
  case ServerMessageType.UpdatePresence: {
2096
- updates.others.push(onUpdatePresenceMessage(subMessage));
2108
+ const othersPresenceUpdate = onUpdatePresenceMessage(subMessage);
2109
+ if (othersPresenceUpdate) {
2110
+ updates.others.push(othersPresenceUpdate);
2111
+ }
2097
2112
  break;
2098
2113
  }
2099
2114
  case ServerMessageType.Event: {
package/lib/index.d.ts CHANGED
@@ -232,27 +232,20 @@ declare type Client = {
232
232
  */
233
233
  leave(roomId: string): void;
234
234
  };
235
- /**
236
- * Represents all the other users connected in the room. Treated as immutable.
237
- */
238
- interface Others<TPresence extends Presence = Presence> {
235
+ declare type ReadonlyArrayWithLegacyMethods<T> = readonly T[] & {
239
236
  /**
240
- * Number of other users in the room.
237
+ * @deprecated Prefer the normal .length property on arrays.
241
238
  */
242
239
  readonly count: number;
243
240
  /**
244
- * Returns a new Iterator object that contains the users.
245
- */
246
- [Symbol.iterator](): IterableIterator<User<TPresence>>;
247
- /**
248
- * Returns the array of connected users in room.
249
- */
250
- toArray(): User<TPresence>[];
251
- /**
252
- * This function let you map over the connected users in the room.
241
+ * @deprecated Calling .toArray() is no longer needed
253
242
  */
254
- map<U>(callback: (user: User<TPresence>) => U): U[];
255
- }
243
+ toArray(): T[];
244
+ };
245
+ /**
246
+ * A read-only array containing all other users connected to the room.
247
+ */
248
+ declare type Others<P extends Presence = Presence> = ReadonlyArrayWithLegacyMethods<User<P>>;
256
249
  /**
257
250
  * Represents a user connected in a room. Treated as immutable.
258
251
  */
package/lib/index.js CHANGED
@@ -127,6 +127,21 @@ function _wrapNativeSuper(Class) {
127
127
  return _wrapNativeSuper(Class);
128
128
  }
129
129
 
130
+ function _objectWithoutPropertiesLoose(source, excluded) {
131
+ if (source == null) return {};
132
+ var target = {};
133
+ var sourceKeys = Object.keys(source);
134
+ var key, i;
135
+
136
+ for (i = 0; i < sourceKeys.length; i++) {
137
+ key = sourceKeys[i];
138
+ if (excluded.indexOf(key) >= 0) continue;
139
+ target[key] = source[key];
140
+ }
141
+
142
+ return target;
143
+ }
144
+
130
145
  function _assertThisInitialized(self) {
131
146
  if (self === void 0) {
132
147
  throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
@@ -2415,28 +2430,26 @@ function makeIdFactory(connectionId) {
2415
2430
  }
2416
2431
 
2417
2432
  function makeOthers(presenceMap) {
2418
- var _ref;
2433
+ var array = Object.values(presenceMap).map(function (presence) {
2434
+ presence._hasReceivedInitialPresence;
2435
+ var publicKeys = _objectWithoutPropertiesLoose(presence, ["_hasReceivedInitialPresence"]);
2419
2436
 
2420
- var array = Object.values(presenceMap);
2421
- return _ref = {
2422
- get count() {
2423
- return array.length;
2437
+ return publicKeys;
2438
+ });
2439
+ var arrayish = Object.assign(array, {
2440
+ count: array.length,
2441
+ toArray: function toArray() {
2442
+ return array;
2424
2443
  }
2425
-
2426
- }, _ref[Symbol.iterator] = function () {
2427
- return array[Symbol.iterator]();
2428
- }, _ref.map = function map(callback) {
2429
- return array.map(callback);
2430
- }, _ref.toArray = function toArray() {
2431
- return array;
2432
- }, _ref;
2444
+ });
2445
+ return Object.freeze(arrayish);
2433
2446
  }
2434
2447
 
2435
2448
  function makeStateMachine(state, context, mockedEffects) {
2436
2449
  var effects = mockedEffects || {
2437
2450
  authenticate: function authenticate(auth, createWebSocket) {
2438
- return auth(context.room).then(function (_ref2) {
2439
- var token = _ref2.token;
2451
+ return auth(context.room).then(function (_ref) {
2452
+ var token = _ref.token;
2440
2453
 
2441
2454
  if (state.connection.state !== "authenticating") {
2442
2455
  return;
@@ -2622,13 +2635,13 @@ function makeStateMachine(state, context, mockedEffects) {
2622
2635
  }
2623
2636
  }
2624
2637
 
2625
- function notify(_ref3) {
2626
- var _ref3$storageUpdates = _ref3.storageUpdates,
2627
- storageUpdates = _ref3$storageUpdates === void 0 ? new Map() : _ref3$storageUpdates,
2628
- _ref3$presence = _ref3.presence,
2629
- presence = _ref3$presence === void 0 ? false : _ref3$presence,
2630
- _ref3$others = _ref3.others,
2631
- others = _ref3$others === void 0 ? [] : _ref3$others;
2638
+ function notify(_ref2) {
2639
+ var _ref2$storageUpdates = _ref2.storageUpdates,
2640
+ storageUpdates = _ref2$storageUpdates === void 0 ? new Map() : _ref2$storageUpdates,
2641
+ _ref2$presence = _ref2.presence,
2642
+ presence = _ref2$presence === void 0 ? false : _ref2$presence,
2643
+ _ref2$others = _ref2.others,
2644
+ others = _ref2$others === void 0 ? [] : _ref2$others;
2632
2645
 
2633
2646
  if (others.length > 0) {
2634
2647
  state.others = makeOthers(state.users);
@@ -2966,17 +2979,23 @@ function makeStateMachine(state, context, mockedEffects) {
2966
2979
  function onUpdatePresenceMessage(message) {
2967
2980
  var user = state.users[message.actor];
2968
2981
 
2982
+ if (message.targetActor === undefined && user != null && !user._hasReceivedInitialPresence) {
2983
+ return undefined;
2984
+ }
2985
+
2969
2986
  if (user == null) {
2970
2987
  state.users[message.actor] = {
2971
2988
  connectionId: message.actor,
2972
- presence: message.data
2989
+ presence: message.data,
2990
+ _hasReceivedInitialPresence: true
2973
2991
  };
2974
2992
  } else {
2975
2993
  state.users[message.actor] = {
2976
2994
  id: user.id,
2977
2995
  info: user.info,
2978
2996
  connectionId: message.actor,
2979
- presence: _extends({}, user.presence, message.data)
2997
+ presence: _extends({}, user.presence, message.data),
2998
+ _hasReceivedInitialPresence: true
2980
2999
  };
2981
3000
  }
2982
3001
 
@@ -3043,7 +3062,8 @@ function makeStateMachine(state, context, mockedEffects) {
3043
3062
  state.users[message.actor] = {
3044
3063
  connectionId: message.actor,
3045
3064
  info: message.info,
3046
- id: message.id
3065
+ id: message.id,
3066
+ _hasReceivedInitialPresence: true
3047
3067
  };
3048
3068
 
3049
3069
  if (state.me) {
@@ -3093,7 +3113,12 @@ function makeStateMachine(state, context, mockedEffects) {
3093
3113
 
3094
3114
  case ServerMessageType.UpdatePresence:
3095
3115
  {
3096
- updates.others.push(onUpdatePresenceMessage(subMessage));
3116
+ var othersPresenceUpdate = onUpdatePresenceMessage(subMessage);
3117
+
3118
+ if (othersPresenceUpdate) {
3119
+ updates.others.push(othersPresenceUpdate);
3120
+ }
3121
+
3097
3122
  break;
3098
3123
  }
3099
3124
 
package/lib/internal.d.ts CHANGED
@@ -25,6 +25,7 @@ declare type UpdatePresenceMessage = {
25
25
  type: ServerMessageType.UpdatePresence;
26
26
  actor: number;
27
27
  data: Presence;
28
+ targetActor?: number;
28
29
  };
29
30
  declare type UserJoinMessage = {
30
31
  type: ServerMessageType.UserJoined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liveblocks/client",
3
- "version": "0.15.6",
3
+ "version": "0.15.9",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -65,4 +65,4 @@
65
65
  "url": "https://github.com/liveblocks/liveblocks.git",
66
66
  "directory": "packages/liveblocks-client"
67
67
  }
68
- }
68
+ }