@masterunoco/casinowebengine-api 0.1.3 → 0.1.6
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.cjs +190 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +120 -3
- package/dist/index.d.ts +120 -3
- package/dist/index.js +190 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -335,6 +335,7 @@ var JwtAuth = class {
|
|
|
335
335
|
const payload = { username, password, recaptchaToken };
|
|
336
336
|
const res = await this.client.post("/auth/login", payload, authPolicy);
|
|
337
337
|
this.setUser(res.user, res.token);
|
|
338
|
+
storage.setSocketToken(res.socketToken);
|
|
338
339
|
return res;
|
|
339
340
|
}
|
|
340
341
|
async GoogleLogin(data) {
|
|
@@ -499,6 +500,9 @@ var ContentAPI = class {
|
|
|
499
500
|
get(slug) {
|
|
500
501
|
return this.http.get(`/content-pages/${slug}`, "none");
|
|
501
502
|
}
|
|
503
|
+
getAnnouncements() {
|
|
504
|
+
return this.http.get("/announcements", "none");
|
|
505
|
+
}
|
|
502
506
|
};
|
|
503
507
|
|
|
504
508
|
// src/apis/deposit.ts
|
|
@@ -524,7 +528,7 @@ var GamesAPI = class {
|
|
|
524
528
|
}
|
|
525
529
|
/** Public: search games */
|
|
526
530
|
search(request) {
|
|
527
|
-
return this.http.
|
|
531
|
+
return this.http.get(`/games/search?${new URLSearchParams(request).toString()}`, "none");
|
|
528
532
|
}
|
|
529
533
|
getCategories() {
|
|
530
534
|
return this.http.get("/games/categories", "none");
|
|
@@ -534,8 +538,8 @@ var GamesAPI = class {
|
|
|
534
538
|
return this.http.post(`/games/getLink`, { gameId }, "required");
|
|
535
539
|
}
|
|
536
540
|
/** Public: demo link */
|
|
537
|
-
getDemoLink(
|
|
538
|
-
return this.http.post("/games/getDemoLink", {
|
|
541
|
+
getDemoLink(gameExternalId) {
|
|
542
|
+
return this.http.post("/games/getDemoLink", { gameExternalId }, "none");
|
|
539
543
|
}
|
|
540
544
|
setFavorite(gameId, isFavorite) {
|
|
541
545
|
return this.http.post("/games/favorites", { gameId, isFavorite }, "required");
|
|
@@ -564,6 +568,9 @@ var GamesAPI = class {
|
|
|
564
568
|
getProviders() {
|
|
565
569
|
return this.http.get("/games/providers", "none");
|
|
566
570
|
}
|
|
571
|
+
getCategoriesProviders() {
|
|
572
|
+
return this.http.get("/games/providers/categories", "none");
|
|
573
|
+
}
|
|
567
574
|
getLobby() {
|
|
568
575
|
const geo = new GeolocationAPI(this.http);
|
|
569
576
|
const countryCode = geo.getCountryCode();
|
|
@@ -652,6 +659,12 @@ var PlayerAPI = class {
|
|
|
652
659
|
verifyPhoneCode(data) {
|
|
653
660
|
return this.http.post("/verify/phone/confirm", data);
|
|
654
661
|
}
|
|
662
|
+
verifyPhoneSignup(data) {
|
|
663
|
+
return this.http.post("/verify/phone/send", data);
|
|
664
|
+
}
|
|
665
|
+
verifyPhoneCodeSignup(data) {
|
|
666
|
+
return this.http.post("/verify/phone/confirm", data);
|
|
667
|
+
}
|
|
655
668
|
getVerificationStatus() {
|
|
656
669
|
return this.http.get("/player/verification-status");
|
|
657
670
|
}
|
|
@@ -773,6 +786,9 @@ var SettingsAPI = class {
|
|
|
773
786
|
getCurrencies() {
|
|
774
787
|
return this.http.get("/currencies/get", "none");
|
|
775
788
|
}
|
|
789
|
+
getCurrenciesRates() {
|
|
790
|
+
return this.http.get("/currencies/rates", "none");
|
|
791
|
+
}
|
|
776
792
|
getWebSetting(lang) {
|
|
777
793
|
return this.http.get(`/website-settings?language=${lang}&key[]=footerCasinoItems&key[]=footerSportsItems&key[]=footerSocialMedia&key[]=footerPromoItems&key[]=footerSupportLegalItems&key[]=footerAboutUsItems&key[]=footerAppLinks`, "none");
|
|
778
794
|
}
|
|
@@ -857,6 +873,171 @@ var WithdrawAPI = class {
|
|
|
857
873
|
}
|
|
858
874
|
};
|
|
859
875
|
|
|
876
|
+
// src/ws/socketClient.ts
|
|
877
|
+
var SocketClient = class {
|
|
878
|
+
constructor(opts) {
|
|
879
|
+
this.opts = opts;
|
|
880
|
+
this.ws = null;
|
|
881
|
+
this.status = "idle";
|
|
882
|
+
this.pingTimer = null;
|
|
883
|
+
this.reconnectTimer = null;
|
|
884
|
+
this.reconnectAttempt = 0;
|
|
885
|
+
this.manualClose = false;
|
|
886
|
+
this.hasJoinedAfterLogin = false;
|
|
887
|
+
this.handlers = /* @__PURE__ */ new Map();
|
|
888
|
+
}
|
|
889
|
+
/** Current status useful for UI */
|
|
890
|
+
getStatus() {
|
|
891
|
+
return this.status;
|
|
892
|
+
}
|
|
893
|
+
/** Raw socket access (optional) */
|
|
894
|
+
getSocket() {
|
|
895
|
+
return this.ws;
|
|
896
|
+
}
|
|
897
|
+
/** Connect (idempotent) */
|
|
898
|
+
connect() {
|
|
899
|
+
if (this.ws && (this.ws.readyState === WebSocket.OPEN || this.ws.readyState === WebSocket.CONNECTING)) {
|
|
900
|
+
return;
|
|
901
|
+
}
|
|
902
|
+
this.manualClose = false;
|
|
903
|
+
this.setStatus(this.reconnectAttempt > 0 ? "reconnecting" : "connecting");
|
|
904
|
+
this.ws = new WebSocket(this.opts.url);
|
|
905
|
+
this.ws.onopen = () => {
|
|
906
|
+
this.reconnectAttempt = 0;
|
|
907
|
+
this.setStatus("connected");
|
|
908
|
+
this.sendRaw({
|
|
909
|
+
type: "joinPublic",
|
|
910
|
+
payload: { name: this.opts.publicName ?? "player1" }
|
|
911
|
+
});
|
|
912
|
+
this.startPing();
|
|
913
|
+
this.tryJoinAfterLogin();
|
|
914
|
+
};
|
|
915
|
+
this.ws.onmessage = (event) => {
|
|
916
|
+
let parsed;
|
|
917
|
+
try {
|
|
918
|
+
parsed = JSON.parse(event.data);
|
|
919
|
+
} catch {
|
|
920
|
+
this.emit("*", event.data, { type: "*", message: event.data });
|
|
921
|
+
return;
|
|
922
|
+
}
|
|
923
|
+
const data = parsed.message ?? parsed.payload ?? parsed;
|
|
924
|
+
this.emit(parsed.type, data, parsed);
|
|
925
|
+
this.emit("*", data, parsed);
|
|
926
|
+
};
|
|
927
|
+
this.ws.onerror = () => {
|
|
928
|
+
this.emit("error", null, { type: "error" });
|
|
929
|
+
};
|
|
930
|
+
this.ws.onclose = () => {
|
|
931
|
+
this.stopPing();
|
|
932
|
+
this.setStatus("disconnected");
|
|
933
|
+
if (!this.manualClose && (this.opts.autoReconnect ?? true)) {
|
|
934
|
+
this.scheduleReconnect();
|
|
935
|
+
}
|
|
936
|
+
};
|
|
937
|
+
}
|
|
938
|
+
/** Disconnect gracefully */
|
|
939
|
+
disconnect(code = 1e3, reason = "client_disconnect") {
|
|
940
|
+
this.manualClose = true;
|
|
941
|
+
this.stopPing();
|
|
942
|
+
this.clearReconnect();
|
|
943
|
+
if (this.ws) {
|
|
944
|
+
try {
|
|
945
|
+
this.ws.close(code, reason);
|
|
946
|
+
} catch {
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
this.ws = null;
|
|
950
|
+
this.setStatus("disconnected");
|
|
951
|
+
}
|
|
952
|
+
/** Call after login (or whenever token/user changes) */
|
|
953
|
+
onLogin() {
|
|
954
|
+
this.hasJoinedAfterLogin = false;
|
|
955
|
+
this.tryJoinAfterLogin();
|
|
956
|
+
}
|
|
957
|
+
/** Reset join flag (call on logout) */
|
|
958
|
+
onLogout() {
|
|
959
|
+
this.hasJoinedAfterLogin = false;
|
|
960
|
+
}
|
|
961
|
+
/** Subscribe to message type (e.g. 'happyHourStarted', 'latest-bet'). Use '*' to receive everything. */
|
|
962
|
+
on(type, handler) {
|
|
963
|
+
const set = this.handlers.get(type) ?? /* @__PURE__ */ new Set();
|
|
964
|
+
set.add(handler);
|
|
965
|
+
this.handlers.set(type, set);
|
|
966
|
+
return () => this.off(type, handler);
|
|
967
|
+
}
|
|
968
|
+
off(type, handler) {
|
|
969
|
+
const set = this.handlers.get(type);
|
|
970
|
+
if (!set) return;
|
|
971
|
+
set.delete(handler);
|
|
972
|
+
if (set.size === 0) this.handlers.delete(type);
|
|
973
|
+
}
|
|
974
|
+
/** Send a typed message (SDK-side helper) */
|
|
975
|
+
send(type, payload) {
|
|
976
|
+
this.sendRaw({ type, payload });
|
|
977
|
+
}
|
|
978
|
+
// ----------------- internals -----------------
|
|
979
|
+
emit(type, data, raw) {
|
|
980
|
+
const set = this.handlers.get(type);
|
|
981
|
+
if (!set) return;
|
|
982
|
+
for (const fn of set) {
|
|
983
|
+
try {
|
|
984
|
+
fn(data, raw);
|
|
985
|
+
} catch {
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
sendRaw(msg) {
|
|
990
|
+
if (!this.ws || this.ws.readyState !== WebSocket.OPEN) return;
|
|
991
|
+
this.ws.send(JSON.stringify(msg));
|
|
992
|
+
}
|
|
993
|
+
tryJoinAfterLogin() {
|
|
994
|
+
if (this.hasJoinedAfterLogin) return;
|
|
995
|
+
if (!this.ws || this.ws.readyState !== WebSocket.OPEN) return;
|
|
996
|
+
const user = this.opts.getUser?.() ?? null;
|
|
997
|
+
if (!user?.id) return;
|
|
998
|
+
const socketToken = this.opts.getSocketToken?.() ?? "";
|
|
999
|
+
if (!socketToken) return;
|
|
1000
|
+
this.sendRaw({
|
|
1001
|
+
type: "join",
|
|
1002
|
+
payload: {
|
|
1003
|
+
name: user.name || "player1",
|
|
1004
|
+
playerId: user.id,
|
|
1005
|
+
socketToken
|
|
1006
|
+
}
|
|
1007
|
+
});
|
|
1008
|
+
this.hasJoinedAfterLogin = true;
|
|
1009
|
+
}
|
|
1010
|
+
startPing() {
|
|
1011
|
+
this.stopPing();
|
|
1012
|
+
const every = this.opts.pingIntervalMs ?? 5e3;
|
|
1013
|
+
this.pingTimer = setInterval(() => {
|
|
1014
|
+
if (!this.ws || this.ws.readyState !== WebSocket.OPEN) return;
|
|
1015
|
+
this.sendRaw({ type: "ping", payload: { ping: 1 } });
|
|
1016
|
+
}, every);
|
|
1017
|
+
}
|
|
1018
|
+
stopPing() {
|
|
1019
|
+
if (this.pingTimer) clearInterval(this.pingTimer);
|
|
1020
|
+
this.pingTimer = null;
|
|
1021
|
+
}
|
|
1022
|
+
scheduleReconnect() {
|
|
1023
|
+
this.clearReconnect();
|
|
1024
|
+
this.reconnectAttempt += 1;
|
|
1025
|
+
const base = Math.min(1e3 * 2 ** (this.reconnectAttempt - 1), this.opts.maxReconnectDelayMs ?? 3e4);
|
|
1026
|
+
const jitter = Math.floor(Math.random() * 250);
|
|
1027
|
+
this.reconnectTimer = setTimeout(() => {
|
|
1028
|
+
this.connect();
|
|
1029
|
+
}, base + jitter);
|
|
1030
|
+
}
|
|
1031
|
+
clearReconnect() {
|
|
1032
|
+
if (this.reconnectTimer) clearTimeout(this.reconnectTimer);
|
|
1033
|
+
this.reconnectTimer = null;
|
|
1034
|
+
}
|
|
1035
|
+
setStatus(s) {
|
|
1036
|
+
this.status = s;
|
|
1037
|
+
this.emit("status", s, { type: "status", payload: s });
|
|
1038
|
+
}
|
|
1039
|
+
};
|
|
1040
|
+
|
|
860
1041
|
// src/sdk.ts
|
|
861
1042
|
var GameSDK = class {
|
|
862
1043
|
constructor(cfg) {
|
|
@@ -866,6 +1047,12 @@ var GameSDK = class {
|
|
|
866
1047
|
// <-- uses this.auth (defined below)
|
|
867
1048
|
timeoutMs: cfg.timeoutMs ?? 15e3
|
|
868
1049
|
});
|
|
1050
|
+
this.ws = new SocketClient({
|
|
1051
|
+
url: cfg.socketUrl || "",
|
|
1052
|
+
publicName: "player1",
|
|
1053
|
+
getSocketToken: cfg.getSocketToken ?? (() => storage.getSocketToken()),
|
|
1054
|
+
getUser: () => this.auth.getUser() ? { id: this.auth.getUser().id, name: this.auth.getUser().name } : null
|
|
1055
|
+
});
|
|
869
1056
|
this.auth = new JwtAuth(this.http);
|
|
870
1057
|
this.affiliate = new AffiliateAPI(this.http);
|
|
871
1058
|
this.content = new ContentAPI(this.http);
|