@beta-gamer/react-native 0.1.1 → 0.1.3

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 (2) hide show
  1. package/dist/index.js +26 -4
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -43,9 +43,31 @@ module.exports = __toCommonJS(index_exports);
43
43
  var import_react = require("react");
44
44
  var import_socket = require("socket.io-client");
45
45
  var import_jsx_runtime = require("react/jsx-runtime");
46
+ function base64Decode(str) {
47
+ const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
48
+ const normalized = str.replace(/-/g, "+").replace(/_/g, "/");
49
+ let output = "";
50
+ let i = 0;
51
+ while (i < normalized.length) {
52
+ const e1 = chars.indexOf(normalized[i++]);
53
+ const e2 = chars.indexOf(normalized[i++]);
54
+ const e3 = chars.indexOf(normalized[i++]);
55
+ const e4 = chars.indexOf(normalized[i++]);
56
+ output += String.fromCharCode(e1 << 2 | e2 >> 4);
57
+ if (e3 !== 64) output += String.fromCharCode((e2 & 15) << 4 | e3 >> 2);
58
+ if (e4 !== 64) output += String.fromCharCode((e3 & 3) << 6 | e4);
59
+ }
60
+ return decodeURIComponent(escape(output));
61
+ }
46
62
  function decodeToken(token) {
47
- const payload = token.split(".")[1];
48
- return JSON.parse(atob(payload.replace(/-/g, "+").replace(/_/g, "/")));
63
+ if (!token || typeof token !== "string") {
64
+ throw new Error("@beta-gamer/react-native: token is required and must be a string");
65
+ }
66
+ const parts = token.split(".");
67
+ if (parts.length < 2) {
68
+ throw new Error("@beta-gamer/react-native: invalid session token format");
69
+ }
70
+ return JSON.parse(base64Decode(parts[1]));
49
71
  }
50
72
  var BetaGamerContext = (0, import_react.createContext)(null);
51
73
  function BetaGamerProvider({ token, serverUrl = "https://api.beta-gamer.com", children }) {
@@ -60,11 +82,11 @@ function BetaGamerProvider({ token, serverUrl = "https://api.beta-gamer.com", ch
60
82
  auth: { token },
61
83
  transports: ["websocket", "polling"]
62
84
  });
63
- s.on("connect", () => setSocket(s));
85
+ setSocket(s);
64
86
  s.on("game:state", (state) => {
65
87
  setGameState((prev) => ({ ...prev, ...state }));
66
88
  });
67
- s.on("game:ended", ({ winner, reason }) => {
89
+ s.on("game:over", ({ winner, reason }) => {
68
90
  setGameState((prev) => ({ ...prev, status: "ended", winner, reason }));
69
91
  });
70
92
  return () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beta-gamer/react-native",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "React Native SDK for Beta Gamer GaaS — composable game components",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",