Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(sandobx): clean up sdk gen #590

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sandbox/client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ <h1>Rivet Modules E2E Test</h1>
<button onclick="findOrCreateLobby()">Find Or Create Lobby</button>
<button onclick="fetchState()">Fetch State</button>
<button onclick="resetState()">Reset State</button>
<button onclick="setAdminToken()">Set Admin Token</button>

<script>
window.addEventListener('load', function() {
Expand Down
29 changes: 19 additions & 10 deletions sandbox/client/index.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
/// <reference path="./dist/sdk.d.mts" />
import { Backend } from './dist/sdk.mjs';
/// <reference path="./sdk/index.d.mts" />
import { Rivet } from './sdk/index.mjs';

const urlParams = new URLSearchParams(window.location.search);
const environment = urlParams.get('env') || 'local';
const API_ENDPOINT = environment === 'remote' ? "https://modules-sand-m4z.backend.staging2.gameinc.io" : "http://localhost:6420";

const backend = new Backend({ endpoint: API_ENDPOINT });

console.log('backend', backend);
function getBackend() {
return new Rivet({ endpoint: localStorage.apiEndpoint ?? "http://localhost:6420" });
}

window.fetchState = async function() {
const { state } = await backend.lobbies.fetchLobbyManagerState({});
const { state } = await getBackend().lobbies.fetchLobbyManagerState({
adminToken: localStorage.adminToken
});
console.log('State', state);
};

window.resetState = async function() {
await backend.lobbies.resetLobbyManagerState({});
await getBackend().lobbies.resetLobbyManagerState({
adminToken: localStorage.adminToken
});
};

window.setAdminToken = function() {
let token = prompt("Admin token");
localStorage.adminToken = token;
};

window.findOrCreateLobby = async function() {
let res;
if (environment == 'local') {
res = await backend.lobbies.findOrCreate({
res = await getBackend().lobbies.findOrCreate({
version: "default",
regions: ["local"],
tags: {},
Expand All @@ -37,7 +45,7 @@ window.findOrCreateLobby = async function() {
} else {
const region = "lnd-atl";
const tags = {"foo": "bar"};
res = await backend.lobbies.findOrCreate({
res = await getBackend().lobbies.findOrCreate({
version: "2024.09.18-2",
regions: [region],
tags,
Expand Down Expand Up @@ -112,3 +120,4 @@ function connect(lobby, players) {
};
});
}

Loading
Loading