infinite-games-sdk 0.0.4 → 0.0.5
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/history/index.d.ts +1 -1
- package/dist/history/index.d.ts.map +1 -1
- package/dist/history/types.d.ts +0 -7
- package/dist/history/types.d.ts.map +1 -1
- package/dist/history/useHistoryClient.d.ts +11 -5
- package/dist/history/useHistoryClient.d.ts.map +1 -1
- package/dist/history/useHistoryClient.js +29 -36
- package/dist/history/useHistoryClient.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/package.json +16 -10
package/dist/history/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/history/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,YAAY,EAAE,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/history/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/history/types.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/history/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/history/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB"}
|
|
@@ -1,13 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HistoryConfig } from './types';
|
|
2
2
|
interface UseHistoryClientOptions {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Callback for all incoming WebSocket messages.
|
|
5
|
+
* Receives the parsed JSON message.
|
|
6
|
+
*/
|
|
7
|
+
onMessage?: (message: any) => void;
|
|
8
|
+
/**
|
|
9
|
+
* History client configuration (baseUrl, reconnect settings, etc.)
|
|
10
|
+
*/
|
|
6
11
|
config?: HistoryConfig;
|
|
7
12
|
}
|
|
8
13
|
export declare function useHistoryClient(tableId: string | null, coinType: string | null, options?: UseHistoryClientOptions): {
|
|
9
14
|
isConnected: boolean;
|
|
10
|
-
|
|
15
|
+
send: (message: object) => void;
|
|
16
|
+
sendBetUpdate: (bets: Record<string, number>) => void;
|
|
11
17
|
sendGameReset: () => void;
|
|
12
18
|
disconnect: () => void;
|
|
13
19
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useHistoryClient.d.ts","sourceRoot":"","sources":["../../src/history/useHistoryClient.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"useHistoryClient.d.ts","sourceRoot":"","sources":["../../src/history/useHistoryClient.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,UAAU,uBAAuB;IAC/B;;;OAGG;IACH,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,IAAI,CAAC;IACnC;;OAEG;IACH,MAAM,CAAC,EAAE,aAAa,CAAC;CACxB;AAED,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,MAAM,GAAG,IAAI,EACtB,QAAQ,EAAE,MAAM,GAAG,IAAI,EACvB,OAAO,GAAE,uBAA4B;;oBAyDF,MAAM;0BAMA,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;;;EAqBhE"}
|
|
@@ -6,20 +6,21 @@ const HistoryClient_1 = require("./HistoryClient");
|
|
|
6
6
|
function useHistoryClient(tableId, coinType, options = {}) {
|
|
7
7
|
const [isConnected, setIsConnected] = (0, react_1.useState)(false);
|
|
8
8
|
const clientRef = (0, react_1.useRef)(null);
|
|
9
|
-
// Use
|
|
10
|
-
const
|
|
11
|
-
const onBetUpdateRef = (0, react_1.useRef)(options.onBetUpdate);
|
|
12
|
-
const onGameResetRef = (0, react_1.useRef)(options.onGameReset);
|
|
9
|
+
// Use ref for callback to avoid stale closures
|
|
10
|
+
const onMessageRef = (0, react_1.useRef)(options.onMessage);
|
|
13
11
|
(0, react_1.useEffect)(() => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
onMessageRef.current = options.onMessage;
|
|
13
|
+
}, [options.onMessage]);
|
|
14
|
+
// Stable config ref to avoid reconnects on config object identity changes
|
|
15
|
+
const configRef = (0, react_1.useRef)(options.config);
|
|
16
|
+
(0, react_1.useEffect)(() => {
|
|
17
|
+
configRef.current = options.config;
|
|
18
|
+
}, [options.config]);
|
|
18
19
|
(0, react_1.useEffect)(() => {
|
|
19
20
|
if (!tableId || !coinType) {
|
|
20
21
|
return;
|
|
21
22
|
}
|
|
22
|
-
const client = new HistoryClient_1.HistoryClient(
|
|
23
|
+
const client = new HistoryClient_1.HistoryClient(configRef.current);
|
|
23
24
|
clientRef.current = client;
|
|
24
25
|
client.onConnect = () => {
|
|
25
26
|
setIsConnected(true);
|
|
@@ -30,27 +31,17 @@ function useHistoryClient(tableId, coinType, options = {}) {
|
|
|
30
31
|
client.onMessage = (event) => {
|
|
31
32
|
try {
|
|
32
33
|
const message = JSON.parse(event.data);
|
|
33
|
-
//
|
|
34
|
+
// For wrapped events {channel, data}, unwrap and pass the data
|
|
35
|
+
// For relay messages {type, ...}, pass as-is
|
|
34
36
|
if (message.channel && message.data) {
|
|
35
|
-
|
|
36
|
-
onGameEventRef.current(message.data);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
// Relay messages: {type, ...}
|
|
40
|
-
else if (message.type === 'bet_update') {
|
|
41
|
-
if (onBetUpdateRef.current) {
|
|
42
|
-
const { type, ...bets } = message;
|
|
43
|
-
onBetUpdateRef.current(bets);
|
|
44
|
-
}
|
|
37
|
+
onMessageRef.current?.(message.data);
|
|
45
38
|
}
|
|
46
|
-
else
|
|
47
|
-
|
|
48
|
-
onGameResetRef.current();
|
|
49
|
-
}
|
|
39
|
+
else {
|
|
40
|
+
onMessageRef.current?.(message);
|
|
50
41
|
}
|
|
51
42
|
}
|
|
52
43
|
catch (error) {
|
|
53
|
-
console.error('Failed to parse WebSocket message:', error);
|
|
44
|
+
console.error('[HistoryClient] Failed to parse WebSocket message:', error);
|
|
54
45
|
}
|
|
55
46
|
};
|
|
56
47
|
client.connect(tableId, coinType);
|
|
@@ -58,24 +49,26 @@ function useHistoryClient(tableId, coinType, options = {}) {
|
|
|
58
49
|
client.disconnect();
|
|
59
50
|
clientRef.current = null;
|
|
60
51
|
};
|
|
61
|
-
}, [tableId, coinType
|
|
62
|
-
const
|
|
52
|
+
}, [tableId, coinType]);
|
|
53
|
+
const send = (0, react_1.useCallback)((message) => {
|
|
63
54
|
if (clientRef.current) {
|
|
64
|
-
clientRef.current.send(
|
|
55
|
+
clientRef.current.send(message);
|
|
65
56
|
}
|
|
66
|
-
};
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
57
|
+
}, []);
|
|
58
|
+
const sendBetUpdate = (0, react_1.useCallback)((bets) => {
|
|
59
|
+
send({ type: 'bet_update', ...bets });
|
|
60
|
+
}, [send]);
|
|
61
|
+
const sendGameReset = (0, react_1.useCallback)(() => {
|
|
62
|
+
send({ type: 'game_reset' });
|
|
63
|
+
}, [send]);
|
|
64
|
+
const disconnect = (0, react_1.useCallback)(() => {
|
|
73
65
|
if (clientRef.current) {
|
|
74
66
|
clientRef.current.disconnect();
|
|
75
67
|
}
|
|
76
|
-
};
|
|
68
|
+
}, []);
|
|
77
69
|
return {
|
|
78
70
|
isConnected,
|
|
71
|
+
send,
|
|
79
72
|
sendBetUpdate,
|
|
80
73
|
sendGameReset,
|
|
81
74
|
disconnect,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useHistoryClient.js","sourceRoot":"","sources":["../../src/history/useHistoryClient.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"useHistoryClient.js","sourceRoot":"","sources":["../../src/history/useHistoryClient.ts"],"names":[],"mappings":";;AAgBA,4CAuFC;AAvGD,iCAAiE;AACjE,mDAAgD;AAehD,SAAgB,gBAAgB,CAC9B,OAAsB,EACtB,QAAuB,EACvB,UAAmC,EAAE;IAErC,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,IAAA,gBAAQ,EAAC,KAAK,CAAC,CAAC;IACtD,MAAM,SAAS,GAAG,IAAA,cAAM,EAAuB,IAAI,CAAC,CAAC;IAErD,+CAA+C;IAC/C,MAAM,YAAY,GAAG,IAAA,cAAM,EAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAC/C,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,YAAY,CAAC,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC;IAC3C,CAAC,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC;IAExB,0EAA0E;IAC1E,MAAM,SAAS,GAAG,IAAA,cAAM,EAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACzC,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,SAAS,CAAC,OAAO,GAAG,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CAAC;IACJ,CAAC,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;IAExB,MAAM,IAAI,GAAG,IAAA,mBAAW,EAAC,CAAC,OAAe,EAAE,EAAE;QAC3C,IAAI,SAAS,CAAC,OAAO,EAAE,CAAC;YACtB,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAClC,CAAC;IACH,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,MAAM,aAAa,GAAG,IAAA,mBAAW,EAAC,CAAC,IAA4B,EAAE,EAAE;QACjE,IAAI,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;IACxC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IAEX,MAAM,aAAa,GAAG,IAAA,mBAAW,EAAC,GAAG,EAAE;QACrC,IAAI,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC;IAC/B,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IAEX,MAAM,UAAU,GAAG,IAAA,mBAAW,EAAC,GAAG,EAAE;QAClC,IAAI,SAAS,CAAC,OAAO,EAAE,CAAC;YACtB,SAAS,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC;QACjC,CAAC;IACH,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO;QACL,WAAW;QACX,IAAI;QACJ,aAAa;QACb,aAAa;QACb,UAAU;KACX,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,6 @@ export { toBackendScale, fromBackendScale, SCALE_FACTOR } from './utils/scale';
|
|
|
6
6
|
export { getCompatibleCoinType, VALID_COINS } from './launcher';
|
|
7
7
|
export { AuthError } from './errors';
|
|
8
8
|
export type { SessionConfig, LaunchParams, LaunchResult, TokenType, InitializeResult, } from './session/types';
|
|
9
|
-
export type { HistoryConfig
|
|
9
|
+
export type { HistoryConfig } from './history/types';
|
|
10
10
|
export type { GameLauncherConfig, UseGameLauncherOptions, GameLauncherState, WalletState, LaunchMutation, } from './launcher';
|
|
11
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAG5D,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAG7C,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC/E,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAGhE,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAGrC,YAAY,EACV,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,gBAAgB,GACjB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EAAE,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAG5D,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAG7C,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC/E,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAGhE,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAGrC,YAAY,EACV,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,gBAAgB,GACjB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,YAAY,EACV,kBAAkB,EAClB,sBAAsB,EACtB,iBAAiB,EACjB,WAAW,EACX,cAAc,GACf,MAAM,YAAY,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "infinite-games-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "Infinite Games SDK",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
|
-
"files": [
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"/dist"
|
|
9
|
+
],
|
|
10
|
+
"keywords": [
|
|
11
|
+
"sdk",
|
|
12
|
+
"typescript",
|
|
13
|
+
"npm"
|
|
14
|
+
],
|
|
13
15
|
"author": "",
|
|
14
16
|
"license": "ISC",
|
|
15
17
|
"devDependencies": {
|
|
@@ -19,5 +21,9 @@
|
|
|
19
21
|
},
|
|
20
22
|
"peerDependencies": {
|
|
21
23
|
"react": "^18.x"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsc",
|
|
27
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
22
28
|
}
|
|
23
|
-
}
|
|
29
|
+
}
|