@react-remote-state/client 1.1.3 → 1.1.5
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +7 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +7 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
@@ -5559,7 +5559,7 @@ function wrapReducer(reducer) {
|
|
5559
5559
|
}
|
5560
5560
|
};
|
5561
5561
|
}
|
5562
|
-
function useRemoteReducer(uri, reducer, gameId) {
|
5562
|
+
function useRemoteReducer(uri, reducer, gameId, storage = sessionStorage) {
|
5563
5563
|
let [meta, setMeta] = useState({
|
5564
5564
|
isHostReady: false,
|
5565
5565
|
isGuestReady: false
|
@@ -5572,7 +5572,9 @@ function useRemoteReducer(uri, reducer, gameId) {
|
|
5572
5572
|
};
|
5573
5573
|
useEffect(() => {
|
5574
5574
|
if (!meta.client) {
|
5575
|
-
|
5575
|
+
setMeta(__spreadProps(__spreadValues({}, meta), {
|
5576
|
+
client: socket_default.connect(uri, { transports: ["websocket"] })
|
5577
|
+
}));
|
5576
5578
|
}
|
5577
5579
|
if (!!meta.client) {
|
5578
5580
|
if (!meta.isGuestReady) {
|
@@ -5583,7 +5585,7 @@ function useRemoteReducer(uri, reducer, gameId) {
|
|
5583
5585
|
(_a = meta.client) == null ? void 0 : _a.emit("create");
|
5584
5586
|
} else if (!!gameId) {
|
5585
5587
|
let playerCache = (0, import_lodash.flow)(
|
5586
|
-
() => !!gameId ?
|
5588
|
+
() => !!gameId ? storage.getItem(gameId) : null,
|
5587
5589
|
(cache) => !!cache ? JSON.parse(cache) : null
|
5588
5590
|
)();
|
5589
5591
|
if (!!playerCache) {
|
@@ -5601,12 +5603,12 @@ function useRemoteReducer(uri, reducer, gameId) {
|
|
5601
5603
|
meta.client.on("assign", (assign) => {
|
5602
5604
|
var _a, _b;
|
5603
5605
|
setMeta(__spreadProps(__spreadValues({}, meta), { localPlayerId: assign.playerId }));
|
5604
|
-
if (!!((_a = meta == null ? void 0 : meta.client) == null ? void 0 : _a.id)
|
5606
|
+
if (!!((_a = meta == null ? void 0 : meta.client) == null ? void 0 : _a.id)) {
|
5605
5607
|
let playerCache = {
|
5606
5608
|
playerId: assign.playerId,
|
5607
5609
|
socketId: (_b = meta.client) == null ? void 0 : _b.id
|
5608
5610
|
};
|
5609
|
-
|
5611
|
+
storage.setItem(assign.gameId, JSON.stringify(playerCache));
|
5610
5612
|
}
|
5611
5613
|
});
|
5612
5614
|
meta.client.on(
|