@beta-gamer/react-native 0.1.5 → 0.1.8
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.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +29 -11
- package/dist/index.mjs +29 -11
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -50,9 +50,10 @@ interface BetaGamerContextValue {
|
|
|
50
50
|
interface BetaGamerProviderProps {
|
|
51
51
|
token: string;
|
|
52
52
|
serverUrl?: string;
|
|
53
|
+
socketPath?: string;
|
|
53
54
|
children: React.ReactNode;
|
|
54
55
|
}
|
|
55
|
-
declare function BetaGamerProvider({ token, serverUrl, children }: BetaGamerProviderProps): react_jsx_runtime.JSX.Element;
|
|
56
|
+
declare function BetaGamerProvider({ token, serverUrl, socketPath, children }: BetaGamerProviderProps): react_jsx_runtime.JSX.Element;
|
|
56
57
|
declare function useBetaGamer(): BetaGamerContextValue;
|
|
57
58
|
|
|
58
59
|
/** Returns the current game state (status, players, winner, etc.) */
|
package/dist/index.d.ts
CHANGED
|
@@ -50,9 +50,10 @@ interface BetaGamerContextValue {
|
|
|
50
50
|
interface BetaGamerProviderProps {
|
|
51
51
|
token: string;
|
|
52
52
|
serverUrl?: string;
|
|
53
|
+
socketPath?: string;
|
|
53
54
|
children: React.ReactNode;
|
|
54
55
|
}
|
|
55
|
-
declare function BetaGamerProvider({ token, serverUrl, children }: BetaGamerProviderProps): react_jsx_runtime.JSX.Element;
|
|
56
|
+
declare function BetaGamerProvider({ token, serverUrl, socketPath, children }: BetaGamerProviderProps): react_jsx_runtime.JSX.Element;
|
|
56
57
|
declare function useBetaGamer(): BetaGamerContextValue;
|
|
57
58
|
|
|
58
59
|
/** Returns the current game state (status, players, winner, etc.) */
|
package/dist/index.js
CHANGED
|
@@ -44,20 +44,37 @@ 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
46
|
function base64Decode(str) {
|
|
47
|
-
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
|
|
48
|
-
const normalized = str.replace(/-/g, "+").replace(/_/g, "/");
|
|
49
|
-
|
|
47
|
+
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
48
|
+
const normalized = str.replace(/-/g, "+").replace(/_/g, "/").padEnd(str.length + (4 - str.length % 4) % 4, "=");
|
|
49
|
+
const bytes = [];
|
|
50
50
|
let i = 0;
|
|
51
51
|
while (i < normalized.length) {
|
|
52
52
|
const e1 = chars.indexOf(normalized[i++]);
|
|
53
53
|
const e2 = chars.indexOf(normalized[i++]);
|
|
54
|
-
const e3 = chars.indexOf(normalized[i
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
const e3 = normalized[i] === "=" ? 64 : chars.indexOf(normalized[i]);
|
|
55
|
+
i++;
|
|
56
|
+
const e4 = normalized[i] === "=" ? 64 : chars.indexOf(normalized[i]);
|
|
57
|
+
i++;
|
|
58
|
+
bytes.push(e1 << 2 | e2 >> 4);
|
|
59
|
+
if (e3 !== 64) bytes.push((e2 & 15) << 4 | e3 >> 2);
|
|
60
|
+
if (e4 !== 64) bytes.push((e3 & 3) << 6 | e4);
|
|
59
61
|
}
|
|
60
|
-
|
|
62
|
+
let out = "";
|
|
63
|
+
let j = 0;
|
|
64
|
+
while (j < bytes.length) {
|
|
65
|
+
const b = bytes[j++];
|
|
66
|
+
if (b < 128) {
|
|
67
|
+
out += String.fromCharCode(b);
|
|
68
|
+
} else if (b < 224) {
|
|
69
|
+
out += String.fromCharCode((b & 31) << 6 | bytes[j++] & 63);
|
|
70
|
+
} else if (b < 240) {
|
|
71
|
+
out += String.fromCharCode((b & 15) << 12 | (bytes[j++] & 63) << 6 | bytes[j++] & 63);
|
|
72
|
+
} else {
|
|
73
|
+
const cp = (b & 7) << 18 | (bytes[j++] & 63) << 12 | (bytes[j++] & 63) << 6 | bytes[j++] & 63;
|
|
74
|
+
out += String.fromCodePoint(cp);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return out;
|
|
61
78
|
}
|
|
62
79
|
function decodeToken(token) {
|
|
63
80
|
if (!token || typeof token !== "string") {
|
|
@@ -70,7 +87,7 @@ function decodeToken(token) {
|
|
|
70
87
|
return JSON.parse(base64Decode(parts[1]));
|
|
71
88
|
}
|
|
72
89
|
var BetaGamerContext = (0, import_react.createContext)(null);
|
|
73
|
-
function BetaGamerProvider({ token, serverUrl = "https://api.beta-gamer.com", children }) {
|
|
90
|
+
function BetaGamerProvider({ token, serverUrl = "https://api.beta-gamer.com", socketPath = "/socket.io", children }) {
|
|
74
91
|
const session = decodeToken(token);
|
|
75
92
|
const [socket, setSocket] = (0, import_react.useState)(null);
|
|
76
93
|
const [gameState, setGameState] = (0, import_react.useState)({
|
|
@@ -80,6 +97,7 @@ function BetaGamerProvider({ token, serverUrl = "https://api.beta-gamer.com", ch
|
|
|
80
97
|
(0, import_react.useEffect)(() => {
|
|
81
98
|
const s = (0, import_socket.io)(`${serverUrl}/${session.game}`, {
|
|
82
99
|
auth: { token },
|
|
100
|
+
path: socketPath,
|
|
83
101
|
transports: ["websocket", "polling"]
|
|
84
102
|
});
|
|
85
103
|
setSocket(s);
|
|
@@ -93,7 +111,7 @@ function BetaGamerProvider({ token, serverUrl = "https://api.beta-gamer.com", ch
|
|
|
93
111
|
s.disconnect();
|
|
94
112
|
setSocket(null);
|
|
95
113
|
};
|
|
96
|
-
}, [token, serverUrl, session.game]);
|
|
114
|
+
}, [token, serverUrl, socketPath, session.game]);
|
|
97
115
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(BetaGamerContext.Provider, { value: { token, session, socket, gameState, theme: session.theme ?? {} }, children });
|
|
98
116
|
}
|
|
99
117
|
function useBetaGamer() {
|
package/dist/index.mjs
CHANGED
|
@@ -3,20 +3,37 @@ import { createContext, useContext, useEffect, useState } from "react";
|
|
|
3
3
|
import { io } from "socket.io-client";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
5
|
function base64Decode(str) {
|
|
6
|
-
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
|
|
7
|
-
const normalized = str.replace(/-/g, "+").replace(/_/g, "/");
|
|
8
|
-
|
|
6
|
+
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
7
|
+
const normalized = str.replace(/-/g, "+").replace(/_/g, "/").padEnd(str.length + (4 - str.length % 4) % 4, "=");
|
|
8
|
+
const bytes = [];
|
|
9
9
|
let i = 0;
|
|
10
10
|
while (i < normalized.length) {
|
|
11
11
|
const e1 = chars.indexOf(normalized[i++]);
|
|
12
12
|
const e2 = chars.indexOf(normalized[i++]);
|
|
13
|
-
const e3 = chars.indexOf(normalized[i
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
const e3 = normalized[i] === "=" ? 64 : chars.indexOf(normalized[i]);
|
|
14
|
+
i++;
|
|
15
|
+
const e4 = normalized[i] === "=" ? 64 : chars.indexOf(normalized[i]);
|
|
16
|
+
i++;
|
|
17
|
+
bytes.push(e1 << 2 | e2 >> 4);
|
|
18
|
+
if (e3 !== 64) bytes.push((e2 & 15) << 4 | e3 >> 2);
|
|
19
|
+
if (e4 !== 64) bytes.push((e3 & 3) << 6 | e4);
|
|
18
20
|
}
|
|
19
|
-
|
|
21
|
+
let out = "";
|
|
22
|
+
let j = 0;
|
|
23
|
+
while (j < bytes.length) {
|
|
24
|
+
const b = bytes[j++];
|
|
25
|
+
if (b < 128) {
|
|
26
|
+
out += String.fromCharCode(b);
|
|
27
|
+
} else if (b < 224) {
|
|
28
|
+
out += String.fromCharCode((b & 31) << 6 | bytes[j++] & 63);
|
|
29
|
+
} else if (b < 240) {
|
|
30
|
+
out += String.fromCharCode((b & 15) << 12 | (bytes[j++] & 63) << 6 | bytes[j++] & 63);
|
|
31
|
+
} else {
|
|
32
|
+
const cp = (b & 7) << 18 | (bytes[j++] & 63) << 12 | (bytes[j++] & 63) << 6 | bytes[j++] & 63;
|
|
33
|
+
out += String.fromCodePoint(cp);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return out;
|
|
20
37
|
}
|
|
21
38
|
function decodeToken(token) {
|
|
22
39
|
if (!token || typeof token !== "string") {
|
|
@@ -29,7 +46,7 @@ function decodeToken(token) {
|
|
|
29
46
|
return JSON.parse(base64Decode(parts[1]));
|
|
30
47
|
}
|
|
31
48
|
var BetaGamerContext = createContext(null);
|
|
32
|
-
function BetaGamerProvider({ token, serverUrl = "https://api.beta-gamer.com", children }) {
|
|
49
|
+
function BetaGamerProvider({ token, serverUrl = "https://api.beta-gamer.com", socketPath = "/socket.io", children }) {
|
|
33
50
|
const session = decodeToken(token);
|
|
34
51
|
const [socket, setSocket] = useState(null);
|
|
35
52
|
const [gameState, setGameState] = useState({
|
|
@@ -39,6 +56,7 @@ function BetaGamerProvider({ token, serverUrl = "https://api.beta-gamer.com", ch
|
|
|
39
56
|
useEffect(() => {
|
|
40
57
|
const s = io(`${serverUrl}/${session.game}`, {
|
|
41
58
|
auth: { token },
|
|
59
|
+
path: socketPath,
|
|
42
60
|
transports: ["websocket", "polling"]
|
|
43
61
|
});
|
|
44
62
|
setSocket(s);
|
|
@@ -52,7 +70,7 @@ function BetaGamerProvider({ token, serverUrl = "https://api.beta-gamer.com", ch
|
|
|
52
70
|
s.disconnect();
|
|
53
71
|
setSocket(null);
|
|
54
72
|
};
|
|
55
|
-
}, [token, serverUrl, session.game]);
|
|
73
|
+
}, [token, serverUrl, socketPath, session.game]);
|
|
56
74
|
return /* @__PURE__ */ jsx(BetaGamerContext.Provider, { value: { token, session, socket, gameState, theme: session.theme ?? {} }, children });
|
|
57
75
|
}
|
|
58
76
|
function useBetaGamer() {
|